FossilChangesCountProcess   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A countChanges() 0 14 5
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
/**
13
 * @internal
14
 */
15
final class FossilChangesCountProcess extends ChurnProcess implements ChangesCountInterface
16
{
17
    /**
18
     * Class constructor.
19
     *
20
     * @param File $file The file the process is being executed on.
21
     * @param string $dateSince String containing the date of when to look at commits since (Y-m-d).
22
     */
23
    public function __construct(File $file, string $dateSince)
24
    {
25
        $process = new Process([
26
            'fossil', 'timeline', '-t', 'ci',
27
            '-W', '0', '-n', '0', 'after', $dateSince,
28
            '-p', $file->getFullPath(),
29
        ], \dirname($file->getFullPath()));
30
31
        parent::__construct($file, $process);
32
    }
33
34
    /**
35
     * Returns the number of changes for a file.
36
     */
37
    #[\Override]
38
    public function countChanges(): int
39
    {
40
        $count = 0;
41
42
        foreach (\explode("\n", $this->getOutput()) as $row) {
43
            if (!isset($row[0]) || '=' === $row[0] || '+' === $row[0]) {
44
                continue;
45
            }
46
47
            $count++;
48
        }
49
50
        return $count;
51
    }
52
}
53