Skip to content

Commit 0712a1d

Browse files
authored
Merge pull request #51 from Howriq/issue-#50
Issue #50: Replace Psalm with PHPStan
2 parents a362bbb + ddc78e5 commit 0712a1d

File tree

11 files changed

+88
-42
lines changed

11 files changed

+88
-42
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
- push
3+
4+
name: Run PHPStan checks
5+
6+
jobs:
7+
mutation:
8+
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.2"
19+
- "8.3"
20+
- "8.4"
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Install PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: "${{ matrix.php }}"
30+
coverage: pcov
31+
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
32+
tools: composer:v2, cs2pr
33+
34+
- name: Determine composer cache directory
35+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
36+
37+
- name: Cache dependencies installed with composer
38+
uses: actions/cache@v4
39+
with:
40+
path: ${{ env.COMPOSER_CACHE_DIR }}
41+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
42+
restore-keys: |
43+
php${{ matrix.php }}-composer-
44+
45+
- name: Install dependencies with composer
46+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
47+
48+
- name: Run static analysis with PHPStan
49+
run: vendor/bin/phpstan analyse

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/
99
## Badges
1010

1111
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-errorhandler)
12-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.2.0)
12+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.3.0)
1313

1414
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/issues)
1515
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/network)
1616
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/stargazers)
1717
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/blob/4.1/LICENSE)
1818

1919
[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml/badge.svg?branch=4.1)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml)
20-
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
20+
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.1/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
21+
[![PHPStan](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml/badge.svg?branch=4.1)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml)
2122

2223
## Adding the error handler
2324

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"require-dev": {
3535
"laminas/laminas-coding-standard": "^3.0.1",
3636
"mikey179/vfsstream": "^1.6.12",
37-
"phpunit/phpunit": "^10.5.45",
38-
"vimeo/psalm": "6.6.2"
37+
"phpstan/phpstan": "^2.1",
38+
"phpstan/phpstan-phpunit": "^2.0",
39+
"phpunit/phpunit": "^10.5.45"
3940
},
4041
"autoload": {
4142
"psr-4": {
@@ -57,6 +58,6 @@
5758
"cs-check": "phpcs",
5859
"cs-fix": "phpcbf",
5960
"test": "phpunit --colors=always",
60-
"static-analysis": "psalm --shepherd --stats"
61+
"static-analysis": "phpstan analyse --memory-limit 1G"
6162
}
6263
}

docs/book/v4/overview.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# Overview
22

3-
dot-errorhandler is Dotkernel's PSR-15 compliant error handler.
3+
`dot-errorhandler` is Dotkernel's logging error handler, providing two options:
4+
5+
- `Dot\ErrorHandler\ErrorHandler`, same as the Zend Expressive error handling class with the only difference being the removal of the `final` statement for making extension possible
6+
- `Dot\ErrorHandler\LogErrorHandler` adds logging support to the default `ErrorHandler` class
47

58
## Badges
69

710
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-errorhandler)
8-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.1.1)
11+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-errorhandler/4.3.0)
912

