Passed
Push — master ( d475b6...1e5be3 )
by Fabien
02:11
created

createCyclomaticComplexityProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace Churn\Process;
4
5
use Churn\Values\File;
6
use function getcwd;
7
use Symfony\Component\Process\PhpExecutableFinder;
8
use Symfony\Component\Process\Process;
9
10
class ProcessFactory
11
{
12
    /**
13
     * String containing the date of when to look at commits since.
14
     * @var string
15
     */
16
    private $commitsSince;
17
18
    /**
19
     * ProcessFactory constructor.
20
     * @param string $commitsSince String containing the date of when to look at commits since.
21
     */
22
    public function __construct(string $commitsSince)
23
    {
24
        $this->commitsSince = $commitsSince;
25
    }
26
27
    /**
28
     * Creates a Git Commit Process that will run on $file.
29
     * @param File $file File that the process will execute on.
30
     * @return ChurnProcess
31
     */
32
    public function createGitCommitProcess(File $file): ChurnProcess
33
    {
34
        $process = new Process([
35
            'git', '-C', getcwd(), 'rev-list', '--since',
36
            $this->commitsSince, '--no-merges', '--count', 'HEAD',
37
            $file->getFullPath(),
38
            ]);
39
40
        return new ChurnProcess($file, $process, 'GitCommitProcess');
41
    }
42
43
    /**
44
     * Creates a Cyclomatic Complexity Process that will run on $file.
45
     * @param File $file File that the process will execute on.
46
     * @return ChurnProcess
47
     */
48
    public function createCyclomaticComplexityProcess(File $file): ChurnProcess
49
    {
50
        $php = (new PhpExecutableFinder())->find();
51
        $script = __DIR__ . '/../../bin/CyclomaticComplexityAssessorRunner';
52
        $process = new Process([$php, $script, $file->getFullPath()]);
53
54
        return new ChurnProcess($file, $process, 'CyclomaticComplexityProcess');
55
    }
56
}
57