Skip to content

Commit ca9f1c7

Browse files
committed
Introduce symfony & phpunit entrypoint providers; bump deps
1 parent 6ba6074 commit ca9f1c7

16 files changed

+1028
-483
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: 8.2
21+
php-version: 8.3
2222
-
2323
name: Install dependencies
2424
run: composer install --no-progress --prefer-dist --no-interaction
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
35+
php-version: [ '8.0', '8.1', '8.2', '8.3' ]
3636
dependency-version: [ prefer-lowest, prefer-stable ]
3737
steps:
3838
-

README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,42 @@ includes:
1717

1818

1919
## Configuration:
20-
- You need to mark all entrypoints of your code to get proper results.
21-
- This is typically long whitelist of all code that is called by your framework and libraries.
22-
- You can easily start with DefaultEntrypointProvider which marks all methods declared in vendor packages as entrypoints.
20+
- All entrypoints of your code (controllers, consumers, commands, ...) need to be known to the detector to get proper results
21+
- By default, all overridden methods which declaration originates inside vendor are considered entrypoints
22+
- Also, there are some basic entrypoint providers for `symfony` and `phpunit`
23+
- For everything else, you can implement your own entrypoint provider
2324

2425
```neon
25-
services:
26-
-
27-
class: ShipMonk\PHPStan\DeadCode\Provider\DefaultEntrypointProvider
28-
tags:
29-
- shipmonk.deadCode.entrypointProvider
26+
parameters:
27+
deadCode:
28+
entrypoints:
29+
symfony:
30+
enabled: true
31+
phpunit:
32+
enabled: true
3033
34+
services:
3135
-
32-
class: App\SymfonyEntrypointProvider
36+
class: App\MyEntrypointProvider
3337
tags:
3438
- shipmonk.deadCode.entrypointProvider
3539
```
3640
```php
3741

3842
use ReflectionMethod;
39-
use PHPStan\Reflection\ReflectionProvider;
4043
use ShipMonk\PHPStan\DeadCode\Provider\EntrypointProvider;
4144

42-
class SymfonyEntrypointProvider implements EntrypointProvider
45+
class MyEntrypointProvider implements EntrypointProvider
4346
{
4447

45-
public function __construct(
46-
private ReflectionProvider $reflectionProvider
47-
) {}
48-
4948
public function isEntrypoint(ReflectionMethod $method): bool
5049
{
51-
$methodName = $method->getName();
52-
$reflection = $this->reflectionProvider->getClass($method->getDeclaringClass()->getName());
53-
54-
return $reflection->is(\Symfony\Bundle\FrameworkBundle\Controller\AbstractController::class)
55-
|| $reflection->is(\Symfony\Component\EventDispatcher\EventSubscriberInterface::class)
56-
|| $method->getAttributes(\Symfony\Contracts\Service\Attribute\Required::class) !== []
57-
// and many more
50+
return $method->getDeclaringClass()->implementsInterface(ApiOutput::class));
5851
}
5952
}
6053
```
6154

62-
## Limitations
63-
This project is currently a working prototype (we are using it since 2022) with limited functionality:
55+
## Limitations:
6456

6557
- Only method calls are detected
6658
- Including static methods, trait methods, interface methods, first class callables, etc.
@@ -79,4 +71,4 @@ This project is currently a working prototype (we are using it since 2022) with
7971
- All functionality must be tested
8072

8173
## Supported PHP versions
82-
- PHP 7.4 - 8.3
74+
- PHP 8.0 - 8.3

composer.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212
"dead code"
1313
],
1414
"require": {
15-
"php": "^7.4 || ^8.0",
16-
"phpstan/phpstan": "^1.10.30"
15+
"php": "^8.0",
16+
"phpstan/phpstan": "^1.11.0"
1717
},
1818
"require-dev": {
1919
"editorconfig-checker/editorconfig-checker": "^10.3.0",
2020
"ergebnis/composer-normalize": "^2.28",
2121
"phpstan/phpstan-phpunit": "^1.1.1",
2222
"phpstan/phpstan-strict-rules": "^1.2.3",
23-
"phpunit/phpunit": "^9.5.20",
23+
"phpunit/phpunit": "^10.5.27",
2424
"shipmonk/name-collision-detector": "^2.0.0",
25-
"shipmonk/phpstan-rules": "^2.11",
26-
"slevomat/coding-standard": "^8.0.1"
25+
"shipmonk/phpstan-rules": "^3.1",
26+
"slevomat/coding-standard": "^8.0.1",
27+
"symfony/contracts": "^3.5",
28+
"symfony/event-dispatcher": "^6.0",
29+
"symfony/routing": "^6.0"
2730
},
2831
"autoload": {
2932
"psr-4": {
@@ -65,7 +68,7 @@
6568
"check:composer": "composer normalize --dry-run --no-check-lock --no-update-lock",
6669
"check:cs": "phpcs",
6770
"check:ec": "ec src tests",
68-
"check:tests": "phpunit -vvv tests",
71+
"check:tests": "phpunit tests",
6972
"check:types": "phpstan analyse -vvv --ansi",
7073
"fix:cs": "phpcbf"
7174
}

0 commit comments

Comments
 (0)