AbstractAdapter::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
namespace GettextParser\Adapter;
3
4
use GettextParser\Pattern;
5
6
abstract class AbstractAdapter
7
{
8
    /**
9
     * @var array
10
     */
11
    protected $patternConfig = array();
12
13
    /**
14
     * stores parsing patterns
15
     * @var Pattern[]
16
     */
17
    protected $patterns = array();
18
19
    /**
20
     *
21
     */
22
    public function __construct()
23
    {
24
        $this->addPatterns();
25
    }
26
27
    /**
28
     *
29
     */
30
    protected function addPatterns()
31
    {
32
        foreach ($this->patternConfig as $item) {
33
            foreach ($item['pattern'] as $pattern) {
34
                $this->patterns[] = new Pattern($pattern, $item['plural']);
35
            }
36
        }
37
    }
38
39
    /**
40
     * @param $data
41
     * @return array
42
     */
43
    public function parse($data)
44
    {
45
        $results = array();
46
47
        foreach ($this->patterns as $pattern) {
48
            $result = $pattern->match($data);
49
            if ($result !== false) {
50
                $results = array_merge($results, $result);
51
            }
52
        }
53
54
        return $results;
55
    }
56
}
57