diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index d6c7274fdeed..af29720a21c0 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -148,7 +148,7 @@ public function getComposerInformation(string $identifier): ?array throw $e; } // remember a not-existent composer.json - $composer = []; + $composer = null; } if ($this->shouldCache($identifier)) { @@ -158,6 +158,11 @@ public function getComposerInformation(string $identifier): ?array $this->infoCache[$identifier] = $composer; } + // old cache files had '' stored instead of null due to af3783b5f40bae32a23e353eaf0a00c9b8ce82e2, so we make sure here that we always return null or array + if (!is_array($this->infoCache[$identifier])) { + return null; + } + return $this->infoCache[$identifier]; } diff --git a/src/Composer/Repository/Vcs/VcsDriver.php b/src/Composer/Repository/Vcs/VcsDriver.php index 484082de02df..e53b9bd237e0 100644 --- a/src/Composer/Repository/Vcs/VcsDriver.php +++ b/src/Composer/Repository/Vcs/VcsDriver.php @@ -109,7 +109,7 @@ public function getComposerInformation(string $identifier): ?array /** * @param string $identifier * - * @return array|null + * @return array|null */ protected function getBaseComposerInformation(string $identifier): ?array { @@ -121,6 +121,10 @@ protected function getBaseComposerInformation(string $identifier): ?array $composer = JsonFile::parseJson($composerFileContent, $identifier . ':composer.json'); + if ([] === $composer || !is_array($composer)) { + return null; + } + if (empty($composer['time']) && null !== ($changeDate = $this->getChangeDate($identifier))) { $composer['time'] = $changeDate->format(DATE_RFC3339); } @@ -134,7 +138,7 @@ protected function getBaseComposerInformation(string $identifier): ?array public function hasComposerFile(string $identifier): bool { try { - return (bool) $this->getComposerInformation($identifier); + return null !== $this->getComposerInformation($identifier); } catch (TransportException $e) { } diff --git a/src/Composer/Repository/Vcs/VcsDriverInterface.php b/src/Composer/Repository/Vcs/VcsDriverInterface.php index 4a05e8d4b8db..fd5684851a6d 100644 --- a/src/Composer/Repository/Vcs/VcsDriverInterface.php +++ b/src/Composer/Repository/Vcs/VcsDriverInterface.php @@ -32,7 +32,7 @@ public function initialize(): void; * Return the composer.json file information * * @param string $identifier Any identifier to a specific branch/tag/commit - * @return mixed[]|null containing all infos from the composer.json file + * @return mixed[]|null Array containing all infos from the composer.json file, or null to denote that no file was present */ public function getComposerInformation(string $identifier): ?array;