Skip to content

Commit

Permalink
qa: revert ReflectionClass#newInstance* usage due to performance re…
Browse files Browse the repository at this point in the history
…gression

Signed-off-by: Maximilian Bösing <[email protected]>
  • Loading branch information
boesing committed Feb 23, 2023
1 parent a7e0bf4 commit 94809b2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/AbstractFactory/ReflectionBasedAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ public function __invoke(ContainerInterface $container, string $requestedName, ?

$constructor = $reflectionClass->getConstructor();
if (null === $constructor) {
return $reflectionClass->newInstanceWithoutConstructor();
/** @psalm-suppress MixedMethodCall We do assert that service without a constructor can be instantiated */
return new $requestedName();
}

$reflectionParameters = $constructor->getParameters();

if ($reflectionParameters === []) {
return $reflectionClass->newInstance();
/** @psalm-suppress MixedMethodCall We do assert that service with without dependencies can be instantiated */
return new $requestedName();
}

$resolver = $container->has('config')
Expand All @@ -133,7 +135,8 @@ public function __invoke(ContainerInterface $container, string $requestedName, ?

$parameters = array_map($resolver, $reflectionParameters);

return $reflectionClass->newInstance(...$parameters);
/** @psalm-suppress MixedMethodCall We do trust the parameter resolver to provide proper parameters */
return new $requestedName(...$parameters);
}

/** {@inheritDoc} */
Expand Down

0 comments on commit 94809b2

Please sign in to comment.