Skip to content

Commit f5e02d4

Browse files
authored
Allow specifying a list of extensions to ignore
1 parent 3f3d1ba commit f5e02d4

File tree

12 files changed

+139
-7
lines changed

12 files changed

+139
-7
lines changed

.github/workflows/integration-tests.yml

+41-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
COMPOSER_ROOT_VERSION: "1.2.x-dev"
1313

1414
jobs:
15-
test:
15+
integration-test:
1616
name: "Integration test"
1717
runs-on: "ubuntu-latest"
1818

@@ -40,16 +40,52 @@ jobs:
4040
tools: "composer:${{ matrix.composer-version }}"
4141

4242
- name: "Install dependencies"
43-
working-directory: "e2e"
43+
working-directory: "e2e/integration"
4444
run: "composer install --no-interaction --no-progress --no-suggest"
4545

4646
- name: "Test"
47-
working-directory: "e2e"
47+
working-directory: "e2e/integration"
4848
run: "vendor/bin/phpstan analyse -l 8 FooTest.php"
4949

5050
- name: "Rename directory"
51-
run: "mv e2e e3e"
51+
working-directory: "e2e"
52+
run: "mv integration integration-copy"
5253

5354
- name: "Test relative paths - after renaming"
54-
working-directory: "e3e"
55+
working-directory: "e2e/integration-copy"
5556
run: "vendor/bin/phpstan analyse -l 8 FooTest.php"
57+
58+
ignore-test:
59+
name: "Ignore test"
60+
runs-on: "ubuntu-latest"
61+
62+
strategy:
63+
matrix:
64+
php-version:
65+
- "7.4"
66+
- "8.0"
67+
- "8.1"
68+
- "8.2"
69+
composer-version:
70+
- "v2"
71+
- "preview"
72+
- "snapshot"
73+
74+
steps:
75+
- name: "Checkout"
76+
uses: actions/checkout@v3
77+
78+
- name: "Install PHP"
79+
uses: "shivammathur/setup-php@v2"
80+
with:
81+
coverage: "none"
82+
php-version: "${{ matrix.php-version }}"
83+
tools: "composer:${{ matrix.composer-version }}"
84+
85+
- name: "Install dependencies"
86+
working-directory: "e2e/ignore"
87+
run: "composer install --no-interaction --no-progress --no-suggest"
88+
89+
- name: "Test"
90+
working-directory: "e2e/ignore"
91+
run: "vendor/bin/phpstan analyse -l 8 IgnoreTest.php"

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ Add `phpstan` key in the extension `composer.json`'s `extra` section:
7272
}
7373
```
7474

75+
## Ignoring a particular extension
76+
77+
You may want to disable auto-installation of a particular extension to handle installation manually. Ignore an extension by adding an `extra.phpstan/extension-installer.ignore` array in `composer.json` that specifies a list of packages to ignore:
78+
79+
```json
80+
{
81+
"extra": {
82+
"phpstan/extension-installer": {
83+
"ignore": [
84+
"phpstan/phpstan-phpunit"
85+
]
86+
}
87+
}
88+
}
89+
```
90+
7591
## Limitations
7692

7793
The extension installer depends on Composer script events, therefore you cannot use `--no-scripts` flag.

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
}
2323
},
2424
"extra": {
25-
"class": "PHPStan\\ExtensionInstaller\\Plugin"
25+
"class": "PHPStan\\ExtensionInstaller\\Plugin",
26+
"phpstan/extension-installer": {
27+
"ignore": ["phpstan/phpstan-phpunit"]
28+
}
2629
},
2730
"autoload": {
2831
"psr-4": {
File renamed without changes.

e2e/ignore/IgnoreTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace App;
4+
5+
class IgnoreTest
6+
{
7+
}

e2e/ignore/composer.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"require": {
3+
"phpstan/phpstan": "^1.8.0",
4+
"phpstan/extension-installer": "1.2.x-dev",
5+
"testing/test-extension": "^1.0"
6+
},
7+
"repositories": [
8+
{
9+
"type": "path",
10+
"url": "../..",
11+
"options": {
12+
"symlink": false
13+
}
14+
},
15+
{
16+
"type": "path",
17+
"url": "../test-extension",
18+
"options": {
19+
"symlink": false
20+
}
21+
}
22+
],
23+
"config": {
24+
"allow-plugins": {
25+
"phpstan/extension-installer": true
26+
}
27+
},
28+
"extra": {
29+
"phpstan/extension-installer": {
30+
"ignore": [
31+
"testing/test-extension"
32+
]
33+
}
34+
}
35+
}

e2e/integration/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor
File renamed without changes.

e2e/composer.json renamed to e2e/integration/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"repositories": [
99
{
1010
"type": "path",
11-
"url": "..",
11+
"url": "../..",
1212
"options": {
1313
"symlink": false
1414
}

e2e/test-extension/composer.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "1.0",
3+
"name": "testing/test-extension",
4+
"extra": {
5+
"phpstan": {
6+
"includes": [
7+
"extension.neon"
8+
]
9+
}
10+
}
11+
}

e2e/test-extension/extension.neon

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
invalidConfig: []

src/Plugin.php

+20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use function ksort;
2020
use function md5;
2121
use function md5_file;
22+
use function sort;
2223
use function sprintf;
2324
use function strpos;
2425
use function var_export;
@@ -97,9 +98,18 @@ public function process(Event $event): void
9798
}
9899
$notInstalledPackages = [];
99100
$installedPackages = [];
101+
$ignoredPackages = [];
100102

101103
$data = [];
102104
$fs = new Filesystem();
105+
$ignore = [];
106+
107+
$packageExtra = $composer->getPackage()->getExtra();
108+
109+
if (isset($packageExtra['phpstan/extension-installer']['ignore'])) {
110+
$ignore = $packageExtra['phpstan/extension-installer']['ignore'];
111+
}
112+
103113
foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
104114
if (
105115
$package->getType() !== 'phpstan-extension'
@@ -119,6 +129,11 @@ public function process(Event $event): void
119129
continue;
120130
}
121131

132+
if (in_array($package->getName(), $ignore, true)) {
133+
$ignoredPackages[] = $package->getName();
134+
continue;
135+
}
136+
122137
$installPath = $installationManager->getInstallPath($package);
123138

124139
$absoluteInstallPath = $fs->isAbsolutePath($installPath)
@@ -138,6 +153,7 @@ public function process(Event $event): void
138153
ksort($data);
139154
ksort($installedPackages);
140155
ksort($notInstalledPackages);
156+
sort($ignoredPackages);
141157

142158
$generatedConfigFileContents = sprintf(self::$generatedFileTemplate, var_export($data, true), var_export($notInstalledPackages, true));
143159
file_put_contents($generatedConfigFilePath, $generatedConfigFileContents);
@@ -154,6 +170,10 @@ public function process(Event $event): void
154170
foreach (array_keys($notInstalledPackages) as $name) {
155171
$io->write(sprintf('> <comment>%s:</comment> not supported', $name));
156172
}
173+
174+
foreach ($ignoredPackages as $name) {
175+
$io->write(sprintf('> <comment>%s:</comment> ignored', $name));
176+
}
157177
}
158178

159179
}

0 commit comments

Comments
 (0)