From 8c1bc60af47676dc93988d3e3c21165954c58f40 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 7 Mar 2024 10:11:41 +0300 Subject: [PATCH] Clarify psalm types in `Result` (#668) --- CHANGELOG.md | 1 + composer-require-checker.json | 5 ++++- src/Result.php | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a84ff5..1ae77f8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.3.0 under development - New #665: Add methods `addErrorWithFormatOnly()` and `addErrorWithoutPostProcessing()` to `Result` object (@vjik) +- Enh #668: Clarify psalm types in `Result` (@vjik) ## 1.2.0 February 21, 2024 diff --git a/composer-require-checker.json b/composer-require-checker.json index a255432f..cfd850c6 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -1,7 +1,10 @@ { "symbol-whitelist": [ "Yiisoft\\Yii\\Debug\\Collector\\CollectorTrait", - "Yiisoft\\Yii\\Debug\\Collector\\SummaryCollectorInterface" + "Yiisoft\\Yii\\Debug\\Collector\\SummaryCollectorInterface", + "JetBrains\\PhpStorm\\ArrayShape", + "JetBrains\\PhpStorm\\ExpectedValues", + "JetBrains\\PhpStorm\\Language" ], "php-core-extensions": [ "Core", diff --git a/src/Result.php b/src/Result.php index 4427ee52..6ea726f1 100644 --- a/src/Result.php +++ b/src/Result.php @@ -17,6 +17,7 @@ final class Result { /** * @var Error[] Validation errors. + * @psalm-var list */ private array $errors = []; @@ -51,6 +52,7 @@ public function isAttributeValid(string $attribute): bool /** * @return Error[] Validation errors. + * @psalm-return list */ public function getErrors(): array { @@ -61,6 +63,7 @@ public function getErrors(): array * Get errors messages as an array of strings. * * @return string[] Array messages as strings. + * @psalm-return list */ public function getErrorMessages(): array { @@ -121,6 +124,8 @@ public function getErrorMessagesIndexedByAttribute(): array * @param string $attribute Attribute name. * * @return Error[] Array of error objects. + * + * @psalm-return list */ public function getAttributeErrors(string $attribute): array { @@ -139,6 +144,8 @@ public function getAttributeErrors(string $attribute): array * Get an array of error messages for the attribute specified. * * @return string[] Error messages. + * + * @psalm-return list */ public function getAttributeErrorMessages(string $attribute): array { @@ -190,6 +197,8 @@ public function getAttributeErrorMessagesIndexedByPath( * Get common error messages that are not attached to any attribute. * * @return string[] Error messages. + * + * @psalm-return list */ public function getCommonErrorMessages(): array {