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

MagicMethodParameters   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 2

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\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