for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Install GitHub App
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <[email protected]>
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Helpers\ComparisonHelper;
/**
* Abstract class to help on creating rules that compare value.
* @author Henrique Moody <[email protected]>
abstract class AbstractComparison extends AbstractRule
{
use ComparisonHelper;
* @var mixed
private $compareTo;
* Initializes the rule by setting the value to be compared to the input.
* @param mixed $maxValue
public function __construct($maxValue)
$this->compareTo = $maxValue;
}
* {@inheritdoc}
public function validate($input): bool
$left = $this->toComparable($input);
$right = $this->toComparable($this->compareTo);
if (!$this->isAbleToCompareValues($left, $right)) {
return false;
return $this->compare($left, $right);
* Compare both values and return whether the comparison is valid or not.
* @param mixed $left
* @param mixed $right
* @return bool
abstract protected function compare($left, $right): bool;