Last active
November 13, 2020 22:10
-
-
Save ArnaudLigny/204812ad76cdc31ab55deb362fe41988 to your computer and use it in GitHub Desktop.
Cecil/Util
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the Cecil/Cecil package. | |
* | |
* Copyright (c) Arnaud Ligny <[email protected]> | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
namespace Cecil\Util; | |
trait DynamicComparisons | |
{ | |
private $operatorToMethod = [ | |
'==' => 'equal', | |
'===' => 'totallyEqual', | |
'!=' => 'notEqual', | |
'>' => 'greaterThan', | |
'<' => 'lessThan', | |
]; | |
protected function is($valueA, $operation, $valueB) | |
{ | |
if ($method = $this->operatorToMethod[$operation]) { | |
return $this->$method($valueA, $valueB); | |
} | |
throw new \Exception('Unknown Dynamic Operator.'); | |
} | |
private function equal($valueA, $valueB) | |
{ | |
return $valueA == $valueB; | |
} | |
private function totallyEqual($valueA, $valueB) | |
{ | |
return $valueA === $valueB; | |
} | |
private function notEqual($valueA, $valueB) | |
{ | |
return $valueA != $valueB; | |
} | |
private function greaterThan($valueA, $valueB) | |
{ | |
return $valueA > $valueB; | |
} | |
private function lessThan($valueA, $valueB) | |
{ | |
return $valueA < $valueB; | |
} | |
private function greaterThanOrEqual($valueA, $valueB) | |
{ | |
return $valueA >= $valueB; | |
} | |
private function lessThanOrEqual($valueA, $valueB) | |
{ | |
return $valueA <= $valueB; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment