for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Validator;
use Yiisoft\Arrays\ArrayHelper;
final class Result
{
/**
* @var Error[]
*/
private array $errors = [];
public function isValid(): bool
return $this->errors === [];
}
* @psalm-param list<int|string>|null $valuePath
public function addError(string $message, array $valuePath = []): void
$this->errors[] = new Error($message, $valuePath);
* @return Error[]
public function getErrorObjects(): array
return $this->errors;
* @return string[]
public function getErrors(): array
return ArrayHelper::getColumn($this->errors, function ($error) {
/** @var Error $error */
return $error->getMessage();
});
* @return array
public function getNestedErrors(): array
$valuePathCountMap = [];
$errors = [];
foreach ($this->errors as $error) {
$stringValuePath = $error->getStringValuePath();
$valuePathCount = $valuePathCountMap[$stringValuePath] ?? 0;
$errorValuePath = "$stringValuePath.$valuePathCount";
ArrayHelper::setValueByPath($errors, $errorValuePath, $error->getMessage());
$valuePathCount++;
$valuePathCountMap[$stringValuePath] = $valuePathCount;
return $errors;
public function getErrorsIndexedByPath(string $separator = '.'): array
$separator
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function getErrorsIndexedByPath(/** @scrutinizer ignore-unused */ string $separator = '.'): array
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
$errors[$error->getStringValuePath()][] = $error->getMessage();
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.