Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6481: Fixed keys in array returned by VersionValidator::validate #271

Merged
merged 8 commits into from
Sep 27, 2023
40 changes: 0 additions & 40 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7070,11 +7070,6 @@ parameters:
count: 1
path: src/contracts/Repository/Validator/ContentValidator.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Validator\\\\ContentValidator\\:\\:validate\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/contracts/Repository/Validator/ContentValidator.php

-
message: "#^Class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Bookmark\\\\BookmarkList implements generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#"
count: 1
Expand Down Expand Up @@ -7500,11 +7495,6 @@ parameters:
count: 1
path: src/contracts/Repository/Values/ContentType/FieldDefinitionCollection.php

-
message: "#^Interface Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinitionCollection extends generic interface IteratorAggregate but does not specify its types\\: TKey, TValue$#"
count: 1
path: src/contracts/Repository/Values/ContentType/FieldDefinitionCollection.php

-
message: "#^Method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\ContentType\\\\FieldDefinitionCollection\\:\\:map\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -21405,11 +21395,6 @@ parameters:
count: 1
path: src/lib/Repository/Strategy/ContentValidator/ContentValidatorStrategy.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\Strategy\\\\ContentValidator\\\\ContentValidatorStrategy\\:\\:validate\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/Strategy/ContentValidator/ContentValidatorStrategy.php

-
message: "#^Property Ibexa\\\\Core\\\\Repository\\\\Strategy\\\\ContentValidator\\\\ContentValidatorStrategy\\:\\:\\$contentValidators \\(array\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Validator\\\\ContentValidator\\>\\) does not accept iterable\\.$#"
count: 1
Expand Down Expand Up @@ -21670,11 +21655,6 @@ parameters:
count: 1
path: src/lib/Repository/Validator/ContentCreateStructValidator.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\Validator\\\\ContentCreateStructValidator\\:\\:validate\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/Validator/ContentCreateStructValidator.php

-
message: "#^Cannot access property \\$value on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\|null\\.$#"
count: 2
Expand All @@ -21685,11 +21665,6 @@ parameters:
count: 1
path: src/lib/Repository/Validator/ContentUpdateStructValidator.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\Validator\\\\ContentUpdateStructValidator\\:\\:validate\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/Validator/ContentUpdateStructValidator.php

-
message: "#^Property Ibexa\\\\Core\\\\Repository\\\\Validator\\\\ContentUpdateStructValidator\\:\\:\\$contentLanguageHandler \\(Ibexa\\\\Core\\\\Persistence\\\\Legacy\\\\Content\\\\Language\\\\Handler\\) does not accept Ibexa\\\\Contracts\\\\Core\\\\Persistence\\\\Content\\\\Language\\\\Handler\\.$#"
count: 1
Expand Down Expand Up @@ -21720,16 +21695,6 @@ parameters:
count: 1
path: src/lib/Repository/Validator/UserPasswordValidator.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\Validator\\\\VersionValidator\\:\\:validate\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/Validator/VersionValidator.php

-
message: "#^Method Ibexa\\\\Core\\\\Repository\\\\Validator\\\\VersionValidator\\:\\:validate\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Repository/Validator/VersionValidator.php

-
message: "#^Call to method getValue\\(\\) on an unknown class eZ\\\\Publish\\\\API\\\\Repository\\\\Values\\\\Content\\\\Field\\.$#"
count: 1
Expand Down Expand Up @@ -56730,11 +56695,6 @@ parameters:
count: 1
path: tests/lib/Repository/ContentValidator/ContentValidatorStrategyTest.php

-
message: "#^Method class@anonymous/tests/lib/Repository/ContentValidator/ContentValidatorStrategyTest\\.php\\:87\\:\\:validate\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/lib/Repository/ContentValidator/ContentValidatorStrategyTest.php

-
message: "#^Property class@anonymous/tests/lib/Repository/ContentValidator/ContentValidatorStrategyTest\\.php\\:87\\:\\:\\$validationReturn type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
10 changes: 9 additions & 1 deletion src/contracts/Repository/Validator/ContentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ public function supports(ValueObject $object): bool;
* @param string[]|null $fieldIdentifiers List of field identifiers for partial validation or null for
* case of full validation. Empty identifiers array is equal to no validation.
*
* @return array Grouped validation errors by field definition and language code, in format:
* @phpstan-return array<
* int,
* array<
* string,
* \Ibexa\Contracts\Core\FieldType\ValidationError|\Ibexa\Contracts\Core\FieldType\ValidationError[]
* >
* >
*
* @return array Grouped validation errors by field definition ID and language code, in format:
* $returnValue[string|int $fieldDefinitionId][string $languageCode] = $fieldErrors;
Steveb-p marked this conversation as resolved.
Show resolved Hide resolved
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Countable;
use IteratorAggregate;

/**
* @phpstan-extends \IteratorAggregate<\Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition>
*/
interface FieldDefinitionCollection extends Countable, IteratorAggregate, ArrayAccess
{
/**
Expand Down
10 changes: 8 additions & 2 deletions src/lib/Repository/Validator/VersionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public function supports(ValueObject $object): bool
return $object instanceof VersionInfo;
}

/**
* @phpstan-param array{
* content?: \Ibexa\Contracts\Core\Repository\Values\Content\Content,
* translations?: string[],
* } $context
*/
public function validate(
ValueObject $object,
array $context = [],
Expand Down Expand Up @@ -73,7 +79,7 @@ public function validate(

if ($fieldType->isEmptyValue($fieldValue)) {
if ($fieldDefinition->isRequired) {
$allFieldErrors[$fieldDefinition->identifier][$languageCode] = new ValidationError(
$allFieldErrors[$fieldDefinition->id][$languageCode] = new ValidationError(
"Value for required field definition '%identifier%' with language '%languageCode%' is empty",
null,
['%identifier%' => $fieldDefinition->identifier, '%languageCode%' => $languageCode],
Expand All @@ -86,7 +92,7 @@ public function validate(
$fieldValue
);
if (!empty($fieldErrors)) {
$allFieldErrors[$fieldDefinition->identifier][$languageCode] = $fieldErrors;
$allFieldErrors[$fieldDefinition->id][$languageCode] = $fieldErrors;
alongosz marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down