Completed
Pull Request — master (#139)
by Kévin
03:44
created

GetParametersCheck   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 31
cts 31
cp 1
rs 10
c 0
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\MagicMethod;
7
8
use PhpParser\Node\Stmt\ClassMethod;
9
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
10
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
11
use PHPSA\Check;
12
use PHPSA\Context;
13
14
class GetParametersCheck implements AnalyzerPassInterface
15
{
16
    use DefaultMetadataPassTrait;
17
18
    /**
19
     * @param ClassMethod $methodStmt
20
     * @param Context $context
21
     * @return bool
22
     */
23 23
    public function pass(ClassMethod $methodStmt, Context $context)
24
    {
25 23
        if ($methodStmt->name == '__get') {
26 1
            if (count($methodStmt->params) == 0) {
27 1
                $context->notice(
28 1
                    'magic.get.wrong-parameters',
29 1
                    'Magic method __get must take 1 parameter at least',
30 1
                    $methodStmt,
31
                    Check::CHECK_SAFE
32 1
                );
33 1
            }
34 1
        }
35
36 23
        if ($methodStmt->name == '__set') {
37 1
            if (count($methodStmt->params) < 2) {
38 1
                $context->notice(
39 1
                    'magic.get.wrong-parameters',
40 1
                    'Magic method __set must take 2 parameters at least',
41 1
                    $methodStmt,
42
                    Check::CHECK_SAFE
43 1
                );
44 1
            }
45 1
        }
46
47 23
        if ($methodStmt->name == '__clone') {
48 1
            if (count($methodStmt->params) > 0) {
49 1
                $context->notice(
50 1
                    'magic.get.wrong-parameters',
51 1
                    'Magic method __clone cannot accept arguments',
52 1
                    $methodStmt,
53
                    Check::CHECK_SAFE
54 1
                );
55 1
            }
56 1
        }
57 23
    }
58
59
    /**
60
     * @return array
61
     */
62 1
    public function getRegister()
63
    {
64
        return [
65
            \PhpParser\Node\Stmt\ClassMethod::class
66 1
        ];
67
    }
68
}
69