These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of PHP Mess Detector. |
||
4 | * |
||
5 | * Copyright (c) Manuel Pichler <[email protected]>. |
||
6 | * All rights reserved. |
||
7 | * |
||
8 | * Licensed under BSD License |
||
9 | * For full copyright and license information, please see the LICENSE file. |
||
10 | * Redistributions of files must retain the above copyright notice. |
||
11 | * |
||
12 | * @author Manuel Pichler <[email protected]> |
||
13 | * @copyright Manuel Pichler. All rights reserved. |
||
14 | * @license https://opensource.org/licenses/bsd-license.php BSD License |
||
15 | * @link http://phpmd.org/ |
||
16 | */ |
||
17 | |||
18 | namespace PHPMD\Node; |
||
19 | |||
20 | use PHPMD\Rule; |
||
21 | |||
22 | /** |
||
23 | * Collection of code annotations. |
||
24 | */ |
||
25 | class Annotations |
||
26 | { |
||
27 | /** |
||
28 | * Detected annotations. |
||
29 | * |
||
30 | * @var \PHPMD\Node\Annotation[] |
||
31 | */ |
||
32 | private $annotations = array(); |
||
33 | |||
34 | /** |
||
35 | * Regexp used to extract code annotations. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $regexp = '(@([a-z_][a-z0-9_]+)\(([^\)]+)\))i'; |
||
40 | |||
41 | /** |
||
42 | * Constructs a new collection instance. |
||
43 | * |
||
44 | * @param \PHPMD\AbstractNode $node |
||
45 | */ |
||
46 | 12 | public function __construct(\PHPMD\AbstractNode $node) |
|
47 | { |
||
48 | 12 | preg_match_all($this->regexp, $node->getDocComment(), $matches); |
|
0 ignored issues
–
show
|
|||
49 | 12 | foreach (array_keys($matches[0]) as $i) { |
|
50 | 6 | $name = $matches[1][$i]; |
|
51 | 6 | $value = trim($matches[2][$i], '" '); |
|
52 | |||
53 | 6 | $this->annotations[] = new Annotation($name, $value); |
|
54 | } |
||
55 | 12 | } |
|
56 | |||
57 | /** |
||
58 | * Checks if one of the annotations suppresses the given rule. |
||
59 | * |
||
60 | * @param \PHPMD\Rule $rule |
||
61 | * @return boolean |
||
62 | */ |
||
63 | 12 | public function suppresses(Rule $rule) |
|
64 | { |
||
65 | 12 | foreach ($this->annotations as $annotation) { |
|
66 | 6 | if ($annotation->suppresses($rule)) { |
|
67 | 5 | return true; |
|
68 | } |
||
69 | } |
||
70 | 9 | ||
71 | return false; |
||
72 | } |
||
73 | } |
||
74 |
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: