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.

ConstructorNewOperator::apply()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4222
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5
1
<?php
2
3
namespace MS\PHPMD\Rule\CleanCode;
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 23
    public function apply(AbstractNode $node)
19
    {
20 23
        $classReferences = $node->findChildrenOfType('ClassReference');
21
22 23
        if ('__construct' !== $node->getImage() || 0 === count($classReferences)) {
23 23
            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