1013
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/issues)
1114
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/network)
1215
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/stargazers)
1316
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-errorhandler)](https://github.com/dotkernel/dot-errorhandler/blob/4.1/LICENSE)
1417

1518
[![Build Static](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml/badge.svg?branch=4.1)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/continuous-integration.yml)
16-
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
19+
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.1/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
20+
[![PHPStan](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml/badge.svg?branch=4.1)](https://github.com/dotkernel/dot-errorhandler/actions/workflows/static-analysis.yml)
1721

1822
## Features
1923

phpstan.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
parameters:
4+
level: 5
5+
paths:
6+
- src
7+
- test
8+
treatPhpDocTypesAsCertain: false

psalm.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Extra/Processor/AbstractProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function replaceInlineCookieValues(ReplacementStrategy $replacementStrate
6161
'/([^=\s;]+)=([^;]*)/',
6262
fn (array $matches): string => sprintf(
6363
'%s=%s',
64-
$matches[1] ?? '',
65-
$this->replace($replacementStrategy, $matches[2] ?? '')
64+
$matches[1],
65+
$this->replace($replacementStrategy, $matches[2])
6666
),
6767
$header
6868
);

src/LogErrorHandler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,27 +140,27 @@ public function provideExtra(Throwable $throwable, ServerRequestInterface $reque
140140
];
141141

142142
if ($this->extraProvider?->getCookie()->isEnabled()) {
143-
$extra['cookie'] = $this->extraProvider?->getCookie()->provide($request->getCookieParams());
143+
$extra['cookie'] = $this->extraProvider->getCookie()->provide($request->getCookieParams());
144144
}
145145

146146
if ($this->extraProvider?->getHeader()->isEnabled()) {
147-
$extra['header'] = $this->extraProvider?->getHeader()->provide($request->getHeaders());
147+
$extra['header'] = $this->extraProvider->getHeader()->provide($request->getHeaders());
148148
}
149149

150150
if ($this->extraProvider?->getRequest()->isEnabled()) {
151-
$extra['request'] = $this->extraProvider?->getRequest()->provide((array) $request->getParsedBody());
151+
$extra['request'] = $this->extraProvider->getRequest()->provide((array) $request->getParsedBody());
152152
}
153153

154154
if ($this->extraProvider?->getServer()->isEnabled()) {
155-
$extra['server'] = $this->extraProvider?->getServer()->provide($request->getServerParams());
155+
$extra['server'] = $this->extraProvider->getServer()->provide($request->getServerParams());
156156
}
157157

158158
if ($this->extraProvider?->getSession()->isEnabled()) {
159-
$extra['session'] = $this->extraProvider?->getSession()->provide($_SESSION ?? []);
159+
$extra['session'] = $this->extraProvider->getSession()->provide($_SESSION ?? []);
160160
}
161161

162162
if ($this->extraProvider?->getTrace()->isEnabled()) {
163-
$extra['trace'] = $this->extraProvider?->getTrace()->provide($throwable->getTrace());
163+
$extra['trace'] = $this->extraProvider->getTrace()->provide($throwable->getTrace());
164164
}
165165

166166
return $extra;

test/ErrorHandlerFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testWillCreateWithDefaultOption(): void
4545
->willReturn($this->responseFactory);
4646

4747
$result = (new ErrorHandlerFactory())($this->container);
48-
$this->assertInstanceOf(ErrorHandler::class, $result);
48+
$this->assertSame(ErrorHandler::class, $result::class);
4949
}
5050

5151
/**
@@ -66,6 +66,6 @@ public function testWillCreateWithErrorResponseGenerator(): void
6666
]);
6767

6868
$result = (new ErrorHandlerFactory())($this->container);
69-
$this->assertInstanceOf(ErrorHandler::class, $result);
69+
$this->assertSame(ErrorHandler::class, $result::class);
7070
}
7171
}

test/ErrorHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function setUp(): void
5151

5252
public function testWillCreateWithDefaultParameters(): void
5353
{
54-
$this->assertInstanceOf(Subject::class, $this->subject);
54+
$this->assertContainsOnlyInstancesOf(Subject::class, [$this->subject]);
5555
}
5656

5757
public function testCreateErrorHandlerReturnsCallable(): void
@@ -112,7 +112,7 @@ public function testHandleThrowable(): void
112112

113113
$response = ($this->errorResponseGenerator)($this->exception, $this->serverRequest, ($this->responseFactory)());
114114

115-
$this->assertInstanceOf(ResponseInterface::class, $response);
115+
$this->assertContainsOnlyInstancesOf(ResponseInterface::class, [$response]);
116116
}
117117

118118
public function testErrorHandlingTriggersListeners(): void

0 commit comments

Comments
 (0)