Passed
Pull Request — master (#282)
by Fabien
02:58
created

MercurialChangesCountProcess   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A countChanges() 0 3 1
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 MercurialChangesCountProcess 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
            'hg', '--pager=never', '--color=never',
25
            'log', '--date', "$dateSince to now",
26
            $file->getFullPath(), '--template=\'1\\n\'',
27
        ]);
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
        return \substr_count($this->getOutput(), "\n");
38
    }
39
}
40