@@ -17,49 +17,48 @@ 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.
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, just tag it with ` shipmonk.deadCode.entrypointProvider `
22
24
23
25
``` neon
26
+ parameters:
27
+ deadCode:
28
+ entrypoints:
29
+ vendor:
30
+ enabled: true # enabled by default
31
+ symfony:
32
+ enabled: true
33
+ phpunit:
34
+ enabled: true
35
+
24
36
services:
25
37
-
26
- class: App\SymfonyEntrypointProvider
38
+ class: App\MyEntrypointProvider
27
39
tags:
28
40
- shipmonk.deadCode.entrypointProvider
29
41
```
30
42
``` php
31
43
32
44
use ReflectionMethod;
33
- use PHPStan\Reflection\ReflectionProvider;
34
45
use ShipMonk\PHPStan\DeadCode\Provider\EntrypointProvider;
35
46
36
- class SymfonyEntrypointProvider implements EntrypointProvider
47
+ class MyEntrypointProvider implements EntrypointProvider
37
48
{
38
49
39
- public function __construct(
40
- private ReflectionProvider $reflectionProvider
41
- ) {}
42
-
43
50
public function isEntrypoint(ReflectionMethod $method): bool
44
51
{
45
- $methodName = $method->getName();
46
- $reflection = $this->reflectionProvider->getClass($method->getDeclaringClass()->getName());
47
-
48
- return $reflection->is(\Symfony\Bundle\FrameworkBundle\Controller\AbstractController::class)
49
- || $reflection->is(\Symfony\Component\EventDispatcher\EventSubscriberInterface::class)
50
- || $reflection->is(\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::class)
51
- || ($reflection->is(\Symfony\Component\Console\Command\Command::class) && in_array($methodName, ['execute', 'initialize', ...], true)
52
- // and many more
52
+ return $method->getDeclaringClass()->implementsInterface(ApiOutput::class));
53
53
}
54
54
}
55
55
```
56
56
57
- ## Limitations
58
- This project is currently a working prototype (we are using it since 2022) with limited functionality:
57
+ ## Limitations:
59
58
60
59
- Only method calls are detected
61
60
- Including static methods, trait methods, interface methods, first class callables, etc.
62
- - Callbacks like ` [$this, 'method'] ` are mostly not detected
61
+ - Callbacks like ` [$this, 'method'] ` are mostly not detected; prefer first class callables ` $this->method(...) `
63
62
- Any calls on mixed types are not detected, e.g. ` $unknownClass->method() `
64
63
- Expression method calls are not detected, e.g. ` $this->$methodName() `
65
64
- Anonymous classes are ignored
0 commit comments