for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Cubiche package.
*
* Copyright (c) Cubiche
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cubiche\Core\Comparable;
* Comparator Trait.
* @author Karel Osorio Ramírez <[email protected]>
* @author Ivannis Suárez Jerez <[email protected]>
trait ComparatorTrait
{
* @param string $method
* @param array $arguments
* @throws \BadMethodCallException
public function __call($method, array $arguments)
if ($method === 'or') {
return \call_user_func_array(array($this, 'orX'), $arguments);
}
throw new \BadMethodCallException(\sprintf('Call to undefined method %s::%s', \get_class($this), $method));
* {@inheritdoc}
public function compare($a, $b)
if ($a instanceof ComparableInterface) {
return $a->compareTo($b);
return $a < $b ? -1 : ($a == $b ? 0 : 1);
public function reverse()
return new ReverseComparator($this);
public function orX(ComparatorInterface $other)
return new MultiComparator($this, $other);