Completed
Push — master ( 124462...3bbcdb )
by Дмитрий
02:56
created

GetParametersCheck::__clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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\Pass\AnalyzerPassInterface;
10
use PHPSA\Analyzer\Pass\ConfigurablePassInterface;
11
use PHPSA\Check;
12
use PHPSA\Context;
13
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
14
15
class GetParametersCheck implements ConfigurablePassInterface, AnalyzerPassInterface
16
{
17
    /**
18
     * @param ClassMethod $methodStmt
19
     * @param Context $context
20
     * @return bool
21
     */
22
    public function pass(ClassMethod $methodStmt, Context $context)
23
    {
24
        if ($methodStmt->name == '__get') {
25
            if (count($methodStmt->params) == 0) {
26
                $context->notice(
27
                    'magic.get.wrong-parameters',
28
                    'Magic method __get must take 1 paramter at least',
29
                    $methodStmt,
30
                    Check::CHECK_SAFE
31
                );
32
            }
33
        }
34
35
        if ($methodStmt->name == '__set') {
36
            if (count($methodStmt->params) == 0) {
37
                $context->notice(
38
                    'magic.get.wrong-parameters',
39
                    'Magic method __set must take 1 paramter at least',
40
                    $methodStmt,
41
                    Check::CHECK_SAFE
42
                );
43
            }
44
        }
45
46
        if ($methodStmt->name == '__clone') {
47
            if (count($methodStmt->params) > 0) {
48
                $context->notice(
49
                    'magic.get.wrong-parameters',
50
                    'Magic method __clone cannot accept arguments',
51
                    $methodStmt,
52
                    Check::CHECK_SAFE
53
                );
54
            }
55
        }
56
    }
57
58
    /**
59
     * @return TreeBuilder
60
     */
61
    public function getConfiguration()
62
    {
63
        $treeBuilder = new TreeBuilder();
64
        $treeBuilder->root('method_cannot_return')
65
            ->canBeDisabled()
66
        ;
67
68
        return $treeBuilder;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getRegister()
75
    {
76
        return [
77
            \PhpParser\Node\Stmt\ClassMethod::class
78
        ];
79
    }
80
}
81