Disallow partial uses in ReferenceUsedNamesOnly#431
Conversation
Partial namespace references like Mockery\MockInterface were not being flagged by ReferenceUsedNamesOnly because Slevomat's allowPartialUses defaults to true. Set it to false so such references are required to be imported via a use statement.
|
Won't this throw error for current usages like https://github.com/cakephp/cakephp/blob/d70712c983e6879bfcddd67d975d4b8ef3328aae/src/Database/TypeFactory.php#L33 ? |
|
This goes into 6.x right now, we can backport it, but thats indeed a bit breaking. |
|
technically nothing can break, its just a code style change. I'd say this can stay in 6.x |
|
My point was this rule is a bit too pedantic for my liking. |
|
If the latest PER standard allows such partial usages then I would be in favor of keeping it. |
|
Partials make the review much harder for humans IMO, as you need to scope in the context then always (you cannot directly see if this is root level or nested namespace). Disallow partial uses Pros
Cons
|
|
I don't mind either way, i just thought its obvious to keep it more consistent. |
Fixes #430.
Partial namespace references like
Mockery\MockInterface(as opposed to the FQCN form\Mockery\MockInterface) were not flagged bySlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnlybecause Slevomat'sallowPartialUsesproperty defaults totrue.Setting it to
falsemakes the sniff flag such references so they must be imported via ausestatement.Before
After
The FQCN form (
\Mockery\MockInterface) was and remains flagged by the same sniff.Note: this is a behavior-tightening change. Downstream code that intentionally uses partial imports would be affected - but I guess thats fair enough as they could change it back themselves.