Completed
Pull Request — master (#64)
by
unknown
02:46
created

commandName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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;
0 ignored issues
show
Documentation Bug introduced by
$recursiveToolInterface is of type object<PhpGitHooks\Infra...RecursiveToolInterface>, but the property $phpMDHandler was declared to be of type object<PhpGitHooks\Infra...ure\PhpMD\PhpMDHandler>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

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.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
30 2
        $this->preCommitConfig = $hookConfigInterface;
0 ignored issues
show
Documentation Bug introduced by
It seems like $hookConfigInterface of type object<PhpGitHooks\Appli...nfigExtraToolInterface> is incompatible with the declared type object<PhpGitHooks\Appli...ig\HookConfigInterface> of property $preCommitConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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