Skip to content

Commit 488030f

Browse files
committed
Fix fatal error when Composer EventDispatcher called programmatically
This now reverts the second code modernization from 234 as well. Annoying, but so be it. I've also now added warnings in both places which were modernized and for which the modernizations had to be reverted to hopefully prevent this happening again. Fixes 247
1 parent 6e0fa42 commit 488030f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/Plugin.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use Composer\Composer;
1414
use Composer\EventDispatcher\EventSubscriberInterface;
15-
use Composer\InstalledVersions;
1615
use Composer\IO\IOInterface;
1716
use Composer\Package\AliasPackage;
1817
use Composer\Package\PackageInterface;
@@ -551,6 +550,10 @@ private function getPHPCodeSnifferPackage($versionConstraint = null)
551550
/**
552551
* Returns the path to the PHP_CodeSniffer package installation location
553552
*
553+
* {@internal Do NOT try to modernize via the Composer 2.2 API (`InstalledVersions::getInstallPath()`).
554+
* Doing so doesn't play nice with other plugins.
555+
* {@link https://github.com/PHPCSStandards/composer-installer/issues/239}}
556+
*
554557
* @return string
555558
*/
556559
private function getPHPCodeSnifferInstallPath()
@@ -561,16 +564,16 @@ private function getPHPCodeSnifferInstallPath()
561564
/**
562565
* Simple check if PHP_CodeSniffer is installed.
563566
*
567+
* {@internal Do NOT try to modernize via the Composer 2.2 API (`InstalledVersions::isInstalled()`).
568+
* Doing so doesn't play nice with integrations calling the Composer EventDispatcher programmatically.
569+
* {@link https://github.com/PHPCSStandards/composer-installer/issues/247}}
570+
*
564571
* @param null|string|\Composer\Semver\Constraint\ConstraintInterface $versionConstraint to match against
565572
*
566573
* @return bool Whether PHP_CodeSniffer is installed
567574
*/
568575
private function isPHPCodeSnifferInstalled($versionConstraint = null)
569576
{
570-
if ($versionConstraint === null) {
571-
return InstalledVersions::isInstalled(self::PACKAGE_NAME);
572-
}
573-
574577
return ($this->getPHPCodeSnifferPackage($versionConstraint) !== null);
575578
}
576579

0 commit comments

Comments
 (0)