|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpGitHooks\Application\PhpMD; |
|
4
|
|
|
|
|
5
|
|
|
use PhpGitHooks\Application\Config\HookConfigExtraToolInterface; |
|
6
|
|
|
use PhpGitHooks\Application\Config\HookConfigInterface; |
|
7
|
|
|
use PhpGitHooks\Infrastructure\Common\PreCommitExecutor; |
|
8
|
|
|
use PhpGitHooks\Infrastructure\Common\RecursiveToolInterface; |
|
9
|
|
|
use PhpGitHooks\Infrastructure\PhpMD\PhpMDHandler; |
|
10
|
|
|
use PhpGitHooks\Infrastructure\PhpMD\PHPMDViolationsException; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class CheckPhpMessDetectionPreCommitExecutor. |
|
15
|
|
|
*/ |
|
16
|
|
|
class CheckPhpMessDetectionPreCommitExecutor extends PreCommitExecutor |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var PhpMDHandler */ |
|
19
|
|
|
private $phpMDHandler; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param HookConfigExtraToolInterface $hookConfigInterface |
|
23
|
|
|
* @param RecursiveToolInterface $recursiveToolInterface |
|
24
|
|
|
*/ |
|
25
|
2 |
|
public function __construct( |
|
26
|
|
|
HookConfigExtraToolInterface $hookConfigInterface, |
|
27
|
|
|
RecursiveToolInterface $recursiveToolInterface |
|
28
|
|
|
) { |
|
29
|
2 |
|
$this->phpMDHandler = $recursiveToolInterface; |
|
|
|
|
|
|
30
|
2 |
|
$this->preCommitConfig = $hookConfigInterface; |
|
|
|
|
|
|
31
|
2 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
2 |
|
protected function commandName() |
|
37
|
|
|
{ |
|
38
|
2 |
|
return 'phpmd'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param OutputInterface $output |
|
43
|
|
|
* @param array $files |
|
44
|
|
|
* @param string $needle |
|
45
|
|
|
* |
|
46
|
|
|
* @throws PHPMDViolationsException |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function run(OutputInterface $output, array $files, $needle) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$data = $this->preCommitConfig->extraOptions($this->commandName()); |
|
51
|
|
|
|
|
52
|
2 |
|
if (true === $data['enabled']) { |
|
53
|
|
|
$this->phpMDHandler->setOutput($output); |
|
54
|
|
|
$this->phpMDHandler->setMinimumPriority(isset($data['minimum-priority']) ? intval($data['minimum-priority']) : 1); |
|
55
|
|
|
$this->phpMDHandler->setFiles($files); |
|
56
|
|
|
$this->phpMDHandler->setNeedle($needle); |
|
57
|
|
|
$this->phpMDHandler->run($this->getMessages()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.