Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install phpstan extension also for root package #39

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"php": "^7.2 || ^8.0",
"composer-plugin-api": "^2.0",
"phpstan/phpstan": ">=0.11.6"
"phpstan/phpstan": ">=0.12.19"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to support infile @phpstan-ignore-line

},
"require-dev": {
"composer/composer": "^2.0",
Expand Down
8 changes: 8 additions & 0 deletions e2e/FooTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ private function requireStd(\stdClass $std): void

}

/**
* @return string
*/
protected function testRootPackageConfigInstall()
{
return 10;
}

}
9 changes: 8 additions & 1 deletion e2e/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
"symlink": false
}
}
]
],
"extra": {
"phpstan": {
"includes": [
"phpstan-ext.neon"
]
}
}
}
6 changes: 6 additions & 0 deletions e2e/phpstan-ext.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
path: FooTest.php
message: '~^Method App\\FooTest::testRootPackageConfigInstall\(\) should return string but returns int\.$~'
count: 1
15 changes: 12 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Composer\Script\ScriptEvents;
use Composer\Util\Filesystem;
use function array_keys;
use function array_merge;
use function dirname;
use function file_exists;
use function file_put_contents;
Expand Down Expand Up @@ -96,9 +97,12 @@ public function process(Event $event): void
$notInstalledPackages = [];
$installedPackages = [];

$rootPackage = $composer->getPAckage(); // @phpstan-ignore-line getpackage() for Composer v1, getPackage() for Composer v2
$dependencyPackages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();

$data = [];
$fs = new Filesystem();
foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
foreach (array_merge([$rootPackage], $dependencyPackages) as $package) {
if (
$package->getType() !== 'phpstan-extension'
&& !isset($package->getExtra()['phpstan'])
Expand All @@ -116,8 +120,13 @@ public function process(Event $event): void
}
continue;
}
$absoluteInstallPath = $installationManager->getInstallPath($package);
$data[$package->getName()] = [

$isRootPackage = $package === $rootPackage;
$packageName = $isRootPackage ? 'root (' . $package->getName() . ')' : $package->getName();
$absoluteInstallPath = $isRootPackage
? dirname($composer->getConfig()->getConfigSource()->getName())
: $installationManager->getInstallPath($package);
$data[$packageName] = [
'install_path' => $absoluteInstallPath,
'relative_install_path' => $fs->findShortestPath(dirname($generatedConfigFilePath), $absoluteInstallPath, true),
'extra' => $package->getExtra()['phpstan'] ?? null,
Expand Down