Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jobs:
- operating-system: ubuntu-latest
php-versions: "8.2"
coverage: pcov
exclude:
# Temporarily disabled: GitHub Actions macOS runners currently fail
# to set up PHP 8.5. Re-enable once the runner image is fixed.
- operating-system: macos-latest
php-versions: "8.5"

steps:
- name: Checkout
Expand Down
19 changes: 5 additions & 14 deletions src/Cache/AnalysisResultCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class AnalysisResultCache
* their shape or naming changes: it is recorded in the metadata marker,
* so a cache written by an older format is cleared on its next use.
*/
public const FORMAT_VERSION = 14;
public const FORMAT_VERSION = 15;

private readonly string $cacheDirectory;

Expand Down Expand Up @@ -297,7 +297,7 @@ private function analysisNodePayload(string $file, string $namespace): ?array
{
$payload = $this->read($this->analysisNodesKey($file, $namespace));

if ($payload === null || ($payload['metadata'] ?? null) !== $this->fileMetadata($file, $namespace)) {
if ($payload === null || ($payload['metadata'] ?? null) !== $this->fileHashProvider->hash($file)) {
return null;
}

Expand Down Expand Up @@ -409,8 +409,10 @@ public function storeAnalysisNodes(
): void {
$this->ensureCacheInitialised();

// The namespace is already part of the file name, so the payload
// only carries the content hash it was built from.
$payload = [
'metadata' => $this->fileMetadata($file, $namespace),
'metadata' => $this->fileHashProvider->hash($file),
'nodes' => array_map($this->classNodeToArray(...), $classNodes),
];

Expand Down Expand Up @@ -1482,15 +1484,4 @@ private function analysisNodesKey(string $file, string $namespace): string
{
return 'analysis-nodes-' . hash('xxh128', $namespace . "\0" . $file);
}

/**
* @return array<string, mixed>
*/
private function fileMetadata(string $file, string $namespace): array
{
return [
'namespace' => $namespace,
'hash' => $this->fileHashProvider->hash($file),
];
}
}
10 changes: 2 additions & 8 deletions tests/Cache/AnalysisResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1369,10 +1369,7 @@ public function testClassNodesLoadOldCachePayloadWithoutInterfaceExtends(): void

try {
$this->writeCachePayload($cacheDirectory, [
'metadata' => [
'namespace' => 'config',
'hash' => hash('xxh128', (string) file_get_contents($sourceFile)),
],
'metadata' => hash('xxh128', (string) file_get_contents($sourceFile)),
'nodes' => [
[
'className' => Foo::class,
Expand Down Expand Up @@ -2672,10 +2669,7 @@ public function testClassNodesMissWhenPayloadIsMalformed(array $payloadOverride)
$cacheFile = $this->firstJsonFile($cacheDirectory);

$this->writeCachePayload($cacheDirectory, [
'metadata' => [
'namespace' => 'config',
'hash' => hash('xxh128', (string) file_get_contents($sourceFile)),
],
'metadata' => hash('xxh128', (string) file_get_contents($sourceFile)),
...$payloadOverride,
], $cacheFile);

Expand Down
Loading