for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Smoren\Validator\Rules;
use Smoren\Validator\Exceptions\ValidationSuccessException;
use Smoren\Validator\Exceptions\ValidationError;
use Smoren\Validator\Interfaces\BaseRuleInterface;
abstract class BaseRule implements BaseRuleInterface
{
public const ERROR_NULL = 'null';
/**
* @var bool
*/
protected bool $isNullable = false;
* {@inheritDoc}
*
* @return static
public function nullable(): self
$this->isNullable = true;
return $this;
}
* @throws ValidationSuccessException
public function validate($value): void
if ($value === null) {
if ($this->isNullable) {
throw new ValidationSuccessException();
throw new ValidationError($value, [[self::ERROR_NULL, []]]);