diff --git a/src/CreateHandler/CreateHandler.php b/src/CreateHandler/CreateHandler.php index 043b27e..93f0b54 100644 --- a/src/CreateHandler/CreateHandler.php +++ b/src/CreateHandler/CreateHandler.php @@ -129,12 +129,13 @@ private function getComposerAutoloaders(): array } try { + /** @var array{autoload: array{psr-4?: array|string}} $composer */ $composer = json_decode(file_get_contents($composerPath), true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $jsonException) { throw CreateHandlerException::invalidComposerJson($jsonException->getMessage()); } - if (! is_array($composer) || ! isset($composer['autoload']['psr-4'])) { + if (! isset($composer['autoload']['psr-4'])) { throw CreateHandlerException::missingComposerAutoloaders(); } @@ -142,8 +143,6 @@ private function getComposerAutoloaders(): array throw CreateHandlerException::missingComposerAutoloaders(); } - /** @psalm-var array Forcing the type because the composer spec is clear here */ - return $composer['autoload']['psr-4']; } diff --git a/src/CreateMiddleware/CreateMiddleware.php b/src/CreateMiddleware/CreateMiddleware.php index 0f271b8..ea2362d 100644 --- a/src/CreateMiddleware/CreateMiddleware.php +++ b/src/CreateMiddleware/CreateMiddleware.php @@ -134,12 +134,13 @@ private function getComposerAutoloaders(string $projectRoot): array } try { + /** @var array{autoload: array{psr-4?: array|string}} $composer */ $composer = json_decode(file_get_contents($composerPath), true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $jsonException) { throw CreateMiddlewareException::invalidComposerJson($jsonException->getMessage()); } - if (! is_array($composer) || ! isset($composer['autoload']['psr-4'])) { + if (! isset($composer['autoload']['psr-4'])) { throw CreateMiddlewareException::missingComposerAutoloaders(); } @@ -147,8 +148,6 @@ private function getComposerAutoloaders(string $projectRoot): array throw CreateMiddlewareException::missingComposerAutoloaders(); } - /** @psalm-var array Forcing this type because the composer spec is clear here */ - return $composer['autoload']['psr-4']; }