Ejemplo n.º 1
0
 /**
  * Compiles the node
  *
  * @param Context $context The context
  * @param array|null $arguments Array of arguments
  * @param boolean|null $important Important flag
  * @return boolean
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     $a = $this->lvalue->compile($context);
     $b = $this->rvalue->compile($context);
     switch ($this->op) {
         case 'and':
             $result = $a && $b;
             break;
         case 'or':
             $result = $a || $b;
             break;
         default:
             $compared = Util::compareNodes($a, $b);
             // strict comparison, we cannot use switch here
             if ($compared === -1) {
                 $result = $this->op === '<' || $this->op === '=<' || $this->op === '<=';
             } elseif ($compared === 0) {
                 $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<=';
             } elseif ($compared === 1) {
                 $result = $this->op === '>' || $this->op === '>=' || $this->op === '=>';
             } else {
                 $result = false;
             }
             break;
     }
     return $this->negate ? !$result : $result;
 }
Ejemplo n.º 2
0
 /**
  * @covers       compareNodes
  * @dataProvider getDataForCompareNodes
  */
 public function testCompareNodes($expected, $a, $b)
 {
     $this->assertSame($expected, Util::compareNodes($a, $b));
 }