Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #50: Replace Psalm with PHPStan #51

Open
wants to merge 2 commits into
base: 4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
- push

name: Run PHPStan checks

jobs:
mutation:
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.2"
- "8.3"
- "8.4"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-

- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis with PHPStan
run: vendor/bin/phpstan analyse
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/
## Badges

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

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

[![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)
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.0/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.1/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
[![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)

## Adding the error handler

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
"require-dev": {
"laminas/laminas-coding-standard": "^3.0.1",
"mikey179/vfsstream": "^1.6.12",
"phpunit/phpunit": "^10.5.45",
"vimeo/psalm": "6.6.2"
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5.45"
},
"autoload": {
"psr-4": {
Expand All @@ -57,6 +58,6 @@
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"static-analysis": "psalm --shepherd --stats"
"static-analysis": "phpstan analyse --memory-limit 1G"
}
}
14 changes: 14 additions & 0 deletions docs/book/v3/overview.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong file, this content should go to docs/book/v4/overview.md.

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@

- `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
- `Dot\ErrorHandler\LogErrorHandler` adds logging support to the default `ErrorHandler` class

## Badges

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

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

[![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)
[![codecov](https://codecov.io/gh/dotkernel/dot-errorhandler/branch/4.1/graph/badge.svg?token=0KIJARS5RS)](https://codecov.io/gh/dotkernel/dot-errorhandler)
[![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)
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 5
paths:
- src
- test
treatPhpDocTypesAsCertain: false
17 changes: 0 additions & 17 deletions psalm.xml

This file was deleted.

4 changes: 2 additions & 2 deletions src/Extra/Processor/AbstractProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function replaceInlineCookieValues(ReplacementStrategy $replacementStrate
'/([^=\s;]+)=([^;]*)/',
fn (array $matches): string => sprintf(
'%s=%s',
$matches[1] ?? '',
$this->replace($replacementStrategy, $matches[2] ?? '')
$matches[1],
$this->replace($replacementStrategy, $matches[2])
),
$header
);
Expand Down
12 changes: 6 additions & 6 deletions src/LogErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,27 @@ public function provideExtra(Throwable $throwable, ServerRequestInterface $reque
];

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

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

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

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

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

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

return $extra;
Expand Down
4 changes: 2 additions & 2 deletions test/ErrorHandlerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testWillCreateWithDefaultOption(): void
->willReturn($this->responseFactory);

$result = (new ErrorHandlerFactory())($this->container);
$this->assertInstanceOf(ErrorHandler::class, $result);
$this->assertSame(ErrorHandler::class, $result::class);
}

/**
Expand All @@ -66,6 +66,6 @@ public function testWillCreateWithErrorResponseGenerator(): void
]);

$result = (new ErrorHandlerFactory())($this->container);
$this->assertInstanceOf(ErrorHandler::class, $result);
$this->assertSame(ErrorHandler::class, $result::class);
}
}
4 changes: 2 additions & 2 deletions test/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setUp(): void

public function testWillCreateWithDefaultParameters(): void
{
$this->assertInstanceOf(Subject::class, $this->subject);
$this->assertContainsOnlyInstancesOf(Subject::class, [$this->subject]);
}

public function testCreateErrorHandlerReturnsCallable(): void
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testHandleThrowable(): void

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

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

public function testErrorHandlingTriggersListeners(): void
Expand Down
10 changes: 5 additions & 5 deletions test/LogErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function setUp(): void

public function testWillCreateWithDefaultParameters(): void
{
$this->assertInstanceOf(Subject::class, $this->subject);
$this->assertContainsOnlyInstancesOf(Subject::class, [$this->subject]);
}

public function testCreateErrorHandlerReturnsCallable(): void
Expand Down Expand Up @@ -104,7 +104,7 @@ public function testLogErrorHandlerWillInitiateWhenExtraProviderIsMissing(): voi
new Logger($this->getConfig()),
);

$this->assertInstanceOf(LogErrorHandler::class, $logErrorHandler);
$this->assertSame(LogErrorHandler::class, $logErrorHandler::class);
$this->assertNull($logErrorHandler->getExtraProvider());
}

Expand All @@ -120,7 +120,7 @@ public function testLogErrorHandlerWillInitiateWhenExtraProviderIsNull(): void
null
);

$this->assertInstanceOf(LogErrorHandler::class, $logErrorHandler);
$this->assertSame(LogErrorHandler::class, $logErrorHandler::class);
$this->assertNull($logErrorHandler->getExtraProvider());
}

Expand All @@ -136,7 +136,7 @@ public function testLogErrorHandlerWillInitiateWhenExtraProviderIsProvided(): vo
new ExtraProvider()
);

$this->assertInstanceOf(LogErrorHandler::class, $logErrorHandler);
$this->assertSame(LogErrorHandler::class, $logErrorHandler::class);
$this->assertInstanceOf(ExtraProvider::class, $logErrorHandler->getExtraProvider());
}

Expand Down Expand Up @@ -255,7 +255,7 @@ public function testHandleThrowable(): void

$response = $responseGenerator($this->exception, $this->serverRequest, ($this->responseFactory)());

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

public function testErrorHandlingTriggersListeners(): void
Expand Down