diff --git a/RoboFile.php b/RoboFile.php index 4b67c5d971..a2db8f7d52 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -466,7 +466,7 @@ class RoboFile extends \Robo\Tasks { 'WP_ROOT="' . getenv('WP_ROOT') . '"', 'php -d memory_limit=2G', "$dir/tasks/phpstan/vendor/bin/phpstan analyse ", - '--level 5', + '--level 7', ]); // PHPStan must be run out of main plugin directory to avoid its autoloading diff --git a/tasks/phpstan/phpstan-baseline-tests.neon b/tasks/phpstan/phpstan-baseline-tests.neon new file mode 100644 index 0000000000..44356a8352 --- /dev/null +++ b/tasks/phpstan/phpstan-baseline-tests.neon @@ -0,0 +1,78 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" + count: 1 + path: %mailpoetDir%/tests/DataFactories/Newsletter.php + + - + message: "#^Parameter \\#1 \\$query of method PDO\\:\\:exec\\(\\) expects string, string\\|false given\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/CleanupExtension.php + + - + message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, array\\\\|false given\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/ErrorsExtension.php + + - + message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/ErrorsExtension.php + + - + message: "#^Parameter \\#1 \\$input of function array_slice expects array, array\\\\|false given\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/ErrorsExtension.php + + - + message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|false given\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/Helper/Database.php + + - + message: "#^Parameter \\#1 \\$query of method PDO\\:\\:exec\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/Helper/Database.php + + - + message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, string given\\.$#" + count: 1 + path: %mailpoetDir%/tests/_support/Helper/WordPress.php + + - + message: "#^Parameter \\#2 \\$value of function get_user_by expects int\\|string, int\\|WP_Error given\\.$#" + count: 1 + path: %mailpoetDir%/tests/acceptance/ViewSegmentSubscribersCest.php + + - + message: "#^Cannot access property \\$roles on WP_User\\|false\\.$#" + count: 1 + path: %mailpoetDir%/tests/acceptance/ViewSegmentSubscribersCest.php + + - + message: "#^Cannot call method remove_role\\(\\) on WP_User\\|false\\.$#" + count: 1 + path: %mailpoetDir%/tests/acceptance/ViewSegmentSubscribersCest.php + + - + message: "#^Cannot call method add_role\\(\\) on WP_User\\|false\\.$#" + count: 1 + path: %mailpoetDir%/tests/acceptance/ViewSegmentSubscribersCest.php + + - + message: "#^Property MailPoet\\\\Test\\\\Subscribers\\\\ImportExport\\\\Import\\\\MailChimpTest\\:\\:\\$api_key \\(string\\) does not accept string\\|false\\.$#" + count: 1 + path: %mailpoetDir%/tests/unit/Subscribers/ImportExport/Import/MailChimpTest.php + + - + message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|false given\\.$#" + count: 1 + path: %mailpoetDir%/tests/unit/Subscribers/ImportExport/Import/MailChimpTest.php + + - + message: "#^Property MailPoet\\\\Test\\\\WP\\\\ReadmeTest\\:\\:\\$data \\(string\\) does not accept string\\|false\\.$#" + count: 1 + path: %mailpoetDir%/tests/unit/WP/ReadmeTest.php + + diff --git a/tasks/phpstan/phpstan-baseline.neon b/tasks/phpstan/phpstan-baseline.neon new file mode 100644 index 0000000000..6143e30446 --- /dev/null +++ b/tasks/phpstan/phpstan-baseline.neon @@ -0,0 +1,208 @@ +parameters: + ignoreErrors: + - + message: "#^Offset 'host' does not exist on array\\('port' \\=\\> int, \\?'scheme' \\=\\> string, \\?'host' \\=\\> string, \\?'user' \\=\\> string, \\?'pass' \\=\\> string, \\?'path' \\=\\> string, \\?'query' \\=\\> string, \\?'fragment' \\=\\> string\\)\\.$#" + count: 3 + path: %mailpoetDir%/lib/Cron/CronHelper.php + + - + message: "#^Offset 'scheme' does not exist on array\\('port' \\=\\> int, \\?'scheme' \\=\\> string, \\?'host' \\=\\> string, \\?'user' \\=\\> string, \\?'pass' \\=\\> string, \\?'path' \\=\\> string, \\?'query' \\=\\> string, \\?'fragment' \\=\\> string\\)\\.$#" + count: 2 + path: %mailpoetDir%/lib/Cron/CronHelper.php + + - + message: "#^Parameter \\#1 \\$str of function strtolower expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Cron/CronHelper.php + + - + message: "#^Property MailPoet\\\\Cron\\\\DaemonHttpRunner\\:\\:\\$daemon \\(MailPoet\\\\Cron\\\\Daemon\\) does not accept MailPoet\\\\Cron\\\\Daemon\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/Cron/DaemonHttpRunner.php + + - + message: "#^Cannot call method createNotificationHistory\\(\\) on bool\\|MailPoet\\\\Models\\\\Newsletter\\.$#" + count: 1 + path: %mailpoetDir%/lib/Cron/Workers/Scheduler.php + + - + message: "#^Parameter \\#1 \\$timestamp of static method Carbon\\\\Carbon\\:\\:createFromTimestamp\\(\\) expects int, int\\|string given\\.$#" + count: 2 + path: %mailpoetDir%/lib/Cron/Workers/Scheduler.php + + - + message: "#^Parameter \\#1 \\$newsletter of method MailPoet\\\\Cron\\\\Workers\\\\StatsNotifications\\\\Scheduler\\:\\:schedule\\(\\) expects MailPoet\\\\Entities\\\\NewsletterEntity, MailPoet\\\\Entities\\\\NewsletterEntity\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Cron/Workers/SendingQueue/SendingQueue.php + + - + message: "#^Parameter \\#1 \\$time of function strtotime expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Cron/Workers/SimpleWorker.php + + - + message: "#^Cannot call method getNewsletterRenderedSubject\\(\\) on MailPoet\\\\Entities\\\\SendingQueueEntity\\|null\\.$#" + count: 2 + path: %mailpoetDir%/lib/Cron/Workers/StatsNotifications/Worker.php + + - + message: "#^Cannot call method has\\(\\) on MailPoetVendor\\\\Psr\\\\Container\\\\ContainerInterface\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/DI/ContainerConfigurator.php + + - + message: "#^Cannot call method get\\(\\) on MailPoetVendor\\\\Psr\\\\Container\\\\ContainerInterface\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/DI/ContainerConfigurator.php + + - + message: "#^Cannot call method contains\\(\\) on MailPoetVendor\\\\Doctrine\\\\Common\\\\Cache\\\\Cache\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/Doctrine/TablePrefixMetadataFactory.php + + - + message: "#^Property MailPoet\\\\DynamicSegments\\\\Filters\\\\EmailAction\\:\\:\\$connect \\(string\\) does not accept string\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/DynamicSegments/Filters/EmailAction.php + + - + message: "#^Property MailPoet\\\\DynamicSegments\\\\Filters\\\\UserRole\\:\\:\\$connect \\(string\\) does not accept string\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/DynamicSegments/Filters/UserRole.php + + - + message: "#^Property MailPoet\\\\DynamicSegments\\\\Filters\\\\WooCommerceCategory\\:\\:\\$connect \\(string\\) does not accept string\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/DynamicSegments/Filters/WooCommerceCategory.php + + - + message: "#^Property MailPoet\\\\DynamicSegments\\\\Filters\\\\WooCommerceProduct\\:\\:\\$connect \\(string\\) does not accept string\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/DynamicSegments/Filters/WooCommerceProduct.php + + - + message: "#^Parameter \\#1 \\$segment_id of method MailPoet\\\\DynamicSegments\\\\Persistence\\\\Loading\\\\SingleSegmentLoader\\:\\:load\\(\\) expects int\\|string, string\\|null given\\.$#" + count: 2 + path: %mailpoetDir%/lib/DynamicSegments/FreePluginConnectors/SendingNewslettersSubscribersFinder.php + + - + message: "#^Parameter \\#2 \\$code of class MailPoet\\\\DynamicSegments\\\\Exceptions\\\\ErrorSavingException constructor expects int, int\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/DynamicSegments/Persistence/Saver.php + + - + message: "#^Parameter \\#1 \\$data of function is_serialized expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Entities/SettingEntity.php + + - + message: "#^Parameter \\#1 \\$variable_representation of function unserialize expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Entities/SettingEntity.php + + - + message: "#^Parameter \\#1 \\$variable_representation of function unserialize expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/CustomField.php + + - + message: "#^Parameter \\#1 \\$variable_representation of function unserialize expects string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/DynamicSegmentFilter.php + + - + message: "#^Parameter \\#1 \\$variable_representation of function unserialize expects string, array\\|string given\\.$#" + count: 2 + path: %mailpoetDir%/lib/Models/Form.php + + - + message: "#^Parameter \\#1 \\$data of function is_serialized expects string, array\\|string given\\.$#" + count: 2 + path: %mailpoetDir%/lib/Models/Form.php + + - + message: "#^Parameter \\#2 \\$value of method MailPoet\\\\Models\\\\Model\\:\\:set\\(\\) expects string\\|null, array\\|string given\\.$#" + count: 2 + path: %mailpoetDir%/lib/Models/Form.php + + - + message: "#^Argument of an invalid type array\\|true supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/Model.php + + - + message: "#^Cannot call method set\\(\\) on static\\(MailPoet\\\\Models\\\\Model\\)\\|true\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/Model.php + + - + message: "#^Cannot call method save\\(\\) on static\\(MailPoet\\\\Models\\\\Model\\)\\|true\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/Model.php + + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, object\\|string given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/Newsletter.php + + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, array\\|string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/ScheduledTask.php + + - + message: "#^Parameter \\#1 \\$value of method Carbon\\\\Carbon\\:\\:addMinutes\\(\\) expects int, float\\|int given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/ScheduledTask.php + + - + message: "#^Method MailPoet\\\\Models\\\\ScheduledTask\\:\\:findOneScheduledByNewsletterIdAndSubscriberId\\(\\) should return MailPoet\\\\Models\\\\ScheduledTask\\|null but returns MailPoet\\\\Models\\\\ScheduledTask\\|true\\|null\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/ScheduledTask.php + + - + message: "#^Cannot call method asArray\\(\\) on bool\\|MailPoet\\\\Models\\\\SubscriberSegment\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/Segment.php + + - + message: "#^Parameter \\#1 \\$data of function is_serialized expects string, array\\|string given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/SendingQueue.php + + - + message: "#^Parameter \\#1 \\$variable_representation of function unserialize expects string, array\\|string given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/SendingQueue.php + + - + message: "#^Parameter \\#1 \\$json of function json_decode expects string, object\\|string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Models/SendingQueue.php + + - + message: "#^Parameter \\#1 \\$str of function strip_tags expects string, array\\|string given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Newsletter/Editor/PostContentManager.php + + - + message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Newsletter/Links/Links.php + + - + message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|null given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Newsletter/Links/Links.php + + - + message: "#^Parameter \\#2 \\$function_to_add of method MailPoet\\\\WP\\\\Functions\\:\\:addAction\\(\\) expects callable\\(\\)\\: mixed, array\\(string, 'ensureConsistentQue…'\\) given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Newsletter/Shortcodes/Categories/Newsletter.php + + - + message: "#^Parameter \\#2 \\$function_to_remove of method MailPoet\\\\WP\\\\Functions\\:\\:removeAction\\(\\) expects callable\\(\\)\\: mixed, array\\(string, 'ensureConsistentQue…'\\) given\\.$#" + count: 1 + path: %mailpoetDir%/lib/Newsletter/Shortcodes/Categories/Newsletter.php + + diff --git a/tasks/phpstan/phpstan-tests.neon b/tasks/phpstan/phpstan-tests.neon index 1e4f55ade0..522da98369 100644 --- a/tasks/phpstan/phpstan-tests.neon +++ b/tasks/phpstan/phpstan-tests.neon @@ -23,3 +23,5 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - extensions/PHPUnit5CompatExtension/extension.neon - extensions/CodeceptionExtension/extension.neon + - phpstan-baseline-tests.neon # https://medium.com/@ondrejmirtes/phpstans-baseline-feature-lets-you-hold-new-code-to-a-higher-standard-e77d815a5dff + diff --git a/tasks/phpstan/phpstan.neon b/tasks/phpstan/phpstan.neon index be053b66aa..52fd292684 100644 --- a/tasks/phpstan/phpstan.neon +++ b/tasks/phpstan/phpstan.neon @@ -16,3 +16,5 @@ parameters: reportUnmatchedIgnoredErrors: false dynamicConstantNames: - WP_DEBUG +includes: + - phpstan-baseline.neon # https://medium.com/@ondrejmirtes/phpstans-baseline-feature-lets-you-hold-new-code-to-a-higher-standard-e77d815a5dff