Skip to content

Commit 0ae85da

Browse files
authored
Merge pull request #39 from ADmad/cake-5
Cake 5
2 parents cffd2da + d6ecf3f commit 0ae85da

File tree

13 files changed

+107
-108
lines changed

13 files changed

+107
-108
lines changed

.gitattributes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.gitattributes export-ignore
44
.gitignore export-ignore
55
phpunit.xml.dist export-ignore
6-
.travis.yml export-ignore
76
tests export-ignore
8-
psalm.xml
7+
psalm.xml export-ignore
8+
phpstan.neon export-ignore
9+
.github export-ignore

.github/workflows/ci.yml

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,21 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
permissions:
12+
contents: read
413

514
jobs:
615
testsuite:
7-
runs-on: ubuntu-18.04
8-
strategy:
9-
fail-fast: false
10-
matrix:
11-
php-version: ['7.4', '8.0', '8.1']
12-
composer-opts: ['']
13-
include:
14-
- php-version: '7.2'
15-
composer-opts: '--prefer-lowest'
16-
17-
steps:
18-
- uses: actions/checkout@v2
19-
20-
- name: Setup PHP
21-
uses: shivammathur/setup-php@v2
22-
with:
23-
php-version: ${{ matrix.php-version }}
24-
extensions: mbstring, intl
25-
coverage: pcov
26-
27-
- name: Composer install
28-
run: |
29-
composer update ${{ matrix.composer-opts }}
30-
31-
- name: Run PHPUnit
32-
run: |
33-
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
34-
vendor/bin/phpunit --coverage-clover=coverage.xml
35-
else
36-
vendor/bin/phpunit
37-
fi
38-
39-
- name: Code Coverage Report
40-
if: matrix.php-version == '7.4'
41-
uses: codecov/codecov-action@v2
16+
uses: ADmad/.github/.github/workflows/testsuite-without-db.yml@master
17+
secrets: inherit
4218

4319
cs-stan:
44-
name: Coding Standard & Static Analysis
45-
runs-on: ubuntu-18.04
46-
47-
steps:
48-
- uses: actions/checkout@v2
49-
50-
- name: Setup PHP
51-
uses: shivammathur/setup-php@v2
52-
with:
53-
php-version: '7.4'
54-
extensions: mbstring, intl
55-
coverage: none
56-
tools: cs2pr, vimeo/psalm:^4
57-
58-
- name: Composer Install
59-
run: composer require cakephp/cakephp-codesniffer:^4.5
60-
61-
- name: Run phpcs
62-
run: vendor/bin/phpcs --report=checkstyle -q --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/ | cs2pr
63-
64-
- name: Run psalm
65-
if: success() || failure()
66-
run: psalm --output-format=github
20+
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
21+
secrets: inherit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/composer.lock
22
/vendor
3+
.phpunit.cache
34
.phpunit.result.cache

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CakePHP Glide
22

