GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 10351e...ea3c3c )
by Michael
03:35
created

ConstructorNewOperator::apply()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 8.8571
cc 5
eloc 8
nc 4
nop 1
crap 5
1
<?php
2
3
namespace MS\PHPMD\Rule\Design;
4
5
use PHPMD\AbstractNode;
6
use PHPMD\AbstractRule;
7
use PHPMD\Node\MethodNode;
8
use PHPMD\Rule\MethodAware;
9
10
/**
11
 * Resolve strong dependency by simply inject the new instance via DI. So your class is more flexible.
12
 */
13
class ConstructorNewOperator extends AbstractRule implements MethodAware
14
{
15
    /**
16
     * @param AbstractNode|MethodNode $node
17
     */
18 7
    public function apply(AbstractNode $node)
19
    {
20 7
        $classReferences = $node->findChildrenOfType('ClassReference');
21
22 7
        if ('__construct' !== $node->getImage() || 0 === count($classReferences)) {
23 7
            return;
24
        }
25
26 1
        $allowedClassNames = explode($this->getStringProperty('delimiter'), $this->getStringProperty('allowedClassNames'));
27
28 1
        foreach ($classReferences as $classReference) {
29 1
            if (false === $this->containsClassName($classReference->getImage(), $allowedClassNames)) {
30 1
                $this->addViolation($classReference);
31 1
            }
32 1
        }
33 1
    }
34
35
    /**
36
     * @param string $className
37
     * @param array  $allowedClassNames
38
     *
39
     * @return bool
40
     */
41 1
    private function containsClassName($className, array $allowedClassNames)
42
    {
43 1
        foreach ($allowedClassNames as $allowedClassName) {
44 1
            if (false !== stripos($className, $allowedClassName)) {
45 1
                return true;
46
            }
47 1
        }
48
49 1
        return false;
50
    }
51
}
52