Skip to content

Commit

Permalink
Allow use within PHP_CodeSniffer itself
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Dec 5, 2023
1 parent 3d4fcbd commit 780a608
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ function (PackageInterface $package) {
*/
private function getPHPCodeSnifferPackage($versionConstraint = null)
{
$rootPackage = $this->composer->getPackage();
if ($rootPackage->getName() === self::PACKAGE_NAME) {
return $rootPackage;
}

$packages = $this
->composer
->getRepositoryManager()
Expand All @@ -554,7 +559,12 @@ private function getPHPCodeSnifferPackage($versionConstraint = null)
*/
private function getPHPCodeSnifferInstallPath()
{
return $this->composer->getInstallationManager()->getInstallPath($this->getPHPCodeSnifferPackage());
$package = $this->getPHPCodeSnifferPackage();
if ($package instanceof \Composer\Package\RootPackageInterface) {
return realpath(dirname(\Composer\Factory::getComposerFile()));
}

return $this->composer->getInstallationManager()->getInstallPath($package);
}

/**
Expand Down

0 comments on commit 780a608

Please sign in to comment.