3-
[![Build Status](https://img.shields.io/github/workflow/status/ADmad/cakephp-glide/CI/master?style=flat-square)](https://github.com/ADmad/cakephp-glide/actions?query=workflow%3ACI+branch%3Amaster)
3+
[![Build Status](https://img.shields.io/github/actions/workflow/status/ADmad/cakephp-glide/ci.yml?style=flat-square&branch=master)](https://github.com/ADmad/cakephp-glide/actions?query=workflow%3ACI+branch%3Amaster)
44
[![Coverage Status](https://img.shields.io/codecov/c/github/ADmad/cakephp-glide.svg?style=flat-square)](https://codecov.io/github/ADmad/cakephp-glide)
55
[![Total Downloads](https://img.shields.io/packagist/dt/ADmad/cakephp-glide.svg?style=flat-square)](https://packagist.org/packages/ADmad/cakephp-glide)
66
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt)

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"issues":"https://github.com/ADmad/cakephp-glide/issues"
2929
},
3030
"require": {
31-
"cakephp/cakephp": "^4.0.2",
32-
"league/glide": "^2.0"
31+
"cakephp/cakephp": "^5.0",
32+
"league/glide": "^2.3"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^8.5 || ^9.3"
35+
"phpunit/phpunit": "^10.1"
3636
},
3737
"autoload": {
3838
"psr-4": {
@@ -44,5 +44,11 @@
4444
"ADmad\\Glide\\Test\\": "tests",
4545
"TestApp\\": "tests/test_app/src"
4646
}
47+
},
48+
"config": {
49+
"sort-packages": true,
50+
"allow-plugins": {
51+
"dealerdirect/phpcodesniffer-composer-installer": true
52+
}
4753
}
4854
}

phpstan.neon

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
parameters:
2-
level: 6
3-
ignoreErrors:
4-
- '#Access to an undefined property ADmad\\Glide\\View\\Helper\\GlideHelper::\$request#'
2+
level: 8
3+
checkMissingIterableValueType: false
4+
paths:
5+
- src/

phpunit.xml.dist

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
colors="true"
4-
processIsolation="false"
5-
stopOnFailure="false"
6-
bootstrap="./tests/bootstrap.php"
7-
>
8-
<php>
9-
<ini name="memory_limit" value="-1"/>
10-
</php>
11-
12-
<!-- Add any additional test suites you want to run here -->
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="./tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
133
<testsuites>
144
<testsuite name="ADmad/Glide TestSuite">
155
<directory>./tests/TestCase</directory>
166
</testsuite>
17-
<!-- Add plugin test suites here. -->
187
</testsuites>
19-
20-
<filter>
21-
<whitelist>
22-
<directory suffix=".php">./src/</directory>
23-
<directory suffix=".ctp">./src/</directory>
24-
</whitelist>
25-
</filter>
8+
<extensions>
9+
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
10+
</extensions>
11+
<coverage/>
12+
<source>
13+
<include>
14+
<directory suffix=".php">src/</directory>
15+
</include>
16+
</source>
2617
</phpunit>

psalm.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="2"
43
resolveFromConfigFile="true"
54
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
65
xmlns="https://getpsalm.org/schema/config"
76
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
findUnusedBaselineEntry="true"
8+
findUnusedCode="false"
89
>
910
<projectFiles>
1011
<directory name="src" />

src/GlidePlugin.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace ADmad\Glide;
5+
6+
use Cake\Core\BasePlugin;
7+
8+
class GlidePlugin extends BasePlugin
9+
{
10+
/**
11+
* Do bootstrapping or not
12+
*
13+
* @var bool
14+
*/
15+
protected bool $bootstrapEnabled = false;
16+
17+
/**
18+
* Console middleware
19+
*
20+
* @var bool
21+
*/
22+
protected bool $consoleEnabled = false;
23+
24+
/**
25+
* Load routes or not
26+
*
27+
* @var bool
28+
*/
29+
protected bool $routesEnabled = false;
30+
}

src/Middleware/GlideMiddleware.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@
2323
use Psr\Http\Server\MiddlewareInterface;
2424
use Psr\Http\Server\RequestHandlerInterface;
2525

26+
/**
27+
* @implements \Cake\Event\EventDispatcherInterface<\ADmad\Glide\Middleware\GlideMiddleware>
28+
*/
2629
class GlideMiddleware implements MiddlewareInterface, EventDispatcherInterface
2730
{
31+
/**
32+
* @use \Cake\Event\EventDispatcherTrait<\ADmad\Glide\Middleware\GlideMiddleware>
33+
*/
2834
use EventDispatcherTrait;
35+
2936
use InstanceConfigTrait;
3037

3138
public const RESPONSE_FAILURE_EVENT = 'Glide.response_failure';
@@ -35,7 +42,7 @@ class GlideMiddleware implements MiddlewareInterface, EventDispatcherInterface
3542
*
3643
* @var array
3744
*/
38-
protected $_defaultConfig = [
45+
protected array $_defaultConfig = [
3946
'path' => null,
4047
'cacheTime' => '+1 days',
4148
'server' => [
@@ -56,7 +63,7 @@ class GlideMiddleware implements MiddlewareInterface, EventDispatcherInterface
5663
*
5764
* @var string
5865
*/
59-
protected $_path = '';
66+
protected string $_path = '';
6067

6168
/**
6269
* Constructor.
@@ -129,10 +136,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
129136
/**
130137
* Get glide server instance.
131138
*
132-
* @param array|callable $config Config array or callable.
139+
* @param callable|array $config Config array or callable.
133140
* @return \League\Glide\Server
134141
*/
135-
protected function _getServer($config): Server
142+
protected function _getServer(callable|array $config): Server
136143
{
137144
if (is_array($config)) {
138145
return ServerFactory::create($config);
@@ -148,7 +155,7 @@ protected function _getServer($config): Server
148155
* @throws \ADmad\Glide\Exception\SignatureException
149156
* @return void
150157
*/
151-
protected function _checkSignature(ServerRequestInterface $request)
158+
protected function _checkSignature(ServerRequestInterface $request): void
152159
{
153160
if (!$this->getConfig('security.secureUrls')) {
154161
return;
@@ -175,12 +182,12 @@ protected function _checkSignature(ServerRequestInterface $request)
175182
* @param \League\Glide\Server $server Glide server.
176183
* @return \Psr\Http\Message\ResponseInterface|int|null
177184
*/
178-
protected function _checkModified(ServerRequestInterface $request, Server $server)
185+
protected function _checkModified(ServerRequestInterface $request, Server $server): ResponseInterface|int|null
179186
{
180187
$modifiedTime = false;
181188

182189
try {
183-
/** @var int|string|false $modifiedTime */
190+
/** @var string|int|false $modifiedTime */
184191
$modifiedTime = $server->getSource()
185192
->lastModified($server->getSourcePath($this->_path));
186193
} catch (Exception $exception) {
@@ -278,7 +285,7 @@ protected function _passThrough(ServerRequestInterface $request, Server $server)
278285
* @param string|int $modifiedTime Last modified time of file.
279286
* @return bool
280287
*/
281-
protected function _isNotModified(ServerRequestInterface $request, $modifiedTime)
288+
protected function _isNotModified(ServerRequestInterface $request, string|int $modifiedTime): bool
282289
{
283290
$modifiedSince = $request->getHeaderLine('If-Modified-Since');
284291
if (!$modifiedSince) {
@@ -293,11 +300,14 @@ protected function _isNotModified(ServerRequestInterface $request, $modifiedTime
293300
*
294301
* @param \Psr\Http\Message\ResponseInterface $response The response.
295302
* @param string $cacheTime Cache time.
296-
* @param int|string $modifiedTime Modified time.
303+
* @param string|int $modifiedTime Modified time.
297304
* @return \Psr\Http\Message\ResponseInterface
298305
*/
299-
protected function _withCacheHeaders(ResponseInterface $response, string $cacheTime, $modifiedTime)
300-
{
306+
protected function _withCacheHeaders(
307+
ResponseInterface $response,
308+
string $cacheTime,
309+
string|int $modifiedTime
310+
): ResponseInterface {
301311
/** @var int $expire */
302312
$expire = strtotime($cacheTime);
303313
$maxAge = $expire - time();
@@ -315,7 +325,7 @@ protected function _withCacheHeaders(ResponseInterface $response, string $cacheT
315325
* @param \Psr\Http\Message\ResponseInterface $response The response.
316326
* @return \Psr\Http\Message\ResponseInterface
317327
*/
318-
protected function _withCustomHeaders(ResponseInterface $response)
328+
protected function _withCustomHeaders(ResponseInterface $response): ResponseInterface
319329
{
320330
foreach ((array)$this->getConfig('headers') as $key => $value) {
321331
$response = $response->withHeader($key, $value);
@@ -332,7 +342,7 @@ protected function _withCustomHeaders(ResponseInterface $response)
332342
* @throws \ADmad\Glide\Exception\ResponseException
333343
* @return \Psr\Http\Message\ResponseInterface|null
334344
*/
335-
protected function _handleException(ServerRequestInterface $request, $exception): ?ResponseInterface
345+
protected function _handleException(ServerRequestInterface $request, Exception $exception): ?ResponseInterface
336346
{
337347
$event = $this->dispatchEvent(
338348
static::RESPONSE_FAILURE_EVENT,

0 commit comments

Comments
 (0)