Code Duplication    Length = 23-23 lines in 2 locations

src/Rule/AndRule.php 1 location

@@ 193-215 (lines=23) @@
190
    /**
191
     * Remove AndRules operands of AndRules
192
     */
193
    public function removeSameOperationOperands()
194
    {
195
        foreach ($this->operands as $i => $operand) {
196
            if ( ! is_a($operand, AndRule::class)) {
197
                continue;
198
            }
199
200
            if ( ! $operands = $operand->getOperands()) {
201
                continue;
202
            }
203
204
            // Id AND is an operand on AND they can be merge (and the same with OR)
205
            foreach ($operands as $sub_operand) {
206
                $this->addOperand( $sub_operand->copy() );
207
            }
208
            unset($this->operands[$i]);
209
210
            // possibility of mono-operand or dupicates
211
            $has_been_changed = true;
212
        }
213
214
        return ! empty($has_been_changed);
215
    }
216
217
    /**
218
     * Removes rule branches that cannot produce result like:

src/Rule/OrRule.php 1 location

@@ 19-41 (lines=23) @@
16
    /**
17
     * Remove AndRules operands of AndRules and OrRules of OrRules.
18
     */
19
    public function removeSameOperationOperands(array $simplification_options)
20
    {
21
        foreach ($this->operands as $i => &$operand) {
22
            if ( ! is_a($operand, OrRule::class)) {
23
                continue;
24
            }
25
26
            if ( ! $operand->isNormalizationAllowed($simplification_options) ) {
27
                continue;
28
            }
29
30
            // Id AND is an operand on AND they can be merge (and the same with OR)
31
            foreach ($operand->getOperands() as $sub_operand) {
32
                $this->addOperand( $sub_operand->copy() );
33
            }
34
            unset($this->operands[$i]);
35
36
            // possibility of mono-operand or dupicates
37
            $has_been_changed = true;
38
        }
39
40
        return ! empty($has_been_changed);
41
    }
42
43
    /**
44
     * Replace all the OrRules of the RuleTree by one OrRule at its root.