Skip to content

Releases: shipmonk-rnd/dead-code-detector

0.11.0

04 Apr 12:39
337b299
Compare
Choose a tag to compare

New features

  • Support unknown member names like $foo->$unknown() (#189)
    • Such call marks all methods of $foo as used (including possible descendants, ancestors, traits, ...)
  • Reflection provider:
    • Usages like ReflectionClass->getMethods() now mark alive also methods of descendants (#189)
    • Support calls over unbounded ReflectionClass<object> (#193)
      • e.g. $anyObjectReflection->getMethod('foo') marks all foo methods of all types as alive
      • Can be disabled with usageOverMixed excluder
  • New Twig provider:
    • Support #[AsTwigFilter], #[AsTwigFunction], #[AsTwigTest] and new TwigFilter(..., callback) counterparts (#194, @zacharylund)

Fixes:

  • Fix origin file reference for traits (#190)
  • Report dead method line at its name (#192)
  • Fix mixed calls diagnostics when custom excluder is used (#196)

Breaking changes:

  • Inline ignores of method with attribute need to move (#192):
- #[Deprecated] // @phpstan-ignore shipmonk.deadMethod
- public function someMethod(): void
+ #[Deprecated]
+ public function someMethod(): void // @phpstan-ignore shipmonk.deadMethod

0.10.2

28 Mar 12:13
080f8b9
Compare
Choose a tag to compare

Improvements:

  • Symfony:
  • Doctrine:
    • detect repositoryMethod in #[UniqueEntity] (#184)

Fixes:

  • Autoremove: fix removal of transitively dead constants (#183)

0.10.1

25 Mar 15:16
dacb337
Compare
Choose a tag to compare

Improvements

  • Debug: Changing references not to invalidate result cache (#169)
  • Autoremove: warn about kept excluded usages (#175)
 • Removed method UserFacade::deadMethod
   ! Excluded usage at tests/User/UserFacadeTest.php:241 left intact
  • Improve descendant detection for const fetches (#176)

Dependencies

  • phpstan/phpstan now requires ^2.1.9 (was ^2.1.7) (#169)

0.10.0

21 Mar 13:24
1a94628
Compare
Choose a tag to compare

New features:

  • Allow debugging of usages (#165, #172):
parameters:
    shipmonkDeadCode:
        debug:
            usagesOf:
                - App\User\Entity\Address::__construct

with -vvv outputs e.g.:

App\User\Entity\Address::__construct
|
| Marked as alive by:
| entry virtual usage from ShipMonk\PHPStan\DeadCode\Provider\SymfonyUsageProvider (Route method via #[Route] attribute)
|   calls App\User\RegisterUserController::__invoke:36 
|     calls App\User\UserFacade::registerUser:142
|       calls App\User\Entity\Address::__construct
|
| Found 2 usages:
|  • src/User/UserFacade.php:142
|  • tests/User/Entity/AddressTest.php:64 - excluded by tests excluder
  • Improved possible descendant detection (#151)
    • e.g. new Foo->method() does not mark method as used on Foo children anymore

Improvements:

  • Skip private constructors only when those have zero params (#159)
  • Reduce result cache size (#168)
  • Support Symfony's defaultIndexMethod on AutowireLocator/AutowireIterator attribute (#161, @ruudk)

Dependencies

  • Requires phpstan/phpstan ^2.1.7 (was ^2.0.0) (#151)

Breaking changes

  • ClassMemberUsage now requires UsageOrigin, not optionally ClassMethodRef (#165)
  • UsageOriginDetector was removed (#165)
    • use either UsageOrigin::createRegular or UsageOrigin::createVirtual
  • Virtual usages emitted by ReflectionBasedMemberUsageProvider now require note (#171)
    • true => VirtualUsageData::withNote('why considered used')
    • false => null
  • parameter trackMixedAccess was replaced with excluder (#167)
parameters:
    shipmonkDeadCode:
-         trackMixedAccess: false
+         usageExcluders:
+           usageOverMixed:
+               enabled: true

0.9.2

07 Mar 09:26
a4fef66
Compare
Choose a tag to compare

Fixes:

  • TestsUsageExcluder: fix path normalization for phar files (#155)

0.9.1

05 Mar 15:09
febeb01
Compare
Choose a tag to compare

Fixes

  • TestsUsageExcluder: normalize provided paths (#149)

0.9.0

04 Mar 10:48
c218837
Compare
Choose a tag to compare

New features:

  • Members used only in tests can be reported as dead (#139)
parameters:
    shipmonkDeadCode:
        usageExcluders:
            tests:
                enabled: true # off by default
  • Custom usage exclusions (#139)
    • via MemberUsageExcluder interface

Fixes:

  • Fix false positives in indirect usage edgecases (#141)
  • Fix transitive member reported repeatedly in a dead group when called multiple times (#143)
  • Fix usage of symbols not available on PHP 7.4 (#145)
  • Dead cycle representative error is ignorable now (no longer picked randomly) (#144)

0.8.1

22 Jan 10:36
1935d9b
Compare
Choose a tag to compare

Fixes:

  • Symfony: fix DIC filepath for phpstan-symfony 2.0.2 (#138)

0.8.0

21 Jan 09:39
478ecfa
Compare
Choose a tag to compare

New features

  • Symfony:
    • detect constants used in config yamls via !php const Foo\Bar::BAZ (#131)
    • detect methods called by DIC, e.g. factory: [Acme\SerializerFactory, create] (#128)

Fixes

  • Reflection:
    • support accessing members present only on descendants (#134)
    • proper transitivity detection (#135)
  • Fix missing parts of vendor class hierarchy (#136)

0.7.0

23 Dec 12:41
c9602b5
Compare
Choose a tag to compare

New features:

  • Full dead class constant detection support (#113)
    • Transitive detection (e.g. constant fetched in dead method is dead)
    • Usages over mixed (e.g. $unknown::CONST)
    • Auto-removal (via --error-format removeDeadCode)
    • Trait constants (available since PHP 8.2)
    • constant function (e.g. constant('PDO::ATTR_ERRMODE'))
    • customizable (e.g. you can extract !php/const Foo::BAR usages from your yamls)
  • AST-based usage providers (#117)
    • Just implement MemberUsageProvider
    • Allows to emit member usages based on e.g. methods calls
    • Handy for command buses, event systems, serializers and more
  • Detect reflection usages (#120)
    • e.g. $reflectionClass->getMethod('foo') marks foo method as used

Improvements:

  • Symfony & Doctrine: improve usage provider extendability (#121)
  • Symfony: precise detection of EventSubscriberInterface::getSubscribedEvents (#122)
  • Doctrine: precise detection of Doctrine\Common\EventSubscriber::getSubscribedEvents (#127)

Breaking changes:

  • Renames (to fit constant usages and AST-based providers):
# classes & methods
- `ShipMonk\PHPStan\DeadCode\Provider\MethodEntrypointProvider::getEntrypoints(): list<ReflectionMethod>` 
+ `ShipMonk\PHPStan\DeadCode\Provider\MemberUsageProvider::getUsages(): list<ClassMemberUsage>`

- `ShipMonk\PHPStan\DeadCode\Provider\SimpleMethodEntrypointProvider::isEntrypointMethod(): bool`
+ `ShipMonk\PHPStan\DeadCode\Provider\ReflectionBasedMemberUsageProvider::shouldMarkMethodAsUsed(): bool`

# neon config params
- `parameters.shipmonkDeadCode.entrypoints` 
+ `parameters.shipmonkDeadCode.usageProviders`

- `parameters.shipmonkDeadCode.trackCallsOnMixed` 
+ `parameters.shipmonkDeadCode.trackMixedAccess`

# neon service tag 
- `shipmonk.deadCode.entrypointProvider`
+ `shipmonk.deadCode.memberUsageProvider`