Passed
Push — master ( 1f6501...911244 )
by butschster
33:53 queued 27:07
created

ProcessParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
nc 1
nop 1
dl 0
loc 3
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MonorepoBuilder;
6
7
use Symplify\MonorepoBuilder\Release\Process\ProcessRunner;
8
9
final class ProcessParser implements TagParserInterface
10
{
11
    private const COMMAND = ['git', 'tag', '-l', '--sort=committerdate'];
12
13
    public function __construct(
14
        private readonly ProcessRunner $processRunner
15
    ) {
16
    }
17
18
    /**
19
     * Returns null, when there are no local tags yet
20
     */
21
    public function parse(string $gitDirectory): array
22
    {
23
        return \array_filter($this->parseTags($this->processRunner->run(self::COMMAND, $gitDirectory)));
24
    }
25
26
    /**
27
     * @return string[]
28
     */
29
    private function parseTags(string $commandResult): array
30
    {
31
        $tags = \trim($commandResult);
32
33
        // Remove all "\r" chars in case the CLI env like the Windows OS.
34
        // Otherwise (ConEmu, git bash, mingw cli, e.g.), leave as is.
35
        $normalizedTags = \str_replace("\r", '', $tags);
36
37
        return \explode("\n", $normalizedTags);
38
    }
39
}
40