|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Churn\Processes; |
|
5
|
|
|
|
|
6
|
|
|
use Churn\Values\File; |
|
7
|
|
|
use Symfony\Component\Process\Process; |
|
8
|
|
|
|
|
9
|
|
|
class CyclomaticComplexityProcess |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The Symfony Process Component. |
|
13
|
|
|
* @var Process |
|
14
|
|
|
*/ |
|
15
|
|
|
private $process; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* GitCommitCountProcess constructor. |
|
19
|
|
|
* @param File $file The file the process is being executed on. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(File $file) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->file = $file; |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Start the process. |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function start() |
|
31
|
|
|
{ |
|
32
|
|
|
$command = $this->getCommandString(); |
|
33
|
|
|
$this->process = new Process($command); |
|
34
|
|
|
$this->process->start(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Determines if the process was successful. |
|
39
|
|
|
* @return boolean |
|
40
|
|
|
*/ |
|
41
|
|
|
public function isSuccessful(): bool |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->process->isSuccessful(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Gets the output of the process. |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getOutput(): string |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->process->getOutput(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets the file name of the file the process |
|
57
|
|
|
* is being executed on. |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getFilename(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->file->getDisplayPath(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Gets a unique key used for storing the process in data structures. |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getKey(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return 'CyclomaticComplexityProcess' . $this->file->getFullPath(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the type of this process. |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getType(): string |
|
79
|
|
|
{ |
|
80
|
|
|
return 'CyclomaticComplexityProcess'; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* The process command. |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
private function getCommandString(): string |
|
88
|
|
|
{ |
|
89
|
|
|
$rootFolder = __DIR__ . '/../../'; |
|
90
|
|
|
return "php {$rootFolder}CyclomaticComplexityAssessorRunner {$this->file->getFullPath()}"; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: