Skip to content

Commit

Permalink
refactoring: fix multiple entity transformer validation (#202)
Browse files Browse the repository at this point in the history
* refactoring: fix multiple entity transformer validation

* f
  • Loading branch information
troytft committed Feb 15, 2022
1 parent 9c8f017 commit 0d9dc7f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Services/Mapper/Transformer/DoctrineEntityTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ private function transformSingleItem(string $class, string $fieldName, mixed $va

private function transformMultipleItems(string $class, string $fieldName, mixed $value): array
{
$firstCollectionItem = $value[0] ?? null;
$columnType = RestApiBundle\Helper\DoctrineHelper::extractColumnType($class, $fieldName);
if ($columnType === PropertyInfo\Type::BUILTIN_TYPE_INT && !is_int($value[0] ?? null)) {

if ($columnType === PropertyInfo\Type::BUILTIN_TYPE_INT && !is_numeric($firstCollectionItem)) {
throw new RestApiBundle\Exception\Mapper\Transformer\CollectionOfIntegersRequiredException();
} elseif ($columnType === PropertyInfo\Type::BUILTIN_TYPE_STRING && !is_string($value[0] ?? null)) {
} elseif ($columnType === PropertyInfo\Type::BUILTIN_TYPE_STRING && (!is_string($firstCollectionItem) && !is_numeric($firstCollectionItem))) {
throw new RestApiBundle\Exception\Mapper\Transformer\CollectionOfStringsRequiredException();
}

Expand Down

0 comments on commit 0d9dc7f

Please sign in to comment.