for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of Dimtrovich/Validation.
*
* (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Dimtrovich\Validation\Rules;
class MultipleOf extends AbstractRule
{
* @var array
protected $fillableParams = ['value'];
* {@inheritDoc}
public function check($value): bool
$this->requireParameters($this->fillableParams);
if (is_int($value) || is_float($value)) {
$value = (string) $value;
}
if (! is_string($value)) {
return false;
if (! is_numeric($compare = $this->parameter('value'))) {
$compare = $this->getAttribute()->getValue($compare);
if (! is_numeric($value) || ! is_numeric($compare) || ((int) $compare === 0 && (int) $value === 0)) {
if ((int) $value === 0) {
return true;
if ((int) $compare === 0) {
return $value % $compare === 0;