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 ( b66988...b99575 )
by Michael
04:21
created

ControllerMethodName::apply()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.2
cc 4
eloc 8
nc 4
nop 1
crap 4
1
<?php
2
3
namespace MS\PHPMD\Rule\Naming;
4
5
use PHPMD\AbstractNode;
6
use PHPMD\AbstractRule;
7
use PHPMD\Node\ClassNode;
8
use PHPMD\Node\MethodNode;
9
use PHPMD\Rule\MethodAware;
10
11
/**
12
 * When the class is concrete and ends with Controller, the method names have to end with Action.
13
 */
14
class ControllerMethodName extends AbstractRule implements MethodAware
15
{
16
    /**
17
     * @param AbstractNode|MethodNode $node
18
     */
19 6
    public function apply(AbstractNode $node)
20
    {
21 6
        if (false === $this->isController($node->getParentType())) {
22 4
            return;
23
        }
24
25 2
        $allowedMethodNames = explode($this->getStringProperty('delimiter'), $this->getStringProperty('allowedMethodNames'));
26
27 2
        if (true === in_array($node->getImage(), $allowedMethodNames)) {
28 2
            return;
29
        }
30
31 2
        if ('Action' !== substr($node->getImage(), -6, 6)) {
32 2
            $this->addViolation($node);
33 2
        }
34 2
    }
35
36
    /**
37
     * @param AbstractNode $node
38
     *
39
     * @return bool
40
     */
41 6
    private function isController(AbstractNode $node)
42
    {
43 6
        if (false === $node instanceof ClassNode) {
44
            return false;
45
        }
46
47 6
        if (true === $node->isAbstract()) {
48 1
            return false;
49
        }
50
51 5
        if ('Controller' === substr($node->getImage(), -10, 10)) {
52 2
            return true;
53
        }
54
55 3
        return false;
56
    }
57
}
58