public function isValid(array $data, Filter $filter)
 {
     $logicalValidationSum = 0;
     $lastLogicalOperator = null;
     foreach ($filter->getOperators() as $operator) {
         if ($operator instanceof ComparisonOperatorInterface) {
             $handler = $this->handlerFactory->getHandler($operator);
             /**
              * This is based on the idea that boolean will be cast to integer (TRUE -> 1 and FALSE -> 0)
              * and that the operator 'AND' represents the mathematical '*' and 'OR' represents '+'.
              * This will happen for example: (TRUE and FALSE or TRUE and TRUE) -> (1 * 0 + 1 * 1) = 1
              */
             $currentValidation = (int) $handler->doesMatch($this->getValue($operator->getField(), $data));
             if ($lastLogicalOperator === Names::LOGICAL_OR) {
                 $logicalValidationSum = $logicalValidationSum + $currentValidation;
             } elseif ($lastLogicalOperator === Names::LOGICAL_AND) {
                 $logicalValidationSum = $logicalValidationSum * $currentValidation;
             } elseif ($lastLogicalOperator === null) {
                 $logicalValidationSum = $currentValidation;
             }
         }
         if ($operator instanceof AbstractLogicalOperator) {
             $lastLogicalOperator = $operator->getName();
         }
         if ($lastLogicalOperator === Names::LOGICAL_OR && $logicalValidationSum >= 1) {
             return true;
         }
     }
     return $logicalValidationSum >= 1 || count($filter->getOperators()) === 0;
 }
 /**
  * @return Filter|null
  */
 protected function getCurrentFilter()
 {
     if ($this->currentFilter instanceof Filter) {
         return $this->currentFilter;
     } elseif ($this->currentFilter instanceof NestedFilter) {
         return $this->currentFilter->getFilter();
     } else {
         return null;
     }
 }
 public function testSetOffset()
 {
     $this->subject = new Filter();
     $this->assertSame(null, $this->subject->getOffset(), 'init offset should ne null');
     $this->subject->setOffset(10);
     $this->assertSame(10, $this->subject->getOffset(), 'set offset correctly');
     $this->subject->setOffset('string value');
     $this->assertSame(0, $this->subject->getOffset(), 'every value is converted to int values');
 }