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