1 | <?php |
||
17 | class EntitySimpleGetterSetter extends AbstractEntityRule |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | private $allowedPrefixes; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $whitelist; |
||
28 | |||
29 | /** |
||
30 | * @param AbstractNode|ClassNode $node |
||
31 | */ |
||
32 | 9 | public function apply(AbstractNode $node) |
|
33 | { |
||
34 | 9 | if (false === $this->isEntity($node)) { |
|
|
|||
35 | 2 | return; |
|
36 | } |
||
37 | |||
38 | 7 | $prefixes = $this->getStringProperty('prefixes'); |
|
39 | 7 | $this->allowedPrefixes = explode($this->getStringProperty('delimiter'), $prefixes); |
|
40 | 7 | $this->whitelist = explode($this->getStringProperty('delimiter'), $this->getStringProperty('whitelist')); |
|
41 | |||
42 | /** @var MethodNode $method */ |
||
43 | 7 | foreach ($node->getMethods() as $method) { |
|
44 | 7 | if (true === $this->isMethodNameOnWhitelist($method)) { |
|
45 | 1 | continue; |
|
46 | } |
||
47 | |||
48 | 6 | if (true === $this->hasCorrectPrefix($method) && true === $this->isSimpleMethod($method)) { |
|
49 | 1 | continue; |
|
50 | } |
||
51 | |||
52 | 5 | $this->addViolation($method, [$prefixes]); |
|
53 | 7 | } |
|
54 | 7 | } |
|
55 | |||
56 | /** |
||
57 | * @param MethodNode $method |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 7 | private function isMethodNameOnWhitelist(MethodNode $method) |
|
65 | |||
66 | /** |
||
67 | * @param MethodNode|ASTMethod $node |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 6 | private function hasCorrectPrefix(MethodNode $node) |
|
81 | |||
82 | /** |
||
83 | * @param MethodNode|ASTMethod $node |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 5 | private function isSimpleMethod(MethodNode $node) |
|
108 | |||
109 | /** |
||
110 | * @param MethodNode $node |
||
111 | * |
||
112 | * @return int |
||
113 | */ |
||
114 | 4 | private function countThis(MethodNode $node) |
|
127 | } |
||
128 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.