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.
Test Failed
Push — master ( ea3c3c...758782 )
by Michael
03:51
created

MemberPrimaryPrefix   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B apply() 0 16 5
A getMemberPrimaryPrefixWithChainCount() 0 12 3
1
<?php
2
3
namespace MS\PHPMD\Rule\CleanCode;
4
5
use MS\PHPMD\Guesser\TestGuesser;
6
use PHPMD\AbstractNode;
7
use PHPMD\AbstractRule;
8
use PHPMD\Node\ClassNode;
9
use PHPMD\Rule\ClassAware;
10
11
/**
12
 * Don't chain methods excessively. The code becomes hard to test and violate the law of demeter.
13
 */
14
class MemberPrimaryPrefix extends AbstractRule implements ClassAware
15
{
16
    use TestGuesser;
17
18
    /**
19
     * @param AbstractNode|ClassNode $node
20
     */
21
    public function apply(AbstractNode $node)
22
    {
23
        if (true === $this->isTest($node)) {
0 ignored issues
show
Compatibility introduced by
$node of type object<PHPMD\AbstractNode> is not a sub-type of object<PHPMD\Node\ClassNode>. It seems like you assume a child class of the class PHPMD\AbstractNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
24
            return;
25
        }
26
27
        $maxChainCount = $this->getIntProperty('maxChainCount');
28
29
        foreach ($node->getMethods() as $method) {
30
            foreach ($method->findChildrenOfType('MemberPrimaryPrefix') as $memberPrimaryPrefix) {
31
                if (null !== $this->getMemberPrimaryPrefixWithChainCount($memberPrimaryPrefix, $maxChainCount)) {
32
                    $this->addViolation($memberPrimaryPrefix, [$maxChainCount]);
33
                }
34
            }
35
        }
36
    }
37
38
    /**
39
     * @param AbstractNode $memberPrimaryPrefix
40
     * @param int          $chainCount
41
     *
42
     * @return null|AbstractNode
43
     */
44
    private function getMemberPrimaryPrefixWithChainCount(AbstractNode $memberPrimaryPrefix, $chainCount)
45
    {
46
        for ($chain = 0; $chain < $chainCount; $chain++) {
47
            if (null === $memberPrimaryPrefix) {
48
                return null;
49
            }
50
51
            $memberPrimaryPrefix = $memberPrimaryPrefix->getFirstChildOfType('MemberPrimaryPrefix');
52
        }
53
54
        return $memberPrimaryPrefix;
55
    }
56
}
57