Skip to content

Commit ade0cbb

Browse files
authored
Raise minimum PHP version to 8.1 and refactor code (#85)
1 parent 749cefa commit ade0cbb

25 files changed

+193
-115
lines changed

.github/workflows/bc.yml

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
on:
2-
- pull_request
3-
- push
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'phpunit.xml.dist'
11+
- 'psalm.xml'
12+
push:
13+
branches: ['master']
14+
paths-ignore:
15+
- 'docs/**'
16+
- 'README.md'
17+
- 'CHANGELOG.md'
18+
- '.gitignore'
19+
- '.gitattributes'
20+
- 'infection.json.dist'
21+
- 'phpunit.xml.dist'
22+
- 'psalm.xml'
423

524
name: backwards compatibility
625

@@ -11,4 +30,4 @@ jobs:
1130
os: >-
1231
['ubuntu-latest']
1332
php: >-
14-
['8.0']
33+
['8.1']

.github/workflows/build.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
- 'psalm.xml'
1111

1212
push:
13+
branches:
14+
- master
1315
paths-ignore:
1416
- 'docs/**'
1517
- 'README.md'
@@ -28,4 +30,4 @@ jobs:
2830
os: >-
2931
['ubuntu-latest', 'windows-latest']
3032
php: >-
31-
['7.4', '8.0', '8.1']
33+
['8.1', '8.2', '8.3']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'phpunit.xml.dist'
11+
- 'psalm.xml'
12+
13+
push:
14+
branches: ['master']
15+
paths-ignore:
16+
- 'docs/**'
17+
- 'README.md'
18+
- 'CHANGELOG.md'
19+
- '.gitignore'
20+
- '.gitattributes'
21+
- 'infection.json.dist'
22+
- 'phpunit.xml.dist'
23+
- 'psalm.xml'
24+
25+
name: Composer require checker
26+
27+
jobs:
28+
composer-require-checker:
29+
uses: yiisoft/actions/.github/workflows/composer-require-checker.yml@master
30+
with:
31+
os: >-
32+
['ubuntu-latest']
33+
php: >-
34+
['8.1', '8.2', '8.3']

.github/workflows/mutation.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- 'psalm.xml'
1010

1111
push:
12+
branches: ['master']
1213
paths-ignore:
1314
- 'docs/**'
1415
- 'README.md'
@@ -26,6 +27,6 @@ jobs:
2627
os: >-
2728
['ubuntu-latest']
2829
php: >-
29-
['8.1']
30+
['8.3']
3031
secrets:
3132
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

.github/workflows/rector.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
on:
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'psalm.xml'
11+
12+
name: rector
13+
14+
jobs:
15+
rector:
16+
uses: yiisoft/actions/.github/workflows/rector.yml@master
17+
secrets:
18+
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
19+
with:
20+
os: >-
21+
['ubuntu-latest']
22+
php: >-
23+
['8.3']

.github/workflows/static.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
- 'phpunit.xml.dist'
1111

1212
push:
13+
branches:
14+
- master
1315
paths-ignore:
1416
- 'docs/**'
1517
- 'README.md'
@@ -28,4 +30,4 @@ jobs:
2830
os: >-
2931
['ubuntu-latest']
3032
php: >-
31-
['7.4', '8.0', '8.1']
33+
['8.1', '8.2', '8.3']

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ phpunit.phar
2828
# local phpunit config
2929
/phpunit.xml
3030
# phpunit cache
31-
.phpunit.result.cache
31+
/.phpunit.cache

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Yii Data Response Change Log
22

3-
## 2.0.1 under development
3+
## 2.1.0 under development
44

5+
- Enh #85: Raise minimum PHP version to 8.1 and refactor code (@vjik)
56
- Enh #80: Add support for `psr/http-message` version `^2.0` (@vjik)
7+
- Bug #85: Explicitly add transitive dependencies `psr/http-factory` and `psr/http-server-handler` (@vjik)
68

79
## 2.0.0 February 15, 2023
810

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ response.
2020

2121
## Requirements
2222

23-
- PHP 7.4 or higher.
24-
- `JSON` PHP extension.
23+
- PHP 8.1 or higher.
2524
- `DOM` PHP extension.
2625

2726
## Installation

composer.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@
1818
"source": "https://github.com/yiisoft/data-response"
1919
},
2020
"require": {
21-
"php": "^7.4|^8.0",
21+
"php": "^8.1",
2222
"ext-dom": "*",
23-
"ext-json": "*",
23+
"psr/http-factory": "^1.0",
2424
"psr/http-message": "^1.0|^2.0",
25+
"psr/http-server-handler": "^1.0",
2526
"psr/http-server-middleware": "^1.0",
2627
"yiisoft/http": "^1.2",
2728
"yiisoft/json": "^1.0",
2829
"yiisoft/strings": "^2.0"
2930
},
3031
"require-dev": {
3132
"httpsoft/http-message": "^1.0",
32-
"phpunit/phpunit": "^9.5",
33+
"maglnet/composer-require-checker": "^4.7",
34+
"phpunit/phpunit": "^10.5",
35+
"rector/rector": "^1.0",
3336
"roave/infection-static-analysis-plugin": "^1.16",
3437
"spatie/phpunit-watcher": "^1.23",
35-
"vimeo/psalm": "^4.30|^5.3",
38+
"vimeo/psalm": "^5.22",
3639
"yiisoft/di": "^1.1"
3740
},
3841
"autoload": {

phpunit.xml.dist

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
bootstrap="vendor/autoload.php"
4-
colors="true"
5-
verbose="true"
6-
failOnRisky="true"
7-
failOnWarning="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
stopOnFailure="false"
12-
executionOrder="random"
13-
resolveDependencies="true"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
requireCoverageMetadata="false"
7+
beStrictAboutCoverageMetadata="true"
8+
beStrictAboutOutputDuringTests="true"
9+
executionOrder="random"
10+
failOnRisky="true"
11+
failOnWarning="true"
12+
stopOnFailure="false"
13+
colors="true"
1414
>
1515
<php>
16-
<ini name="error_reporting" value="-1"/>
16+
<ini name="error_reporting" value="-1" />
1717
</php>
18+
1819
<testsuites>
1920
<testsuite name="Yii Data Response tests">
2021
<directory>./tests</directory>
2122
</testsuite>
2223
</testsuites>
23-
<coverage>
24+
25+
<source>
2426
<include>
25-
<directory>./src</directory>
27+
<directory suffix=".php">./src</directory>
2628
</include>
27-
</coverage>
29+
</source>
2830
</phpunit>

psalm.xml

+7
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@
99
>
1010
<projectFiles>
1111
<directory name="src" />
12+
<ignoreFiles>
13+
<directory name="vendor" />
14+
</ignoreFiles>
1215
</projectFiles>
16+
<issueHandlers>
17+
<MixedAssignment errorLevel="suppress" />
18+
<RiskyTruthyFalsyComparison errorLevel="suppress" />
19+
</issueHandlers>
1320
</psalm>

rector.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
8+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
9+
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
10+
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
11+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
12+
use Rector\Set\ValueObject\LevelSetList;
13+
14+
return static function (RectorConfig $rectorConfig): void {
15+
$rectorConfig->paths([
16+
__DIR__ . '/src',
17+
__DIR__ . '/tests',
18+
]);
19+
20+
// register a single rule
21+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
22+
23+
// define sets of rules
24+
$rectorConfig->sets([
25+
LevelSetList::UP_TO_PHP_81,
26+
]);
27+
28+
$rectorConfig->skip([
29+
ClosureToArrowFunctionRector::class,
30+
JsonThrowOnErrorRector::class,
31+
ReadOnlyPropertyRector::class,
32+
NullToStrictStringFuncCallArgRector::class,
33+
MixedTypeRector::class,
34+
]);
35+
};

src/DataResponse.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use RuntimeException;
1212

1313
use function ftruncate;
14-
use function get_class;
15-
use function gettype;
1614
use function is_callable;
1715
use function is_object;
1816
use function is_resource;
@@ -28,11 +26,6 @@
2826
*/
2927
final class DataResponse implements ResponseInterface
3028
{
31-
/**
32-
* @var mixed
33-
*/
34-
private $data;
35-
3629
/**
3730
* @var resource
3831
*/
@@ -52,13 +45,12 @@ final class DataResponse implements ResponseInterface
5245
* @param StreamFactoryInterface $streamFactory The stream factory instance.
5346
*/
5447
public function __construct(
55-
$data,
48+
private mixed $data,
5649
int $code,
5750
string $reasonPhrase,
5851
ResponseFactoryInterface $responseFactory,
5952
StreamFactoryInterface $streamFactory
6053
) {
61-
$this->data = $data;
6254
$this->createResponse($code, $reasonPhrase, $responseFactory, $streamFactory);
6355
}
6456

@@ -78,7 +70,6 @@ public function getBody(): StreamInterface
7870
return $this->dataStream = $this->response->getBody();
7971
}
8072

81-
/** @var mixed */
8273
$data = $this->getData();
8374

8475
if (is_string($data)) {
@@ -91,7 +82,7 @@ public function getBody(): StreamInterface
9182

9283
throw new RuntimeException(sprintf(
9384
'The data is "%s" not a string. To get non-string data, use the "%s::getData()" method.',
94-
is_object($data) ? get_class($data) : gettype($data),
85+
get_debug_type($data),
9586
self::class,
9687
));
9788
}
@@ -294,7 +285,7 @@ public function hasResponseFormatter(): bool
294285
*
295286
* @return self
296287
*/
297-
public function withData($data): self
288+
public function withData(mixed $data): self
298289
{
299290
if ($this->forcedBody) {
300291
throw new RuntimeException(sprintf(

src/DataResponseFactory.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
*/
1414
final class DataResponseFactory implements DataResponseFactoryInterface
1515
{
16-
private ResponseFactoryInterface $responseFactory;
17-
private StreamFactoryInterface $streamFactory;
18-
19-
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
20-
{
21-
$this->responseFactory = $responseFactory;
22-
$this->streamFactory = $streamFactory;
16+
public function __construct(
17+
private ResponseFactoryInterface $responseFactory,
18+
private StreamFactoryInterface $streamFactory,
19+
) {
2320
}
2421

2522
public function createResponse($data = null, int $code = Status::OK, string $reasonPhrase = ''): DataResponse

src/DataResponseFactoryInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Yiisoft\Http\Status;
88

99
/**
10-
* DataResponseFactoryInterface is the interface that should be implemented by data response factory classes.
10+
* `DataResponseFactoryInterface` is the interface that should be implemented by data response factory classes.
1111
*/
1212
interface DataResponseFactoryInterface
1313
{

0 commit comments

Comments
 (0)