Skip to content

Commit

Permalink
Fix deprecation error message trigger logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mxr576 committed Mar 20, 2024
1 parent 6ec038d commit 833cd73
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Domain/PackageIgnore/PackageIgnoreRuleOptimizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,array<\mxr576\ddqgComposerAudit\Domain\PackageIgnore\PackageIgnoreRule>> $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();
}
}

0 comments on commit 833cd73

Please sign in to comment.