From 833cd73742688dbb6adc89245555c56cac56aae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= Date: Wed, 20 Mar 2024 22:12:13 +0100 Subject: [PATCH] Fix deprecation error message trigger logic --- .../PackageIgnoreRuleOptimizer.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Domain/PackageIgnore/PackageIgnoreRuleOptimizer.php b/src/Domain/PackageIgnore/PackageIgnoreRuleOptimizer.php index 92f0472..9cf2256 100644 --- a/src/Domain/PackageIgnore/PackageIgnoreRuleOptimizer.php +++ b/src/Domain/PackageIgnore/PackageIgnoreRuleOptimizer.php @@ -27,17 +27,26 @@ final protected function optimizePackageIgnoreRules(PackageIgnoreRuleProvider $p $rules = $provider->getIgnoreRules(); /** @var \mxr576\ddqgComposerAudit\Domain\PackageIgnore\PackageIgnoreRule[] $rules */ $rules = $rules instanceof \Traversable ? iterator_to_array($rules, false) : $rules; - if ([] !== $rules) { - trigger_error("Since 1.1.0 DDQG Composer Audit plugin's ignore features are deprecated, use Composer's built-in audit ignore feature instead. https://getcomposer.org/doc/06-config.md#ignore", E_USER_DEPRECATED); - } + $ignore_package_by_installed_version_of_other_package_counter = 0; /** @var \ArrayObject> $tmp */ $tmp = array_reduce($rules, - static function (\ArrayObject $carry, PackageIgnoreRule $item) { + static function (\ArrayObject $carry, PackageIgnoreRule $item) use (&$ignore_package_by_installed_version_of_other_package_counter) { + // This type of ignore rule can be only created programmatically at + // this moment, so we can assume it was added by the package + // maintainer(s). + if ($item instanceof IgnorePackageByInstalledVersionOfOtherPackage) { + ++$ignore_package_by_installed_version_of_other_package_counter; + } + $carry[$item->getPackageName()][] = $item; return $carry; }, new \ArrayObject()); + if (count($tmp) !== $ignore_package_by_installed_version_of_other_package_counter) { + trigger_error("Since 1.1.0 DDQG Composer Audit plugin's ignore features are deprecated, use Composer's built-in audit ignore feature instead. https://getcomposer.org/doc/06-config.md#ignore", E_USER_DEPRECATED); + } + return $tmp->getArrayCopy(); } }