Passed
Pull Request — master (#260)
by Fabien
01:58
created

GitChangesCountProcess   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A countChanges() 0 3 1
1
<?php declare(strict_types = 1);
2
3
namespace Churn\Process\ChangesCount;
4
5
use Churn\File\File;
6
use Churn\Process\ChurnProcess;
7
use Churn\Process\ChangesCountInterface;
8
use function dirname;
9
use Symfony\Component\Process\Process;
10
11
class GitChangesCountProcess extends ChurnProcess implements ChangesCountInterface
12
{
13
    /**
14
     * Class constructor.
15
     * @param File   $file         The file the process is being executed on.
16
     * @param string $commitsSince String containing the date of when to look at commits since.
17
     */
18
    public function __construct(File $file, string $commitsSince)
19
    {
20
        $process = new Process([
21
            'git', '-C', dirname($file->getFullPath()), 'rev-list', '--since',
22
            $commitsSince, '--no-merges', '--count', 'HEAD',
23
            $file->getFullPath(),
24
        ]);
25
26
        parent::__construct($file, $process);
27
    }
28
29
    /**
30
     * Returns the number of changes for a file.
31
     * @return integer
32
     */
33
    public function countChanges(): int
34
    {
35
        return (int) $this->getOutput();
36
    }
37
}
38