Skip to content

Commit d2d042d

Browse files
Copilotsamdark
andcommitted
Optimize ToArrayOfIntegersResolver by using inline cast
Eliminated the castValueToInt() method and use (int) cast directly in an inline closure to avoid function call overhead in array_map. Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
1 parent 8980060 commit d2d042d

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

src/Attribute/Parameter/ToArrayOfIntegersResolver.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,13 @@ public function getParameterValue(
2626
$resolvedValue = $context->getResolvedValue();
2727
if (is_iterable($resolvedValue)) {
2828
$array = array_map(
29-
$this->castValueToInt(...),
29+
static fn(mixed $value): int => (int) $value,
3030
$resolvedValue instanceof Traversable ? iterator_to_array($resolvedValue) : $resolvedValue
3131
);
3232
} else {
33-
$array = [$this->castValueToInt($resolvedValue)];
33+
$array = [(int) $resolvedValue];
3434
}
3535

3636
return Result::success($array);
3737
}
38-
39-
private function castValueToInt(mixed $value): int
40-
{
41-
return (int) $value;
42-
}
4338
}

0 commit comments

Comments
 (0)