Skip to content

Commit

Permalink
Soothe SA
Browse files Browse the repository at this point in the history
Added a property_exists function to the DonutCommandInterceptorTest class to ensure 'bindings' property exists before being accessed. In the ResourceStorage class, simplified the getVary method by directly using the 'X_VARY' server variable in the explode function instead of casting it to a string.
  • Loading branch information
koriym committed May 14, 2024
1 parent 095f391 commit b84f5a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ResourceStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function getUriKey(AbstractUri $uri, string $type): string
private function getVary(): string
{
$xvary = $_SERVER['X_VARY'];
$varys = explode(',', (string) $xvary);
$varys = explode(',', $xvary);
$varyString = '';
foreach ($varys as $vary) {
$phpVaryKey = sprintf('X_%s', strtoupper($vary));
Expand Down
2 changes: 2 additions & 0 deletions tests/DonutCommandInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use function array_map;
use function assert;
use function dirname;
use function property_exists;

class DonutCommandInterceptorTest extends TestCase
{
Expand Down Expand Up @@ -82,6 +83,7 @@ public function testCacheableResponse(): void
$ro = $this->resource->get('page://self/html/blog-posting-cache?id=0');
$interceptors = array_map(static fn (object $object): string => $object::class, $ro->bindings['onGet']); // @phpstan-ignore-line
$this->assertContains(DonutCacheInterceptor::class, $interceptors);
assert(property_exists($ro, 'bindings')); // @phpstan-ignore-line

Check failure on line 86 in tests/DonutCommandInterceptorTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

No error to ignore is reported on line 86.

Check failure on line 86 in tests/DonutCommandInterceptorTest.php

View workflow job for this annotation

GitHub Actions / sa / PHPStan

No error to ignore is reported on line 86.
assert(isset($ro->bindings['onGet'][0]));
assert(isset($ro->bindings['onDelete'][0]));
$this->assertInstanceOf(DonutCacheInterceptor::class, $ro->bindings['onDelete'][0]);
Expand Down

0 comments on commit b84f5a8

Please sign in to comment.