Php-cs-fixer: PSRAutoloading Fixer is removing directory structure from the Class name

Created on 17 Dec 2020  ·  2Comments  ·  Source: FriendsOfPHP/PHP-CS-Fixer

Bug report

Version 2.17.2 just released and I wanted to test it against a repo as I saw the same issue reported in #5342 and was curious if this new release would fix that.

However, after running this new release against this repo, PHP-CS-Fixer stripped all of the PSR0 prefixes off of every class that it touched.

I believe this is due to the changes in #5348. Version 2.17.1 ran on the same repo does not do this.

For example, here's the autoload in composer:

"autoload": {
        "psr-0": {
            "Doctrine_": "lib/"
        },
        "classmap": [
            "lib/Doctrine.php"
        ]
    },

Then in this file: lib/Doctrine/AuditLog/Listener/Microtime.php it's doing this:

Screen Shot 2020-12-17 at 9 58 48 AM

This happens to every file in the repo, which obviously breaks everything since the classnames no longer match what's being used elsewhere.

kinbug kinquestion

Most helpful comment

I'm working (slowly, to remind myself PSR-0 and PSR-4 rules with all the details).
My plan has 3 steps:

  • add better tests cases (with the one from this bug and other coming from PSR0/4 official definitions) and fix the bug with one another if (as the fixer right now is mostly ifs
  • migrate old test cases to the new one as the old ones have a weird mocking mechanism
  • refactor fixer itself as currently, it's really messy

All 2 comments

Hi @jaydiablo and thanks for your report.

ping @kubawerlos
should the dir be configured here to support fixing to the underscore format? curious if this is regression or expected
I think should still follow
Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace.

I'm working (slowly, to remind myself PSR-0 and PSR-4 rules with all the details).
My plan has 3 steps:

  • add better tests cases (with the one from this bug and other coming from PSR0/4 official definitions) and fix the bug with one another if (as the fixer right now is mostly ifs
  • migrate old test cases to the new one as the old ones have a weird mocking mechanism
  • refactor fixer itself as currently, it's really messy
Was this page helpful?
0 / 5 - 0 ratings

Related issues

EvgenyOrekhov picture EvgenyOrekhov  ·  3Comments

ndench picture ndench  ·  3Comments

teohhanhui picture teohhanhui  ·  3Comments

vitek-rostislav picture vitek-rostislav  ·  3Comments

kcloze picture kcloze  ·  3Comments