KK
kkarpieszuk/phpstan-wpforms-rules
PHPStan rules to satisfy WPForms code performance and bugs-avoiding standards
PHPStan Array Merge Rules
This package provides PHPStan rules to satisfy code quality standards for WPForms plugins.
Installation
You can install the package via composer:
composer require --dev kkarpieszuk/phpstan-wpforms-rulesYou cna also install it directly from GitHub:
composer require --dev kkarpieszuk/phpstan-wpforms-rules:mainUsage
The rules will be automatically registered if you include the package in your PHPStan configuration:
includes:
- vendor/kkarpieszuk/phpstan-wpforms-rules/rules.neonRules
DisallowArrayMergeInLoopsRule
This rule prevents the use of array_merge inside foreach and for loops. Using array_merge in loops can lead to performance issues due to repeated array copying.
Example of code that will trigger an error:
$result = [];
foreach ($arrays as $array) {
$result = array_merge($result, $array); // ERROR: Do not use array_merge inside foreach or for loops.
}Alternative solution:
$result = array_merge(...$arrays);License
The MIT License (MIT).