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

GetParametersCheck   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 55
ccs 0
cts 31
cp 0
rs 10
c 2
b 0
f 0
wmc 8
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
C pass() 0 35 7
A 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