PHPCSStandards / composer-installer

Composer installer for PHP_CodeSniffer coding standards
https://packagist.org/packages/dealerdirect/phpcodesniffer-composer-installer
MIT License
552 stars 36 forks source link

Install of dealerdirect/phpcodesniffer-composer-installer failed #121

Closed elb98rm closed 3 years ago

elb98rm commented 3 years ago

Problem/Motivation

Attempting to do a CakePHP upgrade using composer and this plugin is failing

Expected behaviour

Composer should update normally

Actual behaviour

Composer runs into errors:

Using either: "cakephp/cakephp-codesniffer": : "0.7.0" or "dev-master" results in:

  - Installing dealerdirect/phpcodesniffer-composer-installer (v0.7.0): Extracting archive
Plugin initialization failed (include(/var/www/upgrade/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php): failed to open stream: No such file or directory), uninstalling plugin

(which then causes):

  [RuntimeException]                                                                                                 
  Could not delete /var/www/upgrade/vendor/dealerdirect/phpcodesniffer-composer-installer/src: 

Steps to reproduce

This is a clean install from cakephp, using the dev-master branch.

{
    "name": "cakephp/app",
    "description": "CakePHP skeleton app",
    "homepage": "https://cakephp.org",
    "type": "project",
    "license": "MIT",
    "require": {
        "php": ">=7.2",
        "cakephp/cakephp": "~4.1.0",
        "cakephp/migrations": "^3.0",
        "cakephp/plugin-installer": "dev-master",
        "mobiledetect/mobiledetectlib": "^2.8"
    },
    "require-dev": {
        "cakephp/bake": "^2.0.3",
        "cakephp/cakephp-codesniffer": "dev-master",
        "cakephp/debug_kit": "^4.1",
        "josegonzalez/dotenv": "^3.2",
        "phpunit/phpunit": "~8.5.0",
        "psy/psysh": "@stable"
    },
    "suggest": {
        "markstory/asset_compress": "An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.",
        "dereuromark/cakephp-ide-helper": "After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan/Psalm compatibility.",
        "phpstan/phpstan": "PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code."
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Test\\": "tests/",
            "Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
        }
    },
    "scripts": {
        "post-install-cmd": "App\\Console\\Installer::postInstall",
        "post-create-project-cmd": "App\\Console\\Installer::postInstall",
        "check": [
            "@test",
            "@cs-check"
        ],
        "cs-check": "phpcs --colors -p  src/ tests/",
        "cs-fix": "phpcbf --colors -p src/ tests/",
        "stan": "phpstan analyse src/",
        "test": "phpunit --colors=always"
    },
    "prefer-stable": true,
    "config": {
        "sort-packages": true
    }
}

Proposed changes

Have attempted to use dev-master as described above.

Environment

Question Answer
OS Ubuntu 16.04.7 LTS via Vagrant
PHP version 7.4.12
Composer version 2.0.7
PHP_CodeSniffer version dev-master
Dealerdirect PHPCS plugin version unknown
Install type using cakephp's installer: composer create-project --prefer-dist cakephp/app:~4.0 my_app_name

Output of vendor/bin/phpcs --config-show:

-bash: vendor/bin/phpcs: No such file or directory

Tested against master branch?

jrfnl commented 3 years ago

@elb98rm Thanks for reporting this.

Unfortunately I have not been able to reproduce the issue (on Windows).

Steps I executed using PHP 7.4.12 and Composer 2.0.7:

  1. composer create-project --prefer-dist cakephp/app:~4.0 my_app_name
  2. cd my-app_name
  3. vendor/bin/phpcs -i

All worked and finished without errors, with the output of the last command being The installed coding standards are MySource, PEAR, PSR1, PSR12, PSR2, Squiz, Zend, SlevomatCodingStandard and CakePHP.

As Windows is more fiddly than Linux, I expect the same results on Ubuntu.

In your issue you mention that you are attempting to update the install though. I'm willing to give it another try, but would need more detailed information on what the old version of CakePHP was from which you are upgrading, possibly a composer.lock file of the old install would help. Also, what is the update command you are using ?

Potherca commented 3 years ago

I've seen similar issues in the past that were related to composer being run from one environment for the initial install but then run from another environment for a sebsequent update. For instance when Docker or other virtual environments were involved.

Read/Write/Delete errors then occur because the access right from one environment do not match that of the other.

@elb98rm Could something like that be happening here?

elb98rm commented 3 years ago

Hi, sorry for the delay! Was away for the weekend.

I've been able to resolve this by executing this in another folder; which suggests that permissions are wrong somehow.

Not sure if it's vagrant weirdness either... the relevant folder (/var/www/test) was set to 777. This executed fine in the home directory however.

However, I find this even weirder.. composer doesn't fail for other modules, and scripts associated with other frameworks don't seem to have a problem.

Oh well. For anyone else with this issue:

"Try it in your home directory".

Thanks for investigating.

jrfnl commented 3 years ago

@elb98rm Thanks for getting back to us and posting your solution. Hopefully it will help someone else who may run into this.