Skip to content

Disallow partial uses in ReferenceUsedNamesOnly#57

Merged
dereuromark merged 1 commit intomasterfrom
fix/partial-uses
Apr 11, 2026
Merged

Disallow partial uses in ReferenceUsedNamesOnly#57
dereuromark merged 1 commit intomasterfrom
fix/partial-uses

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Partial namespace references like Mockery\MockInterface (as opposed to FQCN \Mockery\MockInterface) were not flagged by SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly because Slevomat's allowPartialUses property defaults to true. Setting it to false makes the sniff flag such references so they must be imported via a use statement.

Related: cakephp/cakephp-codesniffer#430 — same bug confirmed in this ruleset.

Before

namespace App\Test;

class FooTest {
    public function bar(Mockery\MockInterface $x): void {}  // not flagged
}

After

ERROR | Partial use statements are not allowed, but referencing Mockery\MockInterface found.

The FQCN form (\Mockery\MockInterface) was and remains flagged by the same sniff via ReferenceViaFullyQualifiedName.

Note: this is a behavior-tightening change. Downstream code that intentionally uses partial imports (e.g. use Doctrine\ORM\Mapping as ORM; + ORM\Entity) will now error.

Partial namespace references like Mockery\MockInterface were not being
flagged because Slevomat's allowPartialUses defaults to true. Set it to
false so such references must be imported via a use statement.
@dereuromark dereuromark merged commit edf2781 into master Apr 11, 2026
4 checks passed
@dereuromark dereuromark deleted the fix/partial-uses branch April 11, 2026 10:23
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.

1 participant