Skip to content

Commit a3ddfe2

Browse files
authored
Readme: update limitations & problematic cases (#108)
1 parent 9636567 commit a3ddfe2

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,15 @@ parameters:
131131
vendor/bin/phpstan analyse --error-format removeDeadCode
132132
```
133133

134-
```php
135-
// before
134+
```diff
136135
class UserFacade
137136
{
138-
public function deadMethod(): void
139-
{
140-
}
137+
- public function deadMethod(): void
138+
- {
139+
- }
141140
}
142141
```
143142

144-
```php
145-
// after
146-
class UserFacade
147-
{
148-
}
149-
```
150143

151144
## Calls over unknown types
152145
- In order to prevent false positives, we support even calls over unknown types (e.g. `$unknown->method()`) by marking all methods named `method` as used
@@ -176,13 +169,36 @@ Found 2 methods called over unknown type:
176169
- It has almost no built-it library extensions
177170
- It ignores trait methods
178171
- Is lacks many minor features like class-string calls, dynamic method calls, array callbacks, nullsafe call chains etc
172+
- It cannot detect dead cycles nor transitively dead methods
173+
- It has no built-in dead code removal
179174

180175
## Limitations:
176+
- Methods of anonymous classes are never reported as dead ([PHPStan limitation](https://github.com/phpstan/phpstan/issues/8410))
177+
- Abstract trait methods are never reported as dead
178+
- Most magic methods (e.g. `__get`, `__set` etc) are never reported as dead
179+
- Only supported are: `__construct`, `__clone`
180+
181+
### Other problematic cases:
182+
183+
#### Constructors:
184+
- For symfony apps & PHPStan extensions, we simplify the detection by assuming all DIC classes have used constructor.
185+
- For other apps, you may get false-positives if services are created magically.
186+
- To avoid those, you can easily disable consructor analysis with single ignore:
187+
188+
```neon
189+
parameters:
190+
ignoreErrors:
191+
- '#^Unused .*?::__construct$#'
192+
```
193+
194+
#### Private constructors:
195+
- Those are never reported as dead as those are often used to deny class instantiation
181196

182-
- Only dead method calls are detected so far
183-
- Including **constructors**, static methods, trait methods, interface methods, first class callables, clone, etc.
184-
- Methods of anonymous classes are never reported as dead ([PHPStan limitation](https://github.com/phpstan/phpstan/issues/8410))
185-
- Most magic methods (e.g. `__get`, `__set` etc) are never reported as dead
197+
198+
## Future scope:
199+
- Dead class constant detection
200+
- Dead class property detection
201+
- Dead class detection
186202

187203
## Contributing
188204
- Check your code by `composer check`

0 commit comments

Comments
 (0)