OperatorNode::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
nc 1
cc 1
eloc 2
nop 1
crap 2
1
<?php
2
3
namespace PPP\DataModel;
4
5
/**
6
 * An operator node.
7
 *
8
 * @licence AGPLv3+
9
 * @author Thomas Pellissier Tanon
10
 */
11
abstract class OperatorNode extends AbstractNode {
12
13
	/**
14
	 * @var AbstractNode[]
15
	 */
16
	private $operands;
17
18
	/**
19
	 * @param AbstractNode[] $operands
20
	 */
21
	public function __construct($operands) {
22
		$this->operands = $operands;
23
	}
24
25
	/**
26
	 * @return AbstractNode[]
27
	 */
28
	public function getOperands() {
29
		return $this->operands;
30
	}
31
32
	/**
33
	 * @see AbstractNode::equals
34
	 */
35
	public function equals($target) {
36
		if(!($target instanceof self) || count($this->operands) !== count($target->operands)) {
37
			return false;
38
		}
39
40
		foreach($this->operands as $operand1) {
41
			$matched = false;
42
			foreach($this->operands as $operand2) {
43
				if($operand1->equals($operand2)) {
44
					$matched = true;
45
					break;
46
				}
47
			}
48
			if(!$matched) {
49
				return false;
50
			}
51
		}
52
53
		return true;
54
	}
55
}
56