Skip to content

Commit cd39834

Browse files
committedOct 1, 2024··
New idToEntityId() for easier testing #10547
1 parent d41273c commit cd39834

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed
 

‎src/Testing/Api/Input/Operator/OperatorType.php

+25-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ protected function getFilteredResult(string $class, string $field, string $opera
3838
return $qb->getQuery()->getResult();
3939
}
4040

41+
/**
42+
* Parse an ID into an EntityID.
43+
*
44+
* @param class-string $entity
45+
*
46+
* @return ($id is null ? null : EntityID)
47+
*/
48+
protected function idToEntityId(string $entity, ?int $id): ?EntityID
49+
{
50+
if ($id === null) {
51+
return null;
52+
}
53+
54+
$type = _types()->getId($entity);
55+
56+
return $type->parseValue($id);
57+
}
58+
4159
/**
4260
* Parse an array of ID into an array of EntityID.
4361
*
@@ -48,13 +66,13 @@ protected function getFilteredResult(string $class, string $field, string $opera
4866
*/
4967
protected function idsToEntityIds(string $entity, ?array $ids): ?array
5068
{
51-
$type = _types()->getId($entity);
52-
$parsed = null;
53-
if ($ids !== null) {
54-
$parsed = [];
55-
foreach ($ids as $id) {
56-
$parsed[] = $type->parseValue($id);
57-
}
69+
if ($ids === null) {
70+
return null;
71+
}
72+
73+
$parsed = [];
74+
foreach ($ids as $id) {
75+
$parsed[] = $this->idToEntityId($entity, $id);
5876
}
5977

6078
return $parsed;

0 commit comments

Comments
 (0)
Please sign in to comment.