Tweak cache behavior for SvnDriver & co to ensure null returns, refs #10681

main
Jordi Boggiano 2 years ago
parent 986a260d1c
commit 29513c15da
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -148,7 +148,7 @@ class SvnDriver extends VcsDriver
throw $e; throw $e;
} }
// remember a not-existent composer.json // remember a not-existent composer.json
$composer = []; $composer = null;
} }
if ($this->shouldCache($identifier)) { if ($this->shouldCache($identifier)) {
@ -158,6 +158,11 @@ class SvnDriver extends VcsDriver
$this->infoCache[$identifier] = $composer; $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]; return $this->infoCache[$identifier];
} }

@ -109,7 +109,7 @@ abstract class VcsDriver implements VcsDriverInterface
/** /**
* @param string $identifier * @param string $identifier
* *
* @return array<string, mixed>|null * @return array<mixed>|null
*/ */
protected function getBaseComposerInformation(string $identifier): ?array protected function getBaseComposerInformation(string $identifier): ?array
{ {
@ -121,6 +121,10 @@ abstract class VcsDriver implements VcsDriverInterface
$composer = JsonFile::parseJson($composerFileContent, $identifier . ':composer.json'); $composer = JsonFile::parseJson($composerFileContent, $identifier . ':composer.json');
if ([] === $composer || !is_array($composer)) {
return null;
}
if (empty($composer['time']) && null !== ($changeDate = $this->getChangeDate($identifier))) { if (empty($composer['time']) && null !== ($changeDate = $this->getChangeDate($identifier))) {
$composer['time'] = $changeDate->format(DATE_RFC3339); $composer['time'] = $changeDate->format(DATE_RFC3339);
} }
@ -134,7 +138,7 @@ abstract class VcsDriver implements VcsDriverInterface
public function hasComposerFile(string $identifier): bool public function hasComposerFile(string $identifier): bool
{ {
try { try {
return (bool) $this->getComposerInformation($identifier); return null !== $this->getComposerInformation($identifier);
} catch (TransportException $e) { } catch (TransportException $e) {
} }

@ -32,7 +32,7 @@ interface VcsDriverInterface
* Return the composer.json file information * Return the composer.json file information
* *
* @param string $identifier Any identifier to a specific branch/tag/commit * @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; public function getComposerInformation(string $identifier): ?array;

Loading…
Cancel
Save