Skip to content

Commit 3f0758a

Browse files
xepozzvjik
andauthored
Raise PHP version to ^8.0 + Add rector (#64)
Co-authored-by: Sergei Predvoditelev <[email protected]>
1 parent 36957da commit 3f0758a

20 files changed

+108
-131
lines changed

.github/workflows/bc.yml_

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
on:
2-
- pull_request
3-
- push
2+
- pull_request
3+
- push
44

55
name: backwards compatibility
6+
67
jobs:
7-
roave_bc_check:
8-
name: Roave BC Check
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@master
12-
- name: fetch tags
13-
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
14-
- name: Roave BC Check
15-
uses: docker://nyholm/roave-bc-check-ga
8+
roave_bc_check:
9+
uses: yiisoft/actions/.github/workflows/bc.yml@master
10+
with:
11+
os: >-
12+
['ubuntu-latest']
13+
php: >-
14+
['8.0']

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
os: >-
2929
['ubuntu-latest', 'windows-latest']
3030
php: >-
31-
['7.4', '8.0', '8.1']
31+
['8.0', '8.1', '8.2']

.github/workflows/rector.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
with:
18+
os: >-
19+
['ubuntu-latest']
20+
php: >-
21+
['8.0']

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
os: >-
2929
['ubuntu-latest']
3030
php: >-
31-
['7.4', '8.0', '8.1']
31+
['8.0', '8.1', '8.2']

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Yii Error Handler Change Log
22

3-
## 2.1.2 under development
3+
## 2.2.0 under development
44

5-
- no changes in this release.
5+
- Chg #64: Raise PHP version to `^8.0` (@vjik, @xepozz)
66

77
## 2.1.1 January 26, 2023
88

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ The package provides advanced error handling. The features are:
3030

3131
## Requirements
3232

33-
- PHP 7.4 or higher.
33+
- PHP 8.0 or higher.
34+
- `DOM` PHP extension.
35+
- `JSON` PHP extension.
3436

3537
## Installation
3638

3739
The package could be installed with composer:
3840

3941
```shell
40-
composer require yiisoft/error-handler --prefer-dist
42+
composer require yiisoft/error-handler
4143
```
4244

4345
## General usage

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"source": "https://github.com/yiisoft/error-handler"
2222
},
2323
"require": {
24-
"php": "^7.4|^8.0",
24+
"php": "^8.0",
2525
"ext-dom": "*",
2626
"ext-json": "*",
2727
"alexkart/curl-builder": "^1.0",
@@ -38,6 +38,7 @@
3838
"httpsoft/http-message": "^1.0.9",
3939
"phpunit/phpunit": "^9.5",
4040
"psr/http-server-handler": "^1.0",
41+
"rector/rector": "^0.15.10",
4142
"roave/infection-static-analysis-plugin": "^1.16",
4243
"spatie/phpunit-watcher": "^1.23",
4344
"vimeo/psalm": "^4.18",

rector.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Php70\Rector\FuncCall\NonVariableToVariableOnFunctionCallRector;
8+
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
9+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
10+
use Rector\Set\ValueObject\LevelSetList;
11+
12+
return static function (RectorConfig $rectorConfig): void {
13+
$rectorConfig->paths([
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
]);
17+
18+
// register a single rule
19+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
20+
21+
// define sets of rules
22+
$rectorConfig->sets([
23+
LevelSetList::UP_TO_PHP_80,
24+
]);
25+
26+
$rectorConfig->skip([
27+
ClosureToArrowFunctionRector::class,
28+
NonVariableToVariableOnFunctionCallRector::class,
29+
RemoveExtraParametersRector::class,
30+
]);
31+
};

src/ErrorData.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,21 @@
55
namespace Yiisoft\ErrorHandler;
66

77
use Psr\Http\Message\ResponseInterface;
8+
use Stringable;
89

910
/**
1011
* ErrorData stores content and headers that are suitable for adding to response.
1112
*/
12-
final class ErrorData
13+
final class ErrorData implements Stringable
1314
{
14-
/**
15-
* @var string The content to use as response body.
16-
*/
17-
private string $content;
18-
19-
/**
20-
* @var array<string, string|string[]> The headers to add to the response.
21-
*/
22-
private array $headers;
23-
2415
/**
2516
* @param string $content The content to use as response body.
2617
* @param array<string, string|string[]> $headers The headers to add to the response.
2718
*/
28-
public function __construct(string $content, array $headers = [])
29-
{
30-
$this->content = $content;
31-
$this->headers = $headers;
19+
public function __construct(
20+
private string $content,
21+
private array $headers = [],
22+
) {
3223
}
3324

3425
/**

src/ErrorHandler.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,18 @@ final class ErrorHandler
4141
private bool $enabled = false;
4242
private bool $initialized = false;
4343

44-
private LoggerInterface $logger;
45-
private ThrowableRendererInterface $defaultRenderer;
46-
private ?EventDispatcherInterface $eventDispatcher;
47-
4844
public function __construct(
49-
LoggerInterface $logger,
50-
ThrowableRendererInterface $defaultRenderer,
51-
EventDispatcherInterface $eventDispatcher = null
45+
private LoggerInterface $logger,
46+
private ThrowableRendererInterface $defaultRenderer,
47+
private ?EventDispatcherInterface $eventDispatcher = null,
5248
) {
53-
$this->logger = $logger;
54-
$this->defaultRenderer = $defaultRenderer;
55-
$this->eventDispatcher = $eventDispatcher;
5649
}
5750

5851
/**
5952
* Handles throwable and returns error data.
6053
*
61-
* @param Throwable $t
6254
* @param ThrowableRendererInterface|null $renderer
6355
* @param ServerRequestInterface|null $request
64-
*
65-
* @return ErrorData
6656
*/
6757
public function handle(
6858
Throwable $t,
@@ -195,8 +185,6 @@ private function initializeOnce(): void
195185

196186
/**
197187
* Renders the throwable and terminates the script.
198-
*
199-
* @param Throwable $t
200188
*/
201189
private function renderThrowableAndTerminate(Throwable $t): void
202190
{

0 commit comments

Comments
 (0)