Skip to content

Commit a25fea0

Browse files
committed
Issue#45: Replace Psalm with PHPStan
Signed-off-by: horea <horea@rospace.com>
1 parent f8529ba commit a25fea0

File tree

8 files changed

+67
-28
lines changed

8 files changed

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It is more lightweight though, but supports controller plugins and event listene
1414

1515
[![Build Static](https://github.com/dotkernel/dot-controller/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-controller/actions/workflows/continuous-integration.yml)
1616
[![codecov](https://codecov.io/gh/dotkernel/dot-controller/graph/badge.svg?token=VUBG5LM4CK)](https://codecov.io/gh/dotkernel/dot-controller)
17-
17+
[![PHPStan](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml)
1818
## Installation
1919

2020
Install `dot-controller` by executing the following Composer command:

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
"require-dev": {
2929
"laminas/laminas-coding-standard": "^3.0",
3030
"laminas/laminas-diactoros": "^3.0",
31-
"phpunit/phpunit": "^10.2",
32-
"vimeo/psalm": "^6.0"
31+
"phpstan/phpstan": "^2.1",
32+
"phpstan/phpstan-phpunit": "^2.0",
33+
"phpunit/phpunit": "^10.2"
3334
},
3435
"autoload": {
3536
"psr-4": {
@@ -50,8 +51,7 @@
5051
"cs-check": "phpcs",
5152
"cs-fix": "phpcbf",
5253
"test": "phpunit --colors=always",
53-
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
54-
"static-analysis": "psalm --shepherd --stats"
54+
"static-analysis": "phpstan analyse --memory-limit 1G"
5555
},
5656
"config": {
5757
"sort-packages": true,

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.

test/AbstractActionControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testNonExistingActionWillReturnResponse(): void
2828
};
2929

3030
$response = $subject->process($request, $handler);
31-
$this->assertInstanceOf(ResponseInterface::class, $response);
31+
$this->assertContainsOnlyInstancesOf(ResponseInterface::class, [$response]);
3232
}
3333

3434
/**
@@ -49,6 +49,6 @@ public function indexAction(): ResponseInterface
4949
};
5050

5151
$response = $subject->process($request, $handler);
52-
$this->assertInstanceOf(ResponseInterface::class, $response);
52+
$this->assertContainsOnlyInstancesOf(ResponseInterface::class, [$response]);
5353
}
5454
}

test/Factory/ControllerEventListenersInitializerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,5 @@ public function testAttachControllerListeners(): void
7373
->with($this->isInstanceOf(ControllerEventListenerInterface::class), 1);
7474

7575
$this->subject->attachControllerListeners($this->container, $this->controller);
76-
77-
$this->assertTrue(true);
7876
}
7977
}

test/Factory/PluginManagerFactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testInvokeWithUrlHelper(): void
6060

6161
$pluginManager = $this->subject->__invoke($this->container);
6262

63-
$this->assertInstanceOf(PluginManager::class, $pluginManager);
63+
$this->assertContainsOnlyInstancesOf(PluginManager::class, [$pluginManager]);
6464
$this->assertTrue($pluginManager->has('url'));
6565
$this->assertFalse($pluginManager->has('template'));
6666
$this->assertInstanceOf(UrlHelperPlugin::class, $pluginManager->get('url'));
@@ -91,7 +91,7 @@ public function testInvokeWithTemplateRenderer(): void
9191

9292
$pluginManager = $this->subject->__invoke($this->container);
9393

94-
$this->assertInstanceOf(PluginManager::class, $pluginManager);
94+
$this->assertContainsOnlyInstancesOf(PluginManager::class, [$pluginManager]);
9595
$this->assertTrue($pluginManager->has('template'));
9696
$this->assertFalse($pluginManager->has('url'));
9797
$this->assertInstanceOf(TemplatePlugin::class, $pluginManager->get('template'));

0 commit comments

Comments
 (0)