示例#1
0
 public function testComparing()
 {
     $this->assertEquals(-1, Helper::cmp(-1, 0));
     $this->assertEquals(0, Helper::cmp(0, 0));
     $this->assertEquals(1, Helper::cmp(0, -1));
 }
示例#2
0
 public static function compare(Token $a, Token $b)
 {
     $multiplier = $a->isEnd() ? -1 : 1;
     if ($a->isStart() && $b->isEnd() || $a->isEnd() && $b->isStart()) {
         if ($a->getStart() == $b) {
             return 1;
         }
         if ($a->getEnd() == $b) {
             return -1;
         } else {
             return $multiplier;
         }
     } elseif (($rule = Helper::cmp($b->rule->priority, $a->rule->priority)) !== 0) {
         return $multiplier * $rule;
     } else {
         return $multiplier * ($a->id < $b->id ? -1 : 1);
     }
 }