Skip to content

Class clash with phpcs and PHPCompatibility #411

Closed
@Synchro

Description

@Synchro
Q A
Bug report? not sure!
Feature request? no
Library version 1.14.0

I've set up a new project with both phpcs and phpinsights. My phpcs.xml file specifies PSR12 and PHPCompatibility rule sets:

<rule ref="PSR12"/>
<rule ref="PHPCompatibility"/>

but if I run phpinsights, it crashes like this:

 ./vendor/bin/phpinsights analyse src
0/5 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%

Fatal error: Cannot declare class PHPCompatibility\Sniffs\FunctionUse\RequiredToOptionalFunctionParametersSniff, because the name is already in use in project/vendor/phpcompatibility/php-compatibility/PHPCompatibility/Sniffs/FunctionUse/RequiredToOptionalFunctionParametersSniff.php on line 30

Call Stack:
    0.0009     475136   1. {main}() project/vendor/nunomaduro/phpinsights/bin/phpinsights:0
    0.0013     475456   2. {closure: project/vendor/nunomaduro/phpinsights/bin/phpinsights:9-36}() project/vendor/nunomaduro/phpinsights/bin/phpinsights:36
    0.0352    2915168   3. Symfony\Component\Console\Application->run() project/vendor/nunomaduro/phpinsights/bin/phpinsights:35
    0.0486    3149944   4. Symfony\Component\Console\Application->doRun() project/vendor/symfony/console/Application.php:147
    0.0498    3162496   5. Symfony\Component\Console\Application->doRunCommand() project/vendor/symfony/console/Application.php:271
    0.0498    3162496   6. NunoMaduro\PhpInsights\Application\Console\Commands\InvokableCommand->run() project/vendor/symfony/console/Application.php:1001
    0.0502    3163896   7. NunoMaduro\PhpInsights\Application\Console\Commands\InvokableCommand->execute() project/vendor/symfony/console/Command/Command.php:255
    0.0502    3163896   8. call_user_func:{project/vendor/nunomaduro/phpinsights/src/Application/Console/Commands/InvokableCommand.php:37}() project/vendor/nunomaduro/phpinsights/src/Application/Console/Commands/InvokableCommand.php:37
    0.0502    3163896   9. NunoMaduro\PhpInsights\Application\Console\Commands\AnalyseCommand->__invoke() project/vendor/nunomaduro/phpinsights/src/Application/Console/Commands/InvokableCommand.php:37
    0.0559    3566232  10. NunoMaduro\PhpInsights\Application\Console\Analyser->analyse() project/vendor/nunomaduro/phpinsights/src/Application/Console/Commands/AnalyseCommand.php:70
    0.0561    3570592  11. NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory->get() project/vendor/nunomaduro/phpinsights/src/Application/Console/Analyser.php:58
    0.0786    4106392  12. array_map() project/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php:91
    0.0786    4107088  13. NunoMaduro\PhpInsights\Domain\Insights\InsightCollectionFactory->NunoMaduro\PhpInsights\Domain\Insights\{closure: project/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php:82-91}() project/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php:91
    0.0789    4116352  14. NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->makeFrom() project/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightCollectionFactory.php:85
    0.0789    4116352  15. NunoMaduro\PhpInsights\Domain\Insights\InsightFactory->runInsightCollector() project/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightFactory.php:78
    0.1721    9495168  16. NunoMaduro\PhpInsights\Domain\Runner->run() project/vendor/nunomaduro/phpinsights/src/Domain/Insights/InsightFactory.php:107
    0.1742    9649528  17. NunoMaduro\PhpInsights\Domain\Runner->processFile() project/vendor/nunomaduro/phpinsights/src/Domain/Runner.php:80
    0.1742    9649528  18. NunoMaduro\PhpInsights\Domain\FileProcessors\SniffFileProcessor->processFile() project/vendor/nunomaduro/phpinsights/src/Domain/Runner.php:94
    0.1742    9649528  19. NunoMaduro\PhpInsights\Domain\FileFactory->createFromFileInfo() project/vendor/nunomaduro/phpinsights/src/Domain/FileProcessors/SniffFileProcessor.php:59
    0.1770    9974784  20. NunoMaduro\PhpInsights\Domain\File->__construct() project/vendor/nunomaduro/phpinsights/src/Domain/FileFactory.php:18
    0.1871   10241384  21. PHP_CodeSniffer\Ruleset->__construct() project/vendor/nunomaduro/phpinsights/src/Domain/File.php:47
    0.2110   10311048  22. PHP_CodeSniffer\Ruleset->registerSniffs() project/vendor/squizlabs/php_codesniffer/src/Ruleset.php:217
    0.2464   13765592  23. PHP_CodeSniffer\Autoload::loadFile() project/vendor/squizlabs/php_codesniffer/src/Ruleset.php:1159
    0.2466   13847296  24. include('project/vendor/phpcompatibility/php-compatibility/PHPCompatibility/Sniffs/FunctionUse/RequiredToOptionalFunctionParametersSniff.php') project/vendor/squizlabs/php_codesniffer/autoload.php:167

If I comment out the PHPCompability set from my phpcs config file, it works fine. I deduce from this that phpinsights also pulls in PHPCompatibility itself, and this results in a duplicate class definition if it's also pulled in by phpcs.

Would it not be better to have phpinsights defer to the rule set defined for phpcs (if there is one) rather than assuming something that might be wrong, as in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions