Completed
Pull Request — master (#59)
by Bill
04:27
created

ProcessFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace Churn\Factories;
4
5
use Churn\Processes\ChurnProcess;
6
use Churn\Values\Config;
7
use Churn\Values\File;
8
use Symfony\Component\Process\Process;
9
10
class ProcessFactory
11
{
12
    /**
13
     * ProcessFactory constructor.
14
     * @param Config $config Configuration Settings.
15
     */
16
    public function __construct(Config $config)
17
    {
18
        $this->config = $config;
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * Creates a Git Commit Process that will run on $file.
23
     * @param File $file File that the process will execute on.
24
     * @return ChurnProcess
25
     */
26
    public function createGitCommitProcess(File $file): ChurnProcess
27
    {
28
        $process = new Process(
29
            'git -C ' . getcwd() . " log --since=\"" . $this->config->getCommitsSince() . "\"  --name-only --pretty=format: " . $file->getFullPath(). " | sort | uniq -c | sort -nr"
30
        );
31
32
        return new ChurnProcess($file, $process, 'GitCommitProcess');
33
    }
34
35
    /**
36
     * Creates a Cyclomatic Complexity Process that will run on $file.
37
     * @param File $file File that the process will execute on.
38
     * @return ChurnProcess
39
     */
40
    public function createCyclomaticComplexityProcess(File $file): ChurnProcess
41
    {
42
        $rootFolder = __DIR__ . '/../../';
43
44
        $process = new Process(
45
            "php {$rootFolder}CyclomaticComplexityAssessorRunner {$file->getFullPath()}"
46
        );
47
48
        return new ChurnProcess($file, $process, 'CyclomaticComplexityProcess');
49
    }
50
}
51