-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AssertListItem: fix passing correct item type to inner validator
- Loading branch information
Showing
4 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
tests/Compiler/Validator/Array/Data/ListItemValidatorCalledWithCorrectItemTypeMapper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php declare (strict_types=1); | ||
|
||
namespace ShipMonkTests\InputMapper\Compiler\Validator\Array\Data; | ||
|
||
use ShipMonk\InputMapper\Compiler\Mapper\Wrapper\ValidatedMapperCompiler; | ||
use ShipMonk\InputMapper\Runtime\Exception\MappingFailedException; | ||
use ShipMonk\InputMapper\Runtime\Mapper; | ||
use ShipMonk\InputMapper\Runtime\MapperProvider; | ||
use function array_is_list; | ||
use function is_array; | ||
use function is_int; | ||
|
||
/** | ||
* Generated mapper by {@see ValidatedMapperCompiler}. Do not edit directly. | ||
* | ||
* @implements Mapper<list<int>> | ||
*/ | ||
class ListItemValidatorCalledWithCorrectItemTypeMapper implements Mapper | ||
{ | ||
public function __construct(private readonly MapperProvider $provider) | ||
{ | ||
} | ||
|
||
/** | ||
* @param list<string|int> $path | ||
* @return list<int> | ||
* @throws MappingFailedException | ||
*/ | ||
public function map(mixed $data, array $path = []): array | ||
{ | ||
if (!is_array($data) || !array_is_list($data)) { | ||
throw MappingFailedException::incorrectType($data, $path, 'list'); | ||
} | ||
|
||
$mapped = []; | ||
|
||
foreach ($data as $index => $item) { | ||
if (!is_int($item)) { | ||
throw MappingFailedException::incorrectType($item, [...$path, $index], 'int'); | ||
} | ||
|
||
$mapped[] = $item; | ||
} | ||
|
||
foreach ($mapped as $index2 => $item2) { | ||
} | ||
|
||
return $mapped; | ||
} | ||
} |