@@ -11,22 +11,34 @@ final class Package implements PackageInterface
1111{
1212 /**
1313 * @param non-empty-string $packageName
14- * @return non-empty-string[]
14+ *
15+ * @return string[]
16+ *
17+ * @psalm-return list<non-empty-string>
1518 */
19+ #[\Override]
1620 public function getRequiredVersions (string $ packageName ): array
1721 {
1822 $ versions = [];
1923 foreach (InstalledVersions::getInstalledPackages () as $ package ) {
2024 $ path = InstalledVersions::getInstallPath ($ package );
2125 if ($ path !== null && \file_exists ($ path . '/composer.json ' )) {
2226 /** @var array{require?: array<non-empty-string, non-empty-string>} $composerJson */
23- $ composerJson = \json_decode (\file_get_contents ($ path . '/composer.json ' ), true );
27+ $ fileContent = \file_get_contents ($ path . '/composer.json ' );
28+ /** @var array<string, mixed>|null $composerJson */
29+ $ composerJson = $ fileContent === false ? null : \json_decode ($ fileContent , true );
30+
31+ if (isset ($ composerJson ['require ' ][$ packageName ])) {
32+ /** @var mixed $rawPackage */
33+ $ rawPackage = $ composerJson ['require ' ][$ packageName ];
34+
35+ if (is_string ($ rawPackage ) && strlen ($ rawPackage ) > 0 ) {
36+ assert ($ rawPackage !== '' );
2437
25- if (
26- isset ($ composerJson ['require ' ][$ packageName ]) &&
27- $ this ->isSupportedVersion ($ composerJson ['require ' ][$ packageName ])
28- ) {
29- $ versions [] = $ this ->getMinVersion ($ composerJson ['require ' ][$ packageName ]);
38+ if ($ this ->isSupportedVersion ($ rawPackage )) {
39+ $ versions [] = $ this ->getMinVersion ($ rawPackage );
40+ }
41+ }
3042 }
3143 }
3244 }
0 commit comments