/** * Checks whether intersection exsits among all AND conditions within * these composites. * * @param ConditionComposite $ANDComposite1 * @param ConditionComposite $ANDComposite2 * * @throws ImpossibleToLookForIntersection * @return boolean if intersection exist among all AND conditions * withing these composites */ protected function intersectionExistsBetween(ConditionComposite $ANDComposite1, ConditionComposite $ANDComposite2) { $setOfANDConditions1 = $ANDComposite1->getANDConditions(); $setOfANDConditions2 = $ANDComposite2->getANDConditions(); foreach ($setOfANDConditions1 as $ANDCondition1) { foreach ($setOfANDConditions2 as $ANDCondition2) { if (false === $this->leafIntersectDetector->intersectExists($ANDCondition1, $ANDCondition2)) { return false; } } } return true; }
/** * Turns (A AND B) into [[A, B]]. * * @see ORDecomposer::decomposeORConditionsOf() for supporting OR-branches like * (A AND (B OR C)) into [[A, B], [A, C]]. * @param ConditionComposite $c * * @return array [[Condition, Condition], [Condition]] */ protected function decomposeANDConditionsOf(ConditionComposite $c) { $ANDConditions = $c->getANDConditions(); if (empty($ANDConditions)) { return []; } $decomposedANDConditions = array_map(function (Condition $c) { return $this->decompose($c); }, $ANDConditions); return array_reduce($decomposedANDConditions, function ($result, $ANDConditions) { return $this->mergeConditionsIntoChains($ANDConditions, $result); }, [[]]); }
protected function decomposeRow(ConditionComposite $c) { if (false === empty($c->getORConditions())) { throw new InvalidArgumentException("in this test there should be no OR conditions"); } $result = []; foreach ($c->getANDConditions() as $c) { if ($c instanceof ConditionComposite) { throw new InvalidArgumentException("in this test there should be no composite"); } $result[] = $c; } return $result; }
/** * Compares composites that contain only AND conditions (that are not composites). * * @param ConditionComposite $comp1 * @param ConditionComposite $comp2 * * @throws IncomparableConditions when it's not possible to compare leaves * @return boolean */ protected function ANDCompositesAreEqual(ConditionComposite $comp1, ConditionComposite $comp2) { return ArrayComparator::arraysHoldEqualElements($comp1->getANDConditions(), $comp2->getANDConditions(), function (Condition $c1, Condition $c2) { return $this->leafEqualityComparator->equal($c1, $c2); }); }