@@ -17,50 +17,42 @@ includes:
17
17
18
18
19
19
## 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
23
24
24
25
``` 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
30
33
34
+ services:
31
35
-
32
- class: App\SymfonyEntrypointProvider
36
+ class: App\MyEntrypointProvider
33
37
tags:
34
38
- shipmonk.deadCode.entrypointProvider
35
39
```
36
40
``` php
37
41
38
42
use ReflectionMethod;
39
- use PHPStan\Reflection\ReflectionProvider;
40
43
use ShipMonk\PHPStan\DeadCode\Provider\EntrypointProvider;
41
44
42
- class SymfonyEntrypointProvider implements EntrypointProvider
45
+ class MyEntrypointProvider implements EntrypointProvider
43
46
{
44
47
45
- public function __construct(
46
- private ReflectionProvider $reflectionProvider
47
- ) {}
48
-
49
48
public function isEntrypoint(ReflectionMethod $method): bool
50
49
{
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));
58
51
}
59
52
}
60
53
```
61
54
62
- ## Limitations
63
- This project is currently a working prototype (we are using it since 2022) with limited functionality:
55
+ ## Limitations:
64
56
65
57
- Only method calls are detected
66
58
- 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
79
71
- All functionality must be tested
80
72
81
73
## Supported PHP versions
82
- - PHP 7.4 - 8.3
74
+ - PHP 8.0 - 8.3
0 commit comments