Skip to content

Commit 10dc227

Browse files
authored
Merge pull request #5 from middlewares/php84-or-improvements
Add support for php8.4 and other improvements
2 parents 26259b1 + 7700bfa commit 10dc227

File tree

11 files changed

+112
-56
lines changed

11 files changed

+112
-56
lines changed

.gitattributes

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
* text=auto eol=lf
22

3-
/tests export-ignore
4-
.editorconfig export-ignore
5-
.gitattributes export-ignore
6-
.gitignore export-ignore
7-
.travis.yml export-ignore
8-
phpunit.xml export-ignore
9-
phpcs.xml export-ignore
3+
/tests export-ignore
4+
.editorconfig export-ignore
5+
.gitattributes export-ignore
6+
.gitignore export-ignore
7+
.php-cs-fixer.php export-ignore
8+
phpcs.xml.dist export-ignore
9+
phpunit.xml.dist export-ignore
10+
.phpstan.neon export-ignore

.github/workflows/main.yaml

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: "testing"
22

33
on:
4-
push:
5-
branches: [ master ]
6-
pull_request:
7-
branches: [ master ]
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
88

99
jobs:
1010
qa:
@@ -13,23 +13,23 @@ jobs:
1313

1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717

1818
- name: Validate composer.json and composer.lock
1919
run: composer validate
2020

2121
- name: Cache Composer packages
2222
id: composer-cache
23-
uses: actions/cache@v2
23+
uses: actions/cache@v4
2424
with:
25-
path: vendor
26-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
27-
restore-keys: |
28-
${{ runner.os }}-php-
25+
path: vendor
26+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-php-
2929
3030
- name: Install dependencies
3131
if: steps.composer-cache.outputs.cache-hit != 'true'
32-
run: composer install --prefer-dist --no-progress --no-suggest
32+
run: composer install --prefer-dist --no-progress
3333

3434
- name: Coding Standard
3535
run: composer run-script cs
@@ -40,37 +40,34 @@ jobs:
4040

4141
strategy:
4242
matrix:
43-
php:
44-
- 7.2
45-
- 7.3
46-
- 7.4
47-
composer-args: [ "" ]
48-
include:
49-
- php: 8.0
50-
composer-args: --ignore-platform-reqs
51-
fail-fast: false
43+
php:
44+
- 7.2
45+
- 7.3
46+
- 7.4
47+
- 8.0
48+
- 8.1
49+
- 8.2
50+
- 8.3
51+
- 8.4
5252

5353
steps:
5454
- name: Checkout
55-
uses: actions/checkout@v2
55+
uses: actions/checkout@v4
5656

5757
- name: Install PHP
5858
uses: shivammathur/setup-php@v2
5959
with:
6060
php-version: ${{ matrix.php }}
6161

6262
- name: Cache PHP dependencies
63-
uses: actions/cache@v2
63+
uses: actions/cache@v4
6464
with:
6565
path: vendor
6666
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
6767
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
6868

6969
- name: Install dependencies
70-
run: composer install --prefer-dist --no-progress --no-suggest ${{ matrix.composer-args }}
70+
run: composer install --prefer-dist --no-progress
7171

7272
- name: Tests
7373
run: composer test
74-
75-
- name: Tests coverage
76-
run: composer coverage

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ build
44
composer.lock
55
phpunit.xml
66
.php_cs.cache
7+
.idea
8+
kit
9+
*.cache

.php-cs-fixer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
return My\PhpCsFixerConfig::create()
4+
->setFinder(
5+
PhpCsFixer\Finder::create()
6+
->files()
7+
->name('*.php')
8+
->in(__DIR__.'/src')
9+
->in(__DIR__.'/tests')
10+
);

.phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
reportUnmatchedIgnoredErrors: false
3+
level: 8
4+
paths:
5+
- src
6+
- tests
7+
ignoreErrors:
8+
-
9+
identifier: 'isset.offset'
10+
reportUnmatched: false

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [1.1.0] - 2025-03-21
9+
### Added
10+
- Support for PHP 8.4
11+
812
## [1.0.0] - 2018-10-04
913

1014
- Initial Release
15+
16+
[1.1.0]: https://github.com/middlewares/image-manipulation/compare/v1.0.0...v1.1.0

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018
3+
Copyright (c) 2018-2025
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
},
2020
"require": {
2121
"php": "^7.2 || ^8.0",
22-
"middlewares/utils": "^2.1",
23-
"psr/http-server-middleware": "^1.0",
24-
"wyrihaximus/json-throwable": "^2.0",
25-
"thecodingmachine/safe": "^0.1.5"
22+
"middlewares/utils": "^2 || ^3 || ^4",
23+
"psr/http-server-middleware": "^1",
24+
"wyrihaximus/json-throwable": "^2 || ^3 || ^4",
25+
"thecodingmachine/safe": "^1 || ^2 || ^3"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^8|^9",
29-
"zendframework/zend-diactoros": "^1.3",
30-
"friendsofphp/php-cs-fixer": "^2.0",
31-
"squizlabs/php_codesniffer": "^3.0",
32-
"phpstan/phpstan": "^0.12"
28+
"phpunit/phpunit": "^8 || ^9",
29+
"laminas/laminas-diactoros": "^2 || ^3",
30+
"friendsofphp/php-cs-fixer": "^3",
31+
"squizlabs/php_codesniffer": "^3",
32+
"phpstan/phpstan": "^1 || ^2",
33+
"oscarotero/php-cs-fixer-config": "^2",
34+
"ext-json": "*"
3335
},
3436
"autoload": {
3537
"psr-4": {
@@ -49,4 +51,4 @@
4951
"coverage": "phpunit --coverage-text",
5052
"coverage-html": "phpunit --coverage-html=coverage"
5153
}
52-
}
54+
}

