1 | <?php |
||
23 | class RuleSet implements \IteratorAggregate |
||
24 | { |
||
25 | /** |
||
26 | * Should this rule set force the strict mode. |
||
27 | * |
||
28 | * @var boolean |
||
29 | * @since 1.2.0 |
||
30 | */ |
||
31 | private $strict = false; |
||
32 | |||
33 | /** |
||
34 | * The name of the file where this set is specified. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $fileName = ''; |
||
39 | |||
40 | /** |
||
41 | * The name of this rule-set. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $name = ''; |
||
46 | |||
47 | /** |
||
48 | * An optional description for this rule-set. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $description = ''; |
||
53 | |||
54 | /** |
||
55 | * The violation report used by the rule-set. |
||
56 | * |
||
57 | * @var \PHPMD\Report |
||
58 | */ |
||
59 | private $report; |
||
60 | |||
61 | /** |
||
62 | * Mapping between marker interfaces and concrete context code node classes. |
||
63 | * |
||
64 | * @var array(string=>string) |
||
65 | */ |
||
66 | private $applyTo = array( |
||
67 | 'PHPMD\\Rule\\ClassAware' => 'PHPMD\\Node\\ClassNode', |
||
68 | 'PHPMD\\Rule\\FunctionAware' => 'PHPMD\\Node\\FunctionNode', |
||
69 | 'PHPMD\\Rule\\InterfaceAware' => 'PHPMD\\Node\\InterfaceNode', |
||
70 | 'PHPMD\\Rule\\MethodAware' => 'PHPMD\\Node\\MethodNode', |
||
71 | ); |
||
72 | |||
73 | /** |
||
74 | * Mapping of rules that apply to a concrete code node type. |
||
75 | * |
||
76 | * @var array(string=>array) |
||
77 | */ |
||
78 | private $rules = array( |
||
79 | 'PHPMD\\Node\\ClassNode' => array(), |
||
80 | 'PHPMD\\Node\\FunctionNode' => array(), |
||
81 | 'PHPMD\\Node\\InterfaceNode' => array(), |
||
82 | 'PHPMD\\Node\\MethodNode' => array(), |
||
83 | ); |
||
84 | |||
85 | /** |
||
86 | * Returns the file name where the definition of this rule-set comes from. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 6 | public function getFileName() |
|
94 | |||
95 | /** |
||
96 | * Sets the file name where the definition of this rule-set comes from. |
||
97 | * |
||
98 | * @param string $fileName The file name. |
||
99 | * @return void |
||
100 | */ |
||
101 | 6 | public function setFileName($fileName) |
|
105 | |||
106 | /** |
||
107 | * Returns the name of this rule-set. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 6 | public function getName() |
|
115 | |||
116 | /** |
||
117 | * Sets the name of this rule-set. |
||
118 | * |
||
119 | * @param string $name The name of this rule-set. |
||
120 | * @return void |
||
121 | */ |
||
122 | 6 | public function setName($name) |
|
126 | |||
127 | /** |
||
128 | * Returns the description text for this rule-set instance. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getDescription() |
||
136 | |||
137 | /** |
||
138 | * Sets the description text for this rule-set instance. |
||
139 | * |
||
140 | * @param string $description The description text. |
||
141 | * @return void |
||
142 | */ |
||
143 | 6 | public function setDescription($description) |
|
147 | |||
148 | /** |
||
149 | * Activates the strict mode for this rule set instance. |
||
150 | * |
||
151 | * @return void |
||
152 | * @since 1.2.0 |
||
153 | */ |
||
154 | 1 | public function setStrict() |
|
158 | |||
159 | /** |
||
160 | * Returns the violation report used by the rule-set. |
||
161 | * |
||
162 | * @return \PHPMD\Report |
||
163 | */ |
||
164 | public function getReport() |
||
168 | |||
169 | /** |
||
170 | * Sets the violation report used by the rule-set. |
||
171 | * |
||
172 | * @param \PHPMD\Report $report |
||
173 | * @return void |
||
174 | */ |
||
175 | 8 | public function setReport(Report $report) |
|
179 | |||
180 | /** |
||
181 | * This method returns a rule by its name or <b>null</b> if it doesn't exist. |
||
182 | * |
||
183 | * @param string $name |
||
184 | * @return \PHPMD\Rule |
||
185 | */ |
||
186 | 4 | public function getRuleByName($name) |
|
195 | |||
196 | /** |
||
197 | * This method returns an iterator will all rules that belong to this |
||
198 | * rule-set. |
||
199 | * |
||
200 | * @return \Iterator |
||
201 | */ |
||
202 | 4 | public function getRules() |
|
215 | |||
216 | /** |
||
217 | * Adds a new rule to this rule-set. |
||
218 | * |
||
219 | * @param \PHPMD\Rule $rule |
||
220 | * @return void |
||
221 | */ |
||
222 | 9 | public function addRule(Rule $rule) |
|
230 | |||
231 | /** |
||
232 | * Applies all registered rules that match against the concrete node type. |
||
233 | * |
||
234 | * @param \PHPMD\AbstractNode $node |
||
235 | * @return void |
||
236 | */ |
||
237 | 8 | public function apply(AbstractNode $node) |
|
257 | |||
258 | /** |
||
259 | * Returns an iterator with all rules that are part of this rule-set. |
||
260 | * |
||
261 | * @return \Iterator |
||
262 | */ |
||
263 | public function getIterator() |
||
267 | } |
||
268 |