Skip to content

Commit

Permalink
fix psalm error
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Demonchaux <demonchaux.stephane@gmail.com>
  • Loading branch information
fezfez committed Nov 3, 2023
1 parent d981071 commit c166836
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 87 deletions.
5 changes: 4 additions & 1 deletion .laminas-ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"extensions": [
"inotify",
"swoole"
]
],
"ignore_php_platform_requirements": {
"8.3": true
}
}
10 changes: 1 addition & 9 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.12.0@f90118cdeacd0088e7215e64c0c99ceca819e176">
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/AbstractStaticResourceHandlerFactory.php">
<MixedArrayOffset>
<code>$cacheControlDirectives[$regex]</code>
Expand All @@ -26,14 +26,6 @@
<code>InvalidConfigException</code>
</UnusedClass>
</file>
<file src="src/HotCodeReload/FileWatcher/InotifyFileWatcher.php">
<LessSpecificReturnStatement>
<code>$paths</code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[list<non-empty-string>]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/HttpServerFactory.php">
<InvalidConstantAssignmentValue>
<code>PROTOCOLS = [
Expand Down
3 changes: 2 additions & 1 deletion src/StaticResourceHandler/CacheControlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CacheControlMiddleware implements MiddlewareInterface
* Key is a regexp; if a static resource path matches the regexp, the array
* of values provided will be used as the Cache-Control header value.
*
* @psalm-var array<string, list<string>>
* @psalm-var array<non-empty-string, list<string>>
*/
private array $cacheControlDirectives;

Expand Down Expand Up @@ -99,6 +99,7 @@ private function validateCacheControlDirectives(array $cacheControlDirectives):
}

/**
* @param non-empty-string $regex
* @throws Exception\InvalidArgumentException If any regexp is invalid.
*/
private function validateCacheControlDirective(string $regex, string $directive): void
Expand Down
2 changes: 1 addition & 1 deletion src/StaticResourceHandler/ETagMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ETagMiddleware implements MiddlewareInterface
];

