Skip to content

Add support to allow partial use rules per namespace#1856

Merged
kukulich merged 1 commit into
slevomat:masterfrom
Toflar:feature/allow-and-force-partial-namespace-uses
Jun 27, 2026
Merged

Add support to allow partial use rules per namespace#1856
kukulich merged 1 commit into
slevomat:masterfrom
Toflar:feature/allow-and-force-partial-namespace-uses

Conversation

@Toflar

@Toflar Toflar commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Implements feature request in #1310

It adds namespace-aware control to SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly partial-use handling.

As already explained in the original issue, the reason why I would like to have this is that some codebases intentionally use partial references for selected packages, especially Doctrine ORM and Symfony Validator.

You can now either just allow them:

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
	<properties>
		<property name="allowPartialUses" value="false"/>
		<property name="namespacesAllowedToUsePartially" type="array">
			<element value="Doctrine\ORM\Mapping as ORM"/>
			<element value="Symfony\Component\Validator\Constraints as Assert"/>
		</property>
	</properties>
</rule>

or even enforce them:

<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
	<properties>
		<property name="allowPartialUses" value="false"/>
		<property name="namespacesRequiredToUsePartially" type="array">
			<element value="Doctrine\ORM\Mapping as ORM"/>
			<element value="Symfony\Component\Validator\Constraints as Assert"/>
		</property>
	</properties>
</rule>

@Toflar
Toflar marked this pull request as draft June 19, 2026 06:48
@Toflar
Toflar force-pushed the feature/allow-and-force-partial-namespace-uses branch from 80b7915 to 0e1ab34 Compare June 19, 2026 13:47
@Toflar
Toflar marked this pull request as ready for review June 19, 2026 13:51
@Toflar

Toflar commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR so it now also allows namespace aliases properly supporting the Symfony\Component\Validator\Constraints as Assert as well. Initial PR description updated 😎

@kukulich

Copy link
Copy Markdown
Contributor

@Toflar Looks good. Can you please squash it to one commit?

@Toflar
Toflar force-pushed the feature/allow-and-force-partial-namespace-uses branch from 0e1ab34 to 530981b Compare June 22, 2026 07:05
@Toflar

Toflar commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Done 😊

@kukulich
kukulich merged commit 6511c00 into slevomat:master Jun 27, 2026
40 checks passed
@Toflar
Toflar deleted the feature/allow-and-force-partial-namespace-uses branch June 29, 2026 06:58
leofeyer pushed a commit to contao/easy-coding-standard that referenced this pull request Jul 2, 2026
… attributes (see #21)

Description
-----------

With my feature contributed in slevomat/coding-standard#1856 we can now make sure that some partial namespaces are not only allowed but enforced to be used the way we want them to 😎 

This config now ensures this usage:

```php
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Column(type: 'string')]
#[Assert\NotNull]
#[Assert\NotBlank]
private string $myProperty = '';
```

Commits
-------

a2f8efa Ensure partial usage of Symfony validator assertions and Doctrine ORM…
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.

2 participants