Ignore code by dependency version #10593
-
Hello, I’m working on a plugin that needs to support two major versions of a dependency. When the dependency upgraded from version 4 to 5 additional code is now required in my plugin. I’ve come up with something like this, $section = new Section();
if (version_compare(DEP_VERSION, ‘5.0.0’, ‘>=‘)) {
$section->setEntryTypes($entryTypes);
}
$section->save(); In order for that to function I’m setting the DEP_VERSION constant in my bootstrap based on Functionally this does what I want but PHPStan is getting tripped up saying:
Is there a way to tell PHPstan it’s okay to ignore code not meant for this version? Note: my CI is running PHPstan twice, once for the 4.x branch and once for the 5.x branch. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's a good thing you run PHPStan twice because then you can conditionally ignore different things. PHPStan itself does it for different PHPS versions: https://github.com/phpstan/phpstan-src/blob/1.11.x/build/ignore-by-php-version.neon.php So you can ask Composer through InstalledVersions about the version of the package and include different neon files with different ignores that way. |
Beta Was this translation helpful? Give feedback.
It's a good thing you run PHPStan twice because then you can conditionally ignore different things.
PHPStan itself does it for different PHPS versions: https://github.com/phpstan/phpstan-src/blob/1.11.x/build/ignore-by-php-version.neon.php
So you can ask Composer through InstalledVersions about the version of the package and include different neon files with different ignores that way.