@@ 20-42 (lines=23) @@ | ||
17 | /** |
|
18 | * Remove AndRules operands of AndRules and OrRules of OrRules. |
|
19 | */ |
|
20 | public function removeSameOperationOperands(array $simplification_options) |
|
21 | { |
|
22 | foreach ($this->operands as $i => &$operand) { |
|
23 | if ( ! is_a($operand, OrRule::class)) { |
|
24 | continue; |
|
25 | } |
|
26 | ||
27 | if ( ! $operand->isNormalizationAllowed($simplification_options) ) { |
|
28 | continue; |
|
29 | } |
|
30 | ||
31 | // Id AND is an operand on AND they can be merge (and the same with OR) |
|
32 | foreach ($operand->getOperands() as $sub_operand) { |
|
33 | $this->addOperand( $sub_operand->copy() ); |
|
34 | } |
|
35 | unset($this->operands[$i]); |
|
36 | ||
37 | // possibility of mono-operand or dupicates |
|
38 | $has_been_changed = true; |
|
39 | } |
|
40 | ||
41 | return ! empty($has_been_changed); |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * Replace all the OrRules of the RuleTree by one OrRule at its root. |
@@ 199-221 (lines=23) @@ | ||
196 | /** |
|
197 | * Remove AndRules operands of AndRules |
|
198 | */ |
|
199 | public function removeSameOperationOperands() |
|
200 | { |
|
201 | foreach ($this->operands as $i => $operand) { |
|
202 | if ( ! is_a($operand, AndRule::class)) { |
|
203 | continue; |
|
204 | } |
|
205 | ||
206 | if ( ! $operands = $operand->getOperands()) { |
|
207 | continue; |
|
208 | } |
|
209 | ||
210 | // Id AND is an operand on AND they can be merge (and the same with OR) |
|
211 | foreach ($operands as $sub_operand) { |
|
212 | $this->addOperand( $sub_operand->copy() ); |
|
213 | } |
|
214 | unset($this->operands[$i]); |
|
215 | ||
216 | // possibility of mono-operand or dupicates |
|
217 | $has_been_changed = true; |
|
218 | } |
|
219 | ||
220 | return ! empty($has_been_changed); |
|
221 | } |
|
222 | ||
223 | /** |
|
224 | * Removes rule branches that cannot produce result like: |