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.

AbstractNumberOf   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 0
loc 83
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 18 4
A count() 0 13 3
A isMethodPostfixInNames() 0 8 2
A isMethodPostfixContainsNames() 0 10 3
1
<?php
2
3
namespace MS\PHPMD\Rule\Test;
4
5
use PHPMD\Node\ClassNode;
6
use PHPMD\Node\MethodNode;
7
use PHPMD\AbstractNode;
8
9
/**
10
 */
11
abstract class AbstractNumberOf extends AbstractTest
12
{
13
    /**
14
     * @var array
15
     */
16
    private $names;
17
18
    /**
19
     * @var bool
20
     */
21
    private $match;
22
23
    /**
24
     * @param AbstractNode|ClassNode $node
25
     */
26 3
    public function apply(AbstractNode $node)
27
    {
28 3
        if (false === $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...
29 1
            return;
30
        }
31
32 2
        $this->names = explode($this->getStringProperty('delimiter'), $this->getStringProperty('names'));
33 2
        $this->match = $this->getBooleanProperty('match');
34 2
        $number = $this->getIntProperty('number');
35
36 2
        foreach ($node->getMethods() as $method) {
37 2
            $count = $this->count($method);
38
39 2
            if ($number < $count) {
40 2
                $this->addViolation($method, [$count, $number]);
41 2
            }
42 2
        }
43 2
    }
44
45
    /**
46
     * @param MethodNode $node
47
     *
48
     * @return int
49
     */
50 2
    private function count(MethodNode $node)
51
    {
52 2
        $count = 0;
53 2
        $methodPostfixes = $node->findChildrenOfType('MethodPostfix');
54
55 2
        foreach ($methodPostfixes as $methodPostfix) {
56 2
            if (true === $this->isMethodPostfixInNames($methodPostfix)) {
57 2
                $count++;
58 2
            }
59 2
        }
60
61 2
        return $count;
62
    }
63
64
    /**
65
     * @param AbstractNode $methodPostfix
66
     *
67
     * @return bool
68
     */
69 2
    private function isMethodPostfixInNames(AbstractNode $methodPostfix)
70
    {
71 2
        if (true === $this->match) {
72 2
            return in_array($methodPostfix->getImage(), $this->names);
73
        }
74
75 2
        return $this->isMethodPostfixContainsNames($methodPostfix);
76
    }
77
78
    /**
79
     * @param AbstractNode $methodPostfix
80
     *
81
     * @return bool
82
     */
83 2
    private function isMethodPostfixContainsNames(AbstractNode $methodPostfix)
84
    {
85 2
        foreach ($this->names as $name) {
86 2
            if (false !== strpos($methodPostfix->getImage(), $name)) {
87 2
                return true;
88
            }
89 2
        }
90
91 2
        return false;
92
    }
93
}
94