/**
* @var string[] Array of regexp; if a path matches a regexp, an ETag will
* @var non-empty-string[] Array of regexp; if a path matches a regexp, an ETag will
* be emitted for the static file resource.
*/
private array $etagDirectives = [];
Expand Down
4 changes: 2 additions & 2 deletions src/StaticResourceHandler/LastModifiedMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class LastModifiedMiddleware implements MiddlewareInterface
{
use ValidateRegexTrait;

/** @var string[] */
/** @var non-empty-string[] */
private array $lastModifiedDirectives = [];

/**
* @param string[] $lastModifiedDirectives Array of regexex indicating
* @param non-empty-string[] $lastModifiedDirectives Array of regexex indicating
* paths/file types that should emit a Last-Modified header.
*/
public function __construct(array $lastModifiedDirectives = [])
Expand Down
3 changes: 3 additions & 0 deletions src/StaticResourceHandler/ValidateRegexTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

trait ValidateRegexTrait
{
/**
* @param non-empty-string $regex
*/
private function isValidRegex(string $regex): bool
{
set_error_handler(static fn($errno) => $errno === E_WARNING);
Expand Down
16 changes: 8 additions & 8 deletions test/Command/StartCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ public function testExecuteRunsApplicationIfServerIsNotCurrentlyRunning(array $p

$this->input
->method('getOption')
->will($this->returnValueMap([
->willReturnMap([
['daemonize', true],
['num-workers', 6],
['num-task-workers', 4],
]));
]);

$this->pidManager->method('read')->willReturn($pids);

Expand All @@ -243,12 +243,12 @@ public function testExecuteRunsApplicationIfServerIsNotCurrentlyRunning(array $p

$this->container
->method('get')
->will($this->returnValueMap([
->willReturnMap([
[PidManager::class, $this->pidManager],
[SwooleHttpServer::class, $httpServer],
[MiddlewareFactory::class, $middlewareFactory],
[Application::class, $application],
]));
]);

$command = new StartCommand($this->container);

Expand All @@ -264,11 +264,11 @@ public function testExecuteRunsApplicationWithoutSettingOptionsIfNoneProvided(ar
{
$this->input
->method('getOption')
->will($this->returnValueMap([
->willReturnMap([
['daemonize', false],
['num-workers', null],
['num-task-workers', null],
]));
]);

[$command, $httpServer, $application] = $this->prepareSuccessfulStartCommand($pids);

Expand Down Expand Up @@ -303,12 +303,12 @@ private function prepareSuccessfulStartCommand(array $pids): array
$this->pidManager->method('read')->willReturn($pids);
$this->container
->method('get')
->will($this->returnValueMap([
->willReturnMap([
[PidManager::class, $this->pidManager],
[SwooleHttpServer::class, $httpServer],
[MiddlewareFactory::class, $middlewareFactory],
[Application::class, $application],
]));
]);

$command = new StartCommand($this->container);

Expand Down
8 changes: 4 additions & 4 deletions test/Event/HotCodeReloaderWorkerStartListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function testProducesHotCodeReloaderListenerWithDefaultConfiguration(): v
$container
->expects($this->exactly(2))
->method('get')
->will($this->returnValueMap([
->willReturnMap([
[FileWatcherInterface::class, $fileWatcher],
[AccessLogInterface::class, $logger],
]));
]);

$factory = new HotCodeReloaderWorkerStartListenerFactory();
$this->assertIsObject($factory($container));
Expand Down Expand Up @@ -64,11 +64,11 @@ public function testProducesHotCodeReloaderListenerUsingIntervalFromConfiguratio
$container
->expects($this->exactly(3))
->method('get')
->will($this->returnValueMap([
->willReturnMap([
[FileWatcherInterface::class, $fileWatcher],
[AccessLogInterface::class, $logger],
['config', $config],
]));
]);

$fileWatcher
->expects($this->exactly(2))
Expand Down
2 changes: 1 addition & 1 deletion test/Log/LoggerFactoryHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function mockContainer(array $methodMap): ContainerInterface
$valueMap[] = [$service, $value];
}

$container->method($method)->will($this->returnValueMap($valueMap));
$container->method($method)->willReturnMap($valueMap);
}

return $container;
Expand Down
4 changes: 2 additions & 2 deletions test/StaticMappedResourceHandlerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ public function testFactoryConfiguresHandlerBasedOnConfiguration(): void

$this->container
->method('get')
->will($this->returnValueMap([
->willReturnMap([
['config', $config],
[FileLocationRepositoryInterface::class, $this->fileLocRepo],
]));
]);

$factory = new StaticMappedResourceHandlerFactory();

Expand Down
48 changes: 24 additions & 24 deletions test/StaticResourceHandler/IntegrationMappedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public function testSendStaticResourceReturns405ResponseForUnsupportedMethodMatc
$response
->expects($this->exactly(2))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'image/png', true],
['Allow', 'GET, HEAD, OPTIONS', true],
]));
]);
$response->expects($this->once())->method('status')->with(405);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile');
Expand Down Expand Up @@ -115,10 +115,10 @@ public function testSendStaticResourceEmitsAllowHeaderWith200ResponseForOptionsR
$response
->expects($this->exactly(2))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'image/png', true],
['Allow', 'GET, HEAD, OPTIONS', true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile');
Expand Down Expand Up @@ -157,13 +157,13 @@ public function testSendStaticResourceEmitsContentAndHeadersMatchingDirectivesFo
$response
->expects($this->exactly(5))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Content-Length', $this->anything(), true],
['Cache-Control', 'public, no-transform', true],
['Last-Modified', $lastModifiedFormatted, true],
['ETag', $etag, true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->never())->method('end');
$response->expects($this->once())->method('sendfile')->with($file);
Expand Down Expand Up @@ -209,12 +209,12 @@ public function testSendStaticResourceEmitsHeadersOnlyWhenMatchingDirectivesForH
$response
->expects($this->exactly(4))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Cache-Control', 'public, no-transform', true],
['Last-Modified', $lastModifiedFormatted, true],
['ETag', $etag, true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile')->with($file);
Expand Down Expand Up @@ -263,13 +263,13 @@ public function testSendStaticResourceEmitsAllowHeaderWithHeadersAndNoBodyWhenMa
$response
->expects($this->exactly(5))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Allow', 'GET, HEAD, OPTIONS', true],
['Cache-Control', 'public, no-transform', true],
['Last-Modified', $lastModifiedFormatted, true],
['ETag', $etag, true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile')->with($file);
Expand Down Expand Up @@ -321,11 +321,11 @@ public function testSendStaticResourceViaGetSkipsClientSideCacheMatchingIfNoETag
$response
->expects($this->exactly(3))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Content-Length', $this->anything(), true],
['Cache-Control', 'public, no-transform', true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->never())->method('end');
$response->expects($this->once())->method('sendfile')->with($file);
Expand Down Expand Up @@ -374,10 +374,10 @@ public function testSendStaticResourceViaHeadSkipsClientSideCacheMatchingIfNoETa
$response
->expects($this->exactly(2))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Cache-Control', 'public, no-transform', true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile')->with($file);
Expand Down Expand Up @@ -424,10 +424,10 @@ public function testSendStaticResourceViaGetHitsClientSideCacheMatchingIfETagMat
$response
->expects($this->exactly(2))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['ETag', $etag, true],
]));
]);
$response->expects($this->once())->method('status')->with(304);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile')->with($file);
Expand Down Expand Up @@ -475,10 +475,10 @@ public function testSendStaticResourceViaGetHitsClientSideCacheMatchingIfETagMat
$response
->expects($this->exactly(2))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['ETag', $etag, true],
]));
]);
$response->expects($this->once())->method('status')->with(304);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile')->with($file);
Expand Down Expand Up @@ -523,11 +523,11 @@ public function testSendStaticResourceCanGenerateStrongETagValue(): void
$response
->expects($this->exactly(3))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Content-Length', $this->anything(), true],
['ETag', $etag, true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->never())->method('end');
$response->expects($this->once())->method('sendfile')->with($file);
Expand Down Expand Up @@ -575,10 +575,10 @@ public function testSendStaticResourceViaGetHitsClientSideCacheMatchingIfLastMod
$response
->expects($this->exactly(2))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'image/png', true],
['Last-Modified', $lastModifiedFormatted, true],
]));
]);
$response->expects($this->once())->method('status')->with(304);
$response->expects($this->once())->method('end');
$response->expects($this->never())->method('sendfile')->with($file);
Expand Down Expand Up @@ -625,11 +625,11 @@ public function testGetDoesNotHitClientSideCacheMatchingIfLastModifiedDoesNotMat
$response
->expects($this->exactly(3))
->method('header')
->will($this->returnValueMap([
->willReturnMap([
['Content-Type', 'text/plain', true],
['Content-Length', $this->anything(), true],
['Last-Modified', $lastModifiedFormatted, true],
]));
]);
$response->expects($this->once())->method('status')->with(200);
$response->expects($this->never())->method('end');
$response->expects($this->once())->method('sendfile')->with($file);
Expand Down
Loading

0 comments on commit c166836

Please sign in to comment.