1 | <?php |
||
20 | class GitLogParser extends AbstractParser |
||
21 | { |
||
22 | public function parseGitLog() |
||
28 | |||
29 | 1 | public function parseLines(array $lines) |
|
30 | { |
||
31 | 1 | $this->getHistory()->initTags(); |
|
32 | |||
33 | 1 | foreach ($lines as $line) { |
|
34 | 1 | if (!preg_match('/^(\w+) (([0-9-]+) (.*?) \[.*?\]) *\(?(.*?)\)?$/', $line, $m)) { |
|
35 | throw new UnexpectedValueException('failed parse git line'); |
||
36 | } |
||
37 | 1 | $tag = $this->matchTag($m[5]); |
|
38 | 1 | $note = $this->matchNote($m[4]); |
|
39 | 1 | if ($tag) { |
|
40 | 1 | $this->addTag($tag, $m[3]); |
|
41 | } |
||
42 | 1 | if (false && $note) { /// disabled adding notes |
|
43 | $this->addNote($note); |
||
44 | } |
||
45 | 1 | $this->addCommit($m[1], $m[2]); |
|
46 | } |
||
47 | |||
48 | 1 | return $this->getHistory(); |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Finds first tag in given refs string. |
||
53 | * @param string $str |
||
54 | * @return string |
||
55 | */ |
||
56 | 1 | public function matchTag($str) |
|
57 | { |
||
58 | 1 | $refs = explode(', ', $str); |
|
59 | 1 | foreach ($refs as $ref) { |
|
60 | 1 | if (preg_match('/^tag: (.*)$/', $ref, $m)) { |
|
61 | 1 | return $m[1]; |
|
62 | } |
||
63 | } |
||
64 | |||
65 | 1 | return null; |
|
66 | } |
||
67 | |||
68 | 1 | public function matchNote($str) |
|
72 | } |
||
73 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.