Skip to content

Conversation

@JanTvrdik
Copy link
Member

Summary

  • Fixes false positive: unused dependency #224
  • Detects classes used with static access patterns like Foo::class, Foo::method(), or Foo::CONSTANT in global scope when the class is not in $knownSymbols
  • This affects all static access patterns, not just ::class

Problem

When using code like:

<?php
// no namespace, no use statement
$class = ThInCacheInterface::class;

If ThInCacheInterface was not in $knownSymbols, it would not be detected as a class usage. This caused packages to be incorrectly flagged as "unused dependencies".

Solution

Added detection for unqualified class names followed by :: in global scope, similar to the existing handling for unqualified function calls.

Test plan

  • Added test cases for ::class, ::staticMethod(), and ::CONSTANT patterns in global-namespace.php
  • Updated extensions-global.php expectations for ZipArchive::class which is now detected
  • All existing tests pass
  • composer check passes

@janedbal janedbal force-pushed the fix/unqualified-static-access-224 branch from 2b655f5 to 52fe123 Compare November 25, 2025 13:39
@JanTvrdik JanTvrdik force-pushed the fix/unqualified-static-access-224 branch from 52fe123 to d960227 Compare November 25, 2025 14:26
Fix #224: Classes used with static access patterns like `Foo::class`,
`Foo::method()`, or `Foo::CONSTANT` in global scope (no namespace)
were not detected when the class was not in `$knownSymbols`.

This caused false positives where packages with such usages were
reported as "unused dependencies".

The fix adds detection for unqualified class names followed by `::`
in global scope, similar to how unqualified function calls are handled.

Note: `self`, `parent`, and `static` are already filtered by the
Analyser via `$ignoredSymbols`.
@JanTvrdik JanTvrdik force-pushed the fix/unqualified-static-access-224 branch from d960227 to 7506983 Compare November 25, 2025 14:29
@JanTvrdik JanTvrdik requested a review from janedbal November 25, 2025 14:30
@janedbal janedbal merged commit 975e587 into master Nov 25, 2025
111 of 112 checks passed
@janedbal janedbal deleted the fix/unqualified-static-access-224 branch November 25, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

false positive: unused dependency

3 participants