1 | <?php |
||
28 | class LongParameterList extends AbstractRule implements FunctionAware, MethodAware |
||
29 | { |
||
30 | /** |
||
31 | * This method checks the number of arguments for the given function or method |
||
32 | * node against a configured threshold. |
||
33 | * |
||
34 | * @param \PHPMD\AbstractNode $node |
||
35 | * @return void |
||
36 | */ |
||
37 | 8 | public function apply(AbstractNode $node) |
|
38 | { |
||
39 | 8 | $threshold = $this->getIntProperty('minimum'); |
|
40 | 8 | $count = $node->getParameterCount(); |
|
|
|||
41 | 8 | if ($count < $threshold) { |
|
42 | 4 | return; |
|
43 | } |
||
44 | |||
45 | 4 | $exceptions = $this->getExceptionsList(); |
|
46 | |||
47 | 4 | if (in_array($node->getName(), $exceptions, true)) { |
|
48 | return; |
||
49 | } |
||
50 | |||
51 | 4 | $this->addViolation( |
|
52 | 4 | $node, |
|
53 | array( |
||
54 | 4 | $node->getType(), |
|
55 | 4 | $node->getName(), |
|
56 | 4 | $count, |
|
57 | 4 | $threshold |
|
58 | ) |
||
59 | ); |
||
60 | 4 | } |
|
61 | |||
62 | /** |
||
63 | * Gets array of exceptions from property |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | 4 | private function getExceptionsList() |
|
77 | } |
||
78 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: