| @@ 10-70 (lines=61) @@ | ||
| 7 | */ |
|
| 8 | namespace JClaveau\LogicalFilter\Rule; |
|
| 9 | ||
| 10 | class BetweenOrEqualLowerRule extends BetweenRule |
|
| 11 | { |
|
| 12 | /** @var string operator */ |
|
| 13 | const operator = '=><'; |
|
| 14 | ||
| 15 | /** |
|
| 16 | */ |
|
| 17 | public function __construct( $field, array $limits ) |
|
| 18 | { |
|
| 19 | if ($limits[0] == $limits[1]) { |
|
| 20 | // (A = 1 || A > 1) && A < 1 <=> no sens |
|
| 21 | // So if the two limits are equal we only consider the equality |
|
| 22 | $this->addOperand( new EqualRule($field, $limits[0]) ); |
|
| 23 | $this->addOperand( new EqualRule($field, $limits[0]) ); |
|
| 24 | } |
|
| 25 | else { |
|
| 26 | $this->addOperand( new AboveOrEqualRule($field, $limits[0]) ); |
|
| 27 | $this->addOperand( new BelowRule($field, $limits[1]) ); |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @return mixed |
|
| 33 | */ |
|
| 34 | public function getMinimum() |
|
| 35 | { |
|
| 36 | if ($this->getOperandAt(0) instanceof EqualRule) { |
|
| 37 | return $this->getOperandAt(0)->getValue(); |
|
| 38 | } |
|
| 39 | ||
| 40 | return $this->getOperandAt(0)->getMinimum(); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @return mixed |
|
| 45 | */ |
|
| 46 | public function getMaximum() |
|
| 47 | { |
|
| 48 | if ( ! $this->getOperandAt(1)) { |
|
| 49 | return $this->getOperandAt(0)->getValue(); |
|
| 50 | } |
|
| 51 | ||
| 52 | if ($this->getOperandAt(1) instanceof EqualRule) { |
|
| 53 | return $this->getOperandAt(1)->getValue(); |
|
| 54 | } |
|
| 55 | ||
| 56 | return $this->getOperandAt(1)->getMaximum(); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | */ |
|
| 61 | public function getValues() |
|
| 62 | { |
|
| 63 | return [ |
|
| 64 | $this->getMinimum(), |
|
| 65 | $this->getMaximum(), |
|
| 66 | ]; |
|
| 67 | } |
|
| 68 | ||
| 69 | /**/ |
|
| 70 | } |
|
| 71 | ||
| @@ 10-70 (lines=61) @@ | ||
| 7 | */ |
|
| 8 | namespace JClaveau\LogicalFilter\Rule; |
|
| 9 | ||
| 10 | class BetweenOrEqualUpperRule extends BetweenRule |
|
| 11 | { |
|
| 12 | /** @var string operator */ |
|
| 13 | const operator = '><='; |
|
| 14 | ||
| 15 | /** |
|
| 16 | */ |
|
| 17 | public function __construct( $field, array $limits ) |
|
| 18 | { |
|
| 19 | if ($limits[0] == $limits[1]) { |
|
| 20 | // A > 1 && (A = 1 || A < 1) <=> no sens |
|
| 21 | // So if the two limits are equal we only consider the equality |
|
| 22 | $this->addOperand( new EqualRule($field, $limits[0]) ); |
|
| 23 | $this->addOperand( new EqualRule($field, $limits[0]) ); |
|
| 24 | } |
|
| 25 | else { |
|
| 26 | $this->addOperand( new AboveRule($field, $limits[0]) ); |
|
| 27 | $this->addOperand( new BelowOrEqualRule($field, $limits[1]) ); |
|
| 28 | } |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @return mixed |
|
| 33 | */ |
|
| 34 | public function getMinimum() |
|
| 35 | { |
|
| 36 | if ($this->getOperandAt(0) instanceof EqualRule) { |
|
| 37 | return $this->getOperandAt(0)->getValue(); |
|
| 38 | } |
|
| 39 | ||
| 40 | return $this->getOperandAt(0)->getMinimum(); |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @return mixed |
|
| 45 | */ |
|
| 46 | public function getMaximum() |
|
| 47 | { |
|
| 48 | if ( ! $this->getOperandAt(1)) { |
|
| 49 | return $this->getOperandAt(0)->getValue(); |
|
| 50 | } |
|
| 51 | ||
| 52 | if ($this->getOperandAt(1) instanceof EqualRule) { |
|
| 53 | return $this->getOperandAt(1)->getValue(); |
|
| 54 | } |
|
| 55 | ||
| 56 | return $this->getOperandAt(1)->getMaximum(); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | */ |
|
| 61 | public function getValues() |
|
| 62 | { |
|
| 63 | return [ |
|
| 64 | $this->getMinimum(), |
|
| 65 | $this->getMaximum(), |
|
| 66 | ]; |
|
| 67 | } |
|
| 68 | ||
| 69 | /**/ |
|
| 70 | } |
|
| 71 | ||