phpro / grumphp

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

Composer task fails if packagist.org is disabled #879

Closed AegirLeet closed 3 years ago

AegirLeet commented 3 years ago
Q A
Version GrumPHP 1.3.1
Bug? yes
New feature? no
Question? no
Documentation? no
Related tickets N/A

Running the Composer task results in a crash if no_local_repository: true is set and the configuration described here is used to disable packagist.org.

https://github.com/phpro/grumphp/blob/5311bdf2166958094cf69ada9db0e4f77f83fd7b/src/Task/Composer.php#L108 assumes $repository['type'] is set, which is not guaranteed to be the case.

My configuration

# grumphp.yml

grumphp:
  tasks:
    composer:
      no_local_repository: true

Steps to reproduce:

Set up a new project:

mkdir tmp
cd tmp
git init
echo "vendor" > .gitignore
pbpaste > grumphp.yml

Add the following to composer.json:

{
    "name": "foo/bar",
    "description": "foo",
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "require-dev": {
        "phpro/grumphp": "^1.3"
    }
}

Install GrumPHP:

composer u

Then change composer.json to this:

{
    "name": "foo/bar",
    "description": "foo",
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "require-dev": {
        "phpro/grumphp": "^1.3"
    },
    "repositories": [
        {
            "packagist.org": false
        }
    ]
}

Finally, remove composer.lock (because it's outdated), stage composer.json and run GrumPHP:

rm composer.lock
git add composer.json
./vendor/bin/grumphp run

Result:

Notice: Undefined index: type in ./vendor/phpro/grumphp/src/Task/Composer.php on line 108