for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Phypes\Rule\String;
use Phypes\Error\RuleError;
use Phypes\Error\RuleErrorCode;
use Phypes\Result;
use Phypes\Rule\Primitive\StringType;
use Phypes\Rule\Rule;
class MinimumLength implements Rule
{
private $minLength;
public function __construct(int $minLength)
$this->minLength = $minLength;
}
public function validate($data) : Result\Result
$result = (new StringType())->validate($data);
if (!$result->isValid())
return new $result;
if (mb_strlen($data, 'UTF-8') >= $this->minLength) {
return new Result\Success();
else return new Result\Failure(
new RuleError(RuleErrorCode::LENGTH_ERROR,
'The supplied string is too short'));