Skip to content

Add phpcs sniff to report namespace to filename mismatch as per PSR-4#19467

Open
ADmad wants to merge 1 commit into
5.xfrom
phpcs
Open

Add phpcs sniff to report namespace to filename mismatch as per PSR-4#19467
ADmad wants to merge 1 commit into
5.xfrom
phpcs

Conversation

@ADmad

@ADmad ADmad commented May 25, 2026

Copy link
Copy Markdown
Member

No description provided.

@ADmad ADmad added this to the 5.3.6 milestone May 25, 2026
Comment thread phpcs.xml
</rule>
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
<properties>
<property name="rootNamespaces" type="array">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dereuromark Do you have a sniff which auto reads the PSR-4 mapping in composer.json and avoid having to do this manual mapping? 🙂

@dereuromark dereuromark May 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, PhpCollective.Classes.Psr4 already does that. It reads the PSR-4 mappings from composer.json automatically, including both autoload.psr-4 and autoload-dev.psr-4, so there is no need to maintain the namespace map manually. It also supports composerJsonPath in case the file is not at the default location.

  • PhpCollective/Sniffs/Classes/Psr4Sniff.php:47
  • PhpCollective/Sniffs/Classes/Psr4/AutoloadabilityInspectorsFactory.php:62

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, so I guess the question is whether we want to copy that sniff into Cake's codesniffer repo or add php-collective/code-sniffer as a dependency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the copy might be simpler :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying with attribution is fine.

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.

3 participants