for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Smoren\Validator\Rules;
use Smoren\Validator\Interfaces\IntegerRuleInterface;
use Smoren\Validator\Interfaces\NumberRuleInterface;
use Smoren\Validator\Structs\Check;
class IntegerRule extends NumberRule implements IntegerRuleInterface
{
public const ERROR_NOT_INTEGER = 'not_integer';
public const ERROR_NOT_EVEN = 'not_even';
public const ERROR_NOT_ODD = 'not_odd';
public function __construct()
$this->add(new Check(
self::ERROR_NOT_INTEGER,
fn ($value) => is_int($value),
[],
true
));
}
/**
* {@inheritDoc}
*
* @return static
*/
public function even(): self
return $this->add(new Check(
self::ERROR_NOT_EVEN,
fn ($value) => $value % 2 === 0,
public function odd(): self
self::ERROR_NOT_ODD,
fn ($value) => $value % 2 !== 0