Completed
Push — master ( 3708b9...fb0aff )
by Enrico
03:36
created

MagicMethodParameters::pass()   C

Complexity

Conditions 7
Paths 27

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 7

Importance

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