Skip to content

Commit

Permalink
Tweak cache behavior for SvnDriver & co to ensure null returns, refs c…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and emahorvat52 committed Jan 18, 2023
1 parent 6834c8a commit b40fdf7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Composer/Repository/Vcs/SvnDriver.php
Expand Up @@ -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)) {
Expand All @@ -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];
}

Expand Down
8 changes: 6 additions & 2 deletions src/Composer/Repository/Vcs/VcsDriver.php
Expand Up @@ -109,7 +109,7 @@ public function getComposerInformation(string $identifier): ?array
/**
* @param string $identifier
*
* @return array<string, mixed>|null
* @return array<mixed>|null
*/
protected function getBaseComposerInformation(string $identifier): ?array
{
Expand All @@ -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);
}
Expand All @@ -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) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Repository/Vcs/VcsDriverInterface.php
Expand Up @@ -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;

Expand Down

0 comments on commit b40fdf7

Please sign in to comment.