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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 16 5
A containsClassName() 0 10 3
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