Passed
Pull Request — master (#285)
by Fabien
02:18
created

FossilChangesCountProcess::countChanges()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 9.6111
cc 5
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Churn\Process\ChangesCount;
6
7
use Churn\File\File;
8
use Churn\Process\ChangesCountInterface;
9
use Churn\Process\ChurnProcess;
10
use Symfony\Component\Process\Process;
11
12
class FossilChangesCountProcess extends ChurnProcess implements ChangesCountInterface
13
{
14
15
    /**
16
     * Class constructor.
17
     *
18
     * @param File $file The file the process is being executed on.
19
     * @param string $dateSince String containing the date of when to look at commits since (Y-m-d).
20
     */
21
    public function __construct(File $file, string $dateSince)
22
    {
23
        $process = new Process([
24
            'fossil', 'timeline', '-t', 'ci',
25
            '-W', '0', '-n', '0', 'after', $dateSince,
26
            '-p', $file->getFullPath(),
27
        ], \dirname($file->getFullPath()));
28
29
        parent::__construct($file, $process);
30
    }
31
32
    /**
33
     * Returns the number of changes for a file.
34
     */
35
    public function countChanges(): int
36
    {
37
        $count = 0;
38
39
        foreach (\explode("\n", $this->getOutput()) as $row) {
40
            if (!isset($row[0]) || '=' === $row[0] || '+' === $row[0]) {
41
                continue;
42
            }
43
44
            $count++;
45
        }
46
47
        return $count;
48
    }
49
}
50