diff --git a/src/Plugin.php b/src/Plugin.php index a2863d6c..d985a97b 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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() @@ -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); } /**