Completed
Pull Request — master (#139)
by Kévin
22:48 queued 19:51
created

GetParametersCheck::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 9.6666

1 Method

Rating   Name   Duplication   Size   Complexity  
A GetParametersCheck::getRegister() 0 6 1
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Analyzer\Pass\Statement;
7
8
use PhpParser\Node\Stmt\ClassMethod;
9
use PHPSA\Analyzer\Helper\ConfigurablePassTrait;
10
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
11
use PHPSA\Analyzer\Pass\ConfigurablePassInterface;
12
use PHPSA\Check;
13
use PHPSA\Context;
14
15
class GetParametersCheck implements ConfigurablePassInterface, AnalyzerPassInterface
16
{
17
    use ConfigurablePassTrait;
18
19
    /**
20
     * @param ClassMethod $methodStmt
21
     * @param Context $context
22
     * @return bool
23
     */
24
    public function pass(ClassMethod $methodStmt, Context $context)
25
    {
26
        if ($methodStmt->name == '__get') {
27
            if (count($methodStmt->params) == 0) {
28
                $context->notice(
29
                    'magic.get.wrong-parameters',
30
                    'Magic method __get must take 1 paramter at least',
31
                    $methodStmt,
32
                    Check::CHECK_SAFE
33
                );
34
            }
35
        }
36
37
        if ($methodStmt->name == '__set') {
38
            if (count($methodStmt->params) == 0) {
39
                $context->notice(
40
                    'magic.get.wrong-parameters',
41
                    'Magic method __set must take 1 paramter at least',
42
                    $methodStmt,
43
                    Check::CHECK_SAFE
44
                );
45
            }
46
        }
47
48
        if ($methodStmt->name == '__clone') {
49
            if (count($methodStmt->params) > 0) {
50
                $context->notice(
51
                    'magic.get.wrong-parameters',
52
                    'Magic method __clone cannot accept arguments',
53
                    $methodStmt,
54
                    Check::CHECK_SAFE
55
                );
56
            }
57
        }
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getRegister()
64
    {
65
        return [
66
            \PhpParser\Node\Stmt\ClassMethod::class
67
        ];
68
    }
69
}
70