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

MercurialChangesCountProcess::countChanges()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
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 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