Completed
Push — master ( aae171...987d4d )
by Дмитрий
07:41
created

GetParametersCheck::pass()   C

Complexity

Conditions 7
Paths 27

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 22
c 1
b 0
f 0
nc 27
nop 2
dl 0
loc 35
rs 6.7272
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
    public function __clone($name, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
20
    }
21
22
    /**
23
     * @param ClassMethod $methodStmt
24
     * @param Context $context
25
     * @return bool
26
     */
27
    public function pass(ClassMethod $methodStmt, Context $context)
28
    {
29
        if ($methodStmt->name == '__get') {
30
            if (count($methodStmt->params) == 0) {
31
                $context->notice(
32
                    'magic.get.wrong-parameters',
33
                    'Magic method __get must take 1 paramter at least',
34
                    $methodStmt,
35
                    Check::CHECK_SAFE
36
                );
37
            }
38
        }
39
40
        if ($methodStmt->name == '__set') {
41
            if (count($methodStmt->params) == 0) {
42
                $context->notice(
43
                    'magic.get.wrong-parameters',
44
                    'Magic method __set must take 1 paramter at least',
45
                    $methodStmt,
46
                    Check::CHECK_SAFE
47
                );
48
            }
49
        }
50
51
        if ($methodStmt->name == '__clone') {
52
            if (count($methodStmt->params) > 0) {
53
                $context->notice(
54
                    'magic.get.wrong-parameters',
55
                    'Magic method __clone cannot accept arguments',
56
                    $methodStmt,
57
                    Check::CHECK_SAFE
58
                );
59
            }
60
        }
61
    }
62
63
    /**
64
     * @return TreeBuilder
65
     */
66
    public function getConfiguration()
67
    {
68
        $treeBuilder = new TreeBuilder();
69
        $treeBuilder->root('method_cannot_return')
70
            ->canBeDisabled()
71
        ;
72
73
        return $treeBuilder;
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function getRegister()
80
    {
81
        return [
82
            \PhpParser\Node\Stmt\ClassMethod::class
83
        ];
84
    }
85
}
86