Passed
Push — master ( 9251f2...ca8fc4 )
by Herberto
03:14
created

GitAdapter::parseGitEffortOutput()   D

Complexity

Conditions 9
Paths 17

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 9

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 4.909
c 0
b 0
f 0
cc 9
eloc 16
nc 17
nop 1
crap 9
1
<?php
2
3
namespace Hgraca\Phorensic\Miner\Vcs\Git;
4
5
use Hgraca\Phorensic\Miner\Vcs\VcsMinerInterface;
6
7
final class GitAdapter implements VcsMinerInterface
8
{
9
    /** @var ConsoleInterface */
10
    private $console;
11
12 1
    public function __construct(ConsoleInterface $console)
13
    {
14 1
        $this->console = $console;
15 1
    }
16
17 1
    public function findMostChangedFiles(string $repoPath, string $since = null): array
18
    {
19 1
        return $this->parseGitEffortOutput($this->console->gitEffort($repoPath, $since));
20
    }
21
22 1
    private function parseGitEffortOutput(string $gitEffortOutput)
23
    {
24 1
        $outputLines = explode(PHP_EOL, $gitEffortOutput);
25
26 1
        $foundFirstBlankLine = false;
27 1
        $relevantOutputLines = [];
28 1
        foreach ($outputLines as $line) {
29 1
            $foundSecondBlankLine = ($foundFirstBlankLine && $line === '') ? true : false;
30 1
            $foundFirstBlankLine = ($foundFirstBlankLine || $line === '') ? true : false;
31
32 1
            if ($foundSecondBlankLine) {
33 1
                break;
34
            }
35
36 1
            if (!$foundFirstBlankLine || $line === '') {
37 1
                continue;
38
            }
39
40 1
            $relevantLine = explode(' ', preg_replace('/\s+/', ' ', trim($line)));
41 1
            $relevantLine[0] = trim($relevantLine[0], ".");
42 1
            $relevantOutputLines[] = $relevantLine;
43
        }
44 1
        array_pop($relevantOutputLines);
45
46 1
        return $relevantOutputLines;
47
    }
48
}
49