diff --git a/.editorconfig b/.editorconfig index bab1050..4ac9793 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = true [*.yml] indent_style = space indent_size = 2 + +[*.neon] +indent_style = tab diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 266259a..c6d3a5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,8 @@ permissions: jobs: testsuite: uses: ADmad/.github/.github/workflows/testsuite-without-db.yml@master - secrets: inherit + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} cs-stan: uses: ADmad/.github/.github/workflows/cs-stan.yml@master diff --git a/composer.json b/composer.json index 949a38d..0095fb2 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,9 @@ "issues":"https://github.com/ADmad/cakephp-glide/issues" }, "require": { + "php": ">=8.1", "cakephp/cakephp": "^5.0", - "league/glide": "^2.3" + "league/glide": "^3.0" }, "require-dev": { "phpunit/phpunit": "^10.1" diff --git a/phpstan.neon b/phpstan.neon index b925c69..c58cb50 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,7 @@ parameters: - level: 8 - checkMissingIterableValueType: false - paths: - - src/ + level: 8 + paths: + - src/ + ignoreErrors: + - + identifier: missingType.iterableValue diff --git a/psalm.xml b/psalm.xml index e845ffc..d93e5f2 100644 --- a/psalm.xml +++ b/psalm.xml @@ -6,6 +6,7 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" findUnusedBaselineEntry="true" findUnusedCode="false" + ensureOverrideAttribute="false" > @@ -13,4 +14,8 @@ + + + + diff --git a/src/Middleware/GlideMiddleware.php b/src/Middleware/GlideMiddleware.php index 5bde8b3..1f57c34 100644 --- a/src/Middleware/GlideMiddleware.php +++ b/src/Middleware/GlideMiddleware.php @@ -124,7 +124,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface $response = $this->_withCacheHeaders( $response, $config['cacheTime'], - $modifiedTime + $modifiedTime, ); } @@ -165,7 +165,7 @@ protected function _checkSignature(ServerRequestInterface $request): void try { SignatureFactory::create($signKey)->validateRequest( $this->_path, - $request->getQueryParams() + $request->getQueryParams(), ); } catch (Exception $exception) { throw new SignatureException($exception->getMessage(), null, $exception); @@ -184,20 +184,13 @@ protected function _checkSignature(ServerRequestInterface $request): void */ protected function _checkModified(ServerRequestInterface $request, Server $server): ResponseInterface|int|null { - $modifiedTime = false; - try { - /** @var string|int|false $modifiedTime */ $modifiedTime = $server->getSource() ->lastModified($server->getSourcePath($this->_path)); } catch (Exception $exception) { return $this->_handleException($request, $exception); } - if ($modifiedTime === false) { - return null; - } - if ($this->_isNotModified($request, $modifiedTime)) { $response = new Response(['status' => 304]); $response = $this->_withCustomHeaders($response); @@ -205,7 +198,7 @@ protected function _checkModified(ServerRequestInterface $request, Server $serve return $response->withHeader('Last-Modified', (string)$modifiedTime); } - return (int)$modifiedTime; + return $modifiedTime; } /** @@ -306,7 +299,7 @@ protected function _isNotModified(ServerRequestInterface $request, string|int $m protected function _withCacheHeaders( ResponseInterface $response, string $cacheTime, - string|int $modifiedTime + string|int $modifiedTime, ): ResponseInterface { /** @var int $expire */ $expire = strtotime($cacheTime); @@ -346,7 +339,7 @@ protected function _handleException(ServerRequestInterface $request, Exception $ { $event = $this->dispatchEvent( static::RESPONSE_FAILURE_EVENT, - compact('request', 'exception') + compact('request', 'exception'), ); $result = $event->getResult(); diff --git a/src/View/Helper/GlideHelper.php b/src/View/Helper/GlideHelper.php index 369cc38..a61737d 100644 --- a/src/View/Helper/GlideHelper.php +++ b/src/View/Helper/GlideHelper.php @@ -59,7 +59,7 @@ public function image(string $path, array $params = [], array $options = []): st { return $this->Html->image( $this->url($path, $params + ['_base' => false]), - $options + $options, ); } @@ -104,7 +104,7 @@ public function urlBuilder(?UrlBuilder $urlBuilder = null): UrlBuilder $this->_urlBuilder = UrlBuilderFactory::create( $config['baseUrl'], - $config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null + $config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null, ); } diff --git a/tests/TestCase/Middleware/GlideMiddlewareTest.php b/tests/TestCase/Middleware/GlideMiddlewareTest.php index 38d5195..97b634b 100644 --- a/tests/TestCase/Middleware/GlideMiddlewareTest.php +++ b/tests/TestCase/Middleware/GlideMiddlewareTest.php @@ -37,7 +37,7 @@ public function setUp(): void $this->request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/images/cake-logo.png'], - ['w' => '100'] + ['w' => '100'], ); $this->handler = new TestRequestHandler(); @@ -63,7 +63,7 @@ public function testServerCallable() $config = $this->config; $config['server'] = function () { return ServerFactory::create( - $this->config['server'] + ['base_url' => '/images'] + $this->config['server'] + ['base_url' => '/images'], ); }; @@ -81,7 +81,7 @@ public function testAllowedParams() $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/images/cake-logo.png'], - ['w' => '100', 'foo' => 'bar'] + ['w' => '100', 'foo' => 'bar'], ); $middleware = new GlideMiddleware($this->config); @@ -108,7 +108,7 @@ public function testOriginalPassThrough() $this->assertNotSame( $fileSize, (int)$headers['Content-Length'][0], - 'Content length shouldnt be same as original filesize since glide always generates new file.' + 'Content length shouldnt be same as original filesize since glide always generates new file.', ); exec('rm -rf ' . TMP . 'cache/cake-logo.png'); @@ -143,7 +143,7 @@ public function testSecureUrl() $request = ServerRequestFactory::fromGlobals( ['REQUEST_URI' => '/images/cake%20logo.png'], - ['w' => 100, 's' => $sig] + ['w' => 100, 's' => $sig], ); $middleware = new GlideMiddleware($this->config); @@ -169,7 +169,7 @@ public function testCache() 'REQUEST_URI' => '/images/cake-logo.png', 'HTTP_IF_MODIFIED_SINCE' => $headers['Last-Modified'][0], ], - ['w' => '100'] + ['w' => '100'], ); $middleware = new GlideMiddleware($this->config); diff --git a/tests/TestCase/View/Helper/GlideHelperTest.php b/tests/TestCase/View/Helper/GlideHelperTest.php index 830c372..c438d08 100644 --- a/tests/TestCase/View/Helper/GlideHelperTest.php +++ b/tests/TestCase/View/Helper/GlideHelperTest.php @@ -32,7 +32,7 @@ public function testUrl() $this->assertEquals('/images/logo.png?w=100', $result); $this->helper->getView()->setRequest( - $this->helper->getView()->getRequest()->withAttribute('webroot', '/subfolder/') + $this->helper->getView()->getRequest()->withAttribute('webroot', '/subfolder/'), ); $result = $this->helper->url('logo.png', ['w' => 100]); $this->assertEquals('/subfolder/images/logo.png?w=100', $result); @@ -58,7 +58,7 @@ public function testImage() Router::setRequest( $this->helper->getView()->getRequest() - ->withAttribute('webroot', '/subfolder/') + ->withAttribute('webroot', '/subfolder/'), ); $result = $this->helper->image('logo.png', ['w' => 100], ['width' => 100]); $this->assertHtml([