phpcs.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Middlewares coding standard">
3+
<description>Middlewares coding standard</description>
4+
5+
<!-- display progress -->
6+
<arg value="p"/>
7+
<arg name="report" value="full"/>
8+
<arg name="colors"/>
9+
10+
<!-- coding standard -->
11+
<rule ref="PSR2"/>
12+
13+
<!-- Paths to check -->
14+
<file>src</file>
15+
<file>tests</file>
16+
</ruleset>

src/JsonExceptionHandler.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Middlewares;
55

@@ -10,9 +10,8 @@
1010
use Psr\Http\Message\StreamFactoryInterface;
1111
use Psr\Http\Server\MiddlewareInterface;
1212
use Psr\Http\Server\RequestHandlerInterface;
13-
use Throwable;
14-
1513
use function Safe\json_encode;
14+
use Throwable;
1615
use function WyriHaximus\throwable_encode;
1716

1817
class JsonExceptionHandler implements MiddlewareInterface
@@ -33,8 +32,8 @@ class JsonExceptionHandler implements MiddlewareInterface
3332
private $jsonOptions = 0;
3433

3534
public function __construct(
36-
ResponseFactoryInterface $responseFactory = null,
37-
StreamFactoryInterface $streamFactory = null
35+
?ResponseFactoryInterface $responseFactory = null,
36+
?StreamFactoryInterface $streamFactory = null
3837
) {
3938
$this->responseFactory = $responseFactory ?? Factory::getResponseFactory();
4039
$this->streamFactory = $streamFactory ?? Factory::getStreamFactory();
@@ -87,7 +86,20 @@ protected function exceptionResponse(Throwable $e): ResponseInterface
8786
$exceptionJson = throwable_encode($e);
8887

8988
if ($this->includeTrace === false) {
90-
$exceptionJson['trace'] = [];
89+
// version 2 (php 7.2 and 7.3)
90+
/* @phpstan-ignore isset.offset */
91+
if (isset($exceptionJson['trace'])) {
92+
$exceptionJson['trace'] = [];
93+
}
94+
95+
// version 3 and 4 (7.4, >= 8.0)
96+
/* @phpstan-ignore isset.offset */
97+
if (isset($exceptionJson['originalTrace'])) {
98+
$exceptionJson['originalTrace'] = [];
99+
$exceptionJson['additionalProperties'] = [
100+
'trace' => serialize([]),
101+
];
102+
}
91103
}
92104

93105
$exceptionJson = json_encode($exceptionJson, $this->jsonOptions);

tests/JsonExceptionHandlerTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
declare(strict_types=1);
2+
declare(strict_types = 1);
33

44
namespace Middlewares\Tests;
55

@@ -8,12 +8,11 @@
88
use Middlewares\Utils\Dispatcher;
99
use Middlewares\Utils\Factory;
1010
use PHPUnit\Framework\TestCase;
11-
1211
use function WyriHaximus\throwable_json_decode;
1312

1413
class JsonExceptionHandlerTest extends TestCase
1514
{
16-
public function testMiddleware()
15+
public function testMiddleware(): void
1716
{
1817
$middleware = new JsonExceptionHandler();
1918

@@ -35,7 +34,7 @@ public function testMiddleware()
3534
$this->assertSame('Something went wrong', $e->getMessage());
3635
}
3736

38-
public function testContentType()
37+
public function testContentType(): void
3938
{
4039
$middleware = new JsonExceptionHandler();
4140
$middleware->contentType($type = 'application/json;charset=utf-8');
@@ -54,7 +53,7 @@ public function testContentType()
5453
$this->assertSame($type, $response->getHeaderLine('Content-Type'));
5554
}
5655

57-
public function testDisableTrace()
56+
public function testDisableTrace(): void
5857
{
5958
$middleware = new JsonExceptionHandler();
6059
$middleware->includeTrace(false);
@@ -77,7 +76,7 @@ public function testDisableTrace()
7776
$this->assertEmpty($e->getTrace());
7877
}
7978

80-
public function testJsonOptions()
79+
public function testJsonOptions(): void
8180
{
8281
$middleware = new JsonExceptionHandler();
8382
$middleware->jsonOptions(JSON_PRETTY_PRINT);

0 commit comments

Comments
 (0)