phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 430 forks source link

Cannot redeclare Amp\delay() when installed globally and in specific projects #1153

Closed loopy3025 closed 1 month ago

loopy3025 commented 1 month ago
Q A
Version 2.7.0
Bug? yes
New feature? no
Question? yes
Documentation? no
Related tickets #51 #410

Fatal error: Cannot redeclare Amp\delay() (previously declared in /Users/adam/projects/oursite/vendor/amphp/amp/src/functions.php:63) in /Users/adam/.composer/vendor/amphp/amp/lib/functions.php on line 133

I've started getting this recently. I'm not sure what could have changed to cause this to start happening.

I have grumphp installed globally via composer on my computer and I have it installed in each of our projects via composer for ci and ide purposes. I suspect that's why I'm getting the error when I run composer install on those projects. It also throws when I run grumphp commands in those projects.

Running /vendor/bin/grumphp works fine when run explicitly, but when run as a git hook or composer hook, it seems to be the same as executing the grumphp alias.

My configuration

grumphp:
    tasks:
        composer: ~
        phplint: ~ 
        yamllint: ~
        phpcs:
          standard: "phpcs.xml.dist"
        securitychecker_composeraudit: ~
        git_commit_message: 
            matchers:
                Must use the following format (jira project, dash, jira number, space, commit message): "/(\\w+)-\\d+:\\s+.+/"
            max_subject_width: 120
            max_body_width: 255

Steps to reproduce:

Workaround:

BrentRobert commented 1 month ago

Hi @loopy3025, You can install GrumPHP using the 'shim' version. This is a separate packaged version so you don't have a conflicting dependencies: https://github.com/phpro/grumphp-shim

loopy3025 commented 1 month ago

Thanks, I'll check that out.

loopy3025 commented 1 month ago

@BrentRobert Installing phpro/grumphp-shim globally has worked perfectly. Thank you.