Skip to content

Commit dd29749

Browse files
committed
Issue dotkernel#58: Replace Psalm with PHPStan
Signed-off-by: horea <horea@rospace.com>
1 parent c93fe44 commit dd29749

8 files changed

Lines changed: 97 additions & 27 deletions

File tree

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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ Dotkernel component used to create services through [Laminas Service Manager](ht
44

55
This package can clean up your code, by getting rid of all the factories you write, sometimes just to inject a dependency or two.
66

7+
## Documentation
8+
9+
Documentation is available at: https://docs.dotkernel.org/dot-controller/.
10+
11+
## Badges
12+
713
![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-annotated-services%2Fblob%2F4.0%2FOSSMETADATA)
8-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.2.1)
14+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.3.0)
915

1016
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/issues)
1117
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/network)
@@ -14,6 +20,7 @@ This package can clean up your code, by getting rid of all the factories you wri
1420

1521
[![Build Static](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml)
1622
[![codecov](https://codecov.io/gh/dotkernel/dot-annotated-services/graph/badge.svg?token=ZBZDEA3LY8)](https://codecov.io/gh/dotkernel/dot-annotated-services)
23+
[![PHPStan](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml)
1724

1825
## Installation
1926

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "dotkernel/dot-annotated-services",
33
"type": "library",
4-
"description": "DotKernel service creation component through laminas-servicemanager and annotations",
4+
"description": "Dotkernel service creation component through laminas-servicemanager and annotations",
55
"license": "MIT",
66
"homepage": "https://github.com/dotkernel/dot-annotated-services",
77
"authors": [
88
{
9-
"name": "DotKernel Team",
9+
"name": "Dotkernel Team",
1010
"email": "team@dotkernel.com"
1111
}
1212
],
@@ -28,8 +28,9 @@
2828
},
2929
"require-dev": {
3030
"laminas/laminas-coding-standard": "^3.0",
31-
"phpunit/phpunit": "^10.5.9",
32-
"vimeo/psalm": "^6.0"
31+
"phpstan/phpstan": "^2.1",
32+
"phpstan/phpstan-phpunit": "^2.0",
33+
"phpunit/phpunit": "^10.5.9"
3334
},
3435
"autoload": {
3536
"psr-4": {
@@ -49,8 +50,7 @@
4950
"cs-check": "phpcs",
5051
"cs-fix": "phpcbf",
5152
"test": "phpunit --colors=always",
52-
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
53-
"static-analysis": "psalm --shepherd --stats"
53+
"static-analysis": "phpstan analyse --memory-limit 1G"
5454
},
5555
"config": {
5656
"sort-packages": true,

docs/book/v4/overview.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,17 @@
33
`dot-annotated-services` is Dotkernel's dependency injection service.
44

55
By providing reusable factories for service and repository injection, it reduces code complexity in projects.
6+
7+
## Badges
8+
9+
![OSS Lifecycle](https://img.shields.io/osslifecycle?file_url=https%3A%2F%2Fgithub.com%2Fdotkernel%2Fdot-annotated-services%2Fblob%2F4.0%2FOSSMETADATA)
10+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-annotated-services/4.3.0)
11+
12+
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/issues)
13+
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/network)
14+
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/stargazers)
15+
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-annotated-services)](https://github.com/dotkernel/dot-annotated-services/blob/4.0/LICENSE.md)
16+
17+
[![Build Static](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/continuous-integration.yml)
18+
[![codecov](https://codecov.io/gh/dotkernel/dot-annotated-services/graph/badge.svg?token=ZBZDEA3LY8)](https://codecov.io/gh/dotkernel/dot-annotated-services)
19+
[![PHPStan](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/dot-annotated-services/actions/workflows/static-analysis.yml)

phpstan.neon

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
parameters:
4+
level: 5
5+
paths:
6+
- src
7+
- test
8+
treatPhpDocTypesAsCertain: false
9+
ignoreErrors:
10+
- message: '#Call to an undefined method .*::method\(\)\.#'
11+
path: test/AnnotatedRepositoryFactoryTest.php
12+
- message: '~Parameter #1 \$className of method PHPUnit\\Framework\\TestCase::getMockBuilder\(\) expects class-string<TestRepository>, string given.~'
13+
path: test/AnnotatedRepositoryFactoryTest.php
14+
- message: '#Call to an undefined method .*::method\(\)\.#'
15+
path: test/AnnotatedServiceFactoryTest.php
16+
- message: '~Parameter #1 \$className of method PHPUnit\\Framework\\TestCase::getMockBuilder\(\) expects class-string<TestService>, string given.~'
17+
path: test/AnnotatedServiceFactoryTest.php

psalm.xml

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

test/AnnotatedRepositoryFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ public function testCreateObjectReturnsEntityRepository()
8787

8888
$object = $this->subject->__invoke($this->container, $repository::class);
8989

90-
$this->assertInstanceOf(EntityRepository::class, $object);
90+
$this->assertContainsOnlyInstancesOf(EntityRepository::class, [$object]);
9191
}
9292
}

test/AnnotatedServiceFactoryTest.php

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

6161
$object = $this->subject->__invoke($this->container, $requestedName);
6262

63-
$this->assertInstanceOf($requestedName, $object);
63+
$this->assertSame($requestedName, $object::class);
6464
}
6565

6666
public function testThrowsExceptionAnnotationNotFound()
@@ -108,6 +108,6 @@ public function testReturnService()
108108

109109
$service = $this->subject->__invoke($this->container, $requestedName);
110110

111-
$this->assertInstanceOf($requestedName, $service);
111+
$this->assertSame($requestedName, $service::class);
112112
}
113113
}

0 commit comments

Comments
 (0)