From 12e9733820a5226b4461271984ce490755bece0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 29 Nov 2024 14:12:47 +0700 Subject: [PATCH 1/7] Refactor Update Option rule --- .../Rules/DiscourageUpdateOptionUsage.php | 34 --------------- .../phpstan/Rules/DiscourageWPOptionUsage.php | 42 +++++++++++++++++++ 2 files changed, 42 insertions(+), 34 deletions(-) delete mode 100644 tests/phpstan/Rules/DiscourageUpdateOptionUsage.php create mode 100644 tests/phpstan/Rules/DiscourageWPOptionUsage.php diff --git a/tests/phpstan/Rules/DiscourageUpdateOptionUsage.php b/tests/phpstan/Rules/DiscourageUpdateOptionUsage.php deleted file mode 100644 index d9050debc0..0000000000 --- a/tests/phpstan/Rules/DiscourageUpdateOptionUsage.php +++ /dev/null @@ -1,34 +0,0 @@ -name instanceof Node\Name && $node->name->toString() === 'update_option' ) { - return [ - RuleErrorBuilder::message( 'Usage of update_option() is discouraged. Use the Option object instead.' ) - ->identifier( 'custom.rules.discourageApplyFilters' ) - ->build(), - ]; - } - - return []; - } -} diff --git a/tests/phpstan/Rules/DiscourageWPOptionUsage.php b/tests/phpstan/Rules/DiscourageWPOptionUsage.php new file mode 100644 index 0000000000..aadc0d5576 --- /dev/null +++ b/tests/phpstan/Rules/DiscourageWPOptionUsage.php @@ -0,0 +1,42 @@ +name instanceof Node\Name ? $node->name->toString() : ''; + + $discouragedFunctions = [ + 'update_option' => 'Usage of update_option() is discouraged. Use the Option object instead.', + 'get_option' => 'Usage of get_option() is discouraged. Use the Option object instead.', + 'delete_option' => 'Usage of delete_option() is discouraged. Use the Option object instead.', + ]; + + if (isset($discouragedFunctions[$functionName])) { + return [ + RuleErrorBuilder::message($discouragedFunctions[$functionName]) + ->identifier('custom.rules.discourageOptionUsage') + ->build(), + ]; + } + + return []; + } +} From 20b724bd36fd026ba17cdc443e4605f63ce31ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 29 Nov 2024 14:13:20 +0700 Subject: [PATCH 2/7] Update tests --- phpstan.neon.dist | 2 +- .../Rules/DiscourageUpdateOptionUsageTest.php | 28 ----------- .../Rules/DiscourageWPOptionUsageTest.php | 46 +++++++++++++++++++ .../not-valid.php | 45 ------------------ .../use-delete-option.php | 21 +++++++++ .../use-get-option.php | 21 +++++++++ .../use-update-option.php | 22 +++++++++ .../valid.php | 0 8 files changed, 111 insertions(+), 74 deletions(-) delete mode 100644 tests/phpstan/tests/Rules/DiscourageUpdateOptionUsageTest.php create mode 100644 tests/phpstan/tests/Rules/DiscourageWPOptionUsageTest.php delete mode 100644 tests/phpstan/tests/data/DiscourageUpdateOptionUsageTest/not-valid.php create mode 100644 tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-delete-option.php create mode 100644 tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-get-option.php create mode 100644 tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-update-option.php rename tests/phpstan/tests/data/{DiscourageUpdateOptionUsageTest => DiscourageWPOptionUsageTest}/valid.php (100%) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7d2c7a5a48..9b33f10fba 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -55,7 +55,7 @@ parameters: - %currentWorkingDirectory%/inc/classes/subscriber/third-party/ - %currentWorkingDirectory%/inc/3rd-party/ rules: - - WP_Rocket\Tests\phpstan\Rules\DiscourageUpdateOptionUsage + - WP_Rocket\Tests\phpstan\Rules\DiscourageWPOptionUsage - WP_Rocket\Tests\phpstan\Rules\DiscourageApplyFilters - WP_Rocket\Tests\phpstan\Rules\EnsureCallbackMethodsExistsInSubscribedEvents - WP_Rocket\Tests\phpstan\Rules\NoHooksInORM diff --git a/tests/phpstan/tests/Rules/DiscourageUpdateOptionUsageTest.php b/tests/phpstan/tests/Rules/DiscourageUpdateOptionUsageTest.php deleted file mode 100644 index 3ec1fa2425..0000000000 --- a/tests/phpstan/tests/Rules/DiscourageUpdateOptionUsageTest.php +++ /dev/null @@ -1,28 +0,0 @@ -analyse([__DIR__ . '/../data/DiscourageUpdateOptionUsageTest/valid.php'], [ - ]); - } - - public function testShouldGetError() { - $this->analyse([__DIR__ . '/../data/DiscourageUpdateOptionUsageTest/not-valid.php'], [ - [ - "Usage of update_option() is discouraged. Use the Option object instead.", - 38 - ] - ]); - } -} diff --git a/tests/phpstan/tests/Rules/DiscourageWPOptionUsageTest.php b/tests/phpstan/tests/Rules/DiscourageWPOptionUsageTest.php new file mode 100644 index 0000000000..c9e205679f --- /dev/null +++ b/tests/phpstan/tests/Rules/DiscourageWPOptionUsageTest.php @@ -0,0 +1,46 @@ +analyse([__DIR__ . '/../data/DiscourageWPOptionUsageTest/valid.php'], [ + ]); + } + + public function testShouldHaveErrorWithDeleteOption() { + $this->analyse([__DIR__ . '/../data/DiscourageWPOptionUsageTest/use-delete-option.php'], [ + [ + "Usage of delete_option() is discouraged. Use the Option object instead.", + 19 + ] + ]); + } + + public function testShouldHaveErrorWithGetOption() { + $this->analyse([__DIR__ . '/../data/DiscourageWPOptionUsageTest/use-get-option.php'], [ + [ + "Usage of get_option() is discouraged. Use the Option object instead.", + 19 + ] + ]); + } + + public function testShouldHaveErrorWithUpdateOption() { + $this->analyse([__DIR__ . '/../data/DiscourageWPOptionUsageTest/use-update-option.php'], [ + [ + "Usage of update_option() is discouraged. Use the Option object instead.", + 19 + ] + ]); + } +} diff --git a/tests/phpstan/tests/data/DiscourageUpdateOptionUsageTest/not-valid.php b/tests/phpstan/tests/data/DiscourageUpdateOptionUsageTest/not-valid.php deleted file mode 100644 index 61561563ee..0000000000 --- a/tests/phpstan/tests/data/DiscourageUpdateOptionUsageTest/not-valid.php +++ /dev/null @@ -1,45 +0,0 @@ - 'return_false', - 'action_scheduler_extra_action_counts' => [ - ['hide_pastdue_status_filter'], - ['hide_pastdue_status_filter', 10, 3], - ], - ]; - } - - /** - * Hide past-due from status filter in Action Scheduler tools page. - * - * @param array $extra_actions Array with format action_count_identifier => action count. - * - * @return array - */ - public function hide_pastdue_status_filter( array $extra_actions ) { - if ( ! isset( $extra_actions['past-due'] ) ) { - return $extra_actions; - } - update_option( 'test_option', $extra_actions['past-due'] ); - - unset( $extra_actions['past-due'] ); - - - return $extra_actions; - } -} diff --git a/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-delete-option.php b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-delete-option.php new file mode 100644 index 0000000000..570e08c0ad --- /dev/null +++ b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-delete-option.php @@ -0,0 +1,21 @@ + 'callback', + ]; + } + + public function callback() { + return delete_option('test_option' ); + } +} diff --git a/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-get-option.php b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-get-option.php new file mode 100644 index 0000000000..96c405cce6 --- /dev/null +++ b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-get-option.php @@ -0,0 +1,21 @@ + 'callback', + ]; + } + + public function callback() { + return get_option('test_option', false ); + } +} diff --git a/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-update-option.php b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-update-option.php new file mode 100644 index 0000000000..36448603db --- /dev/null +++ b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/use-update-option.php @@ -0,0 +1,22 @@ + 'callback', + ]; + } + + public function callback() { + update_option('test_option', false ); + return true; + } +} diff --git a/tests/phpstan/tests/data/DiscourageUpdateOptionUsageTest/valid.php b/tests/phpstan/tests/data/DiscourageWPOptionUsageTest/valid.php similarity index 100% rename from tests/phpstan/tests/data/DiscourageUpdateOptionUsageTest/valid.php rename to tests/phpstan/tests/data/DiscourageWPOptionUsageTest/valid.php From cd63845d804d1ec1e922dba615773a7a93c08364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Robin?= Date: Fri, 29 Nov 2024 14:21:42 +0700 Subject: [PATCH 3/7] Update baseline --- phpstan-baseline.neon | 475 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 475 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fcc843b472..5a77ceeecf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -40,6 +40,16 @@ parameters: count: 1 path: inc/Engine/Admin/Deactivation/DeactivationIntent.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Admin/Deactivation/DeactivationIntent.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 4 + path: inc/Engine/Admin/DomainChange/Subscriber.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 @@ -55,6 +65,11 @@ parameters: count: 12 path: inc/Engine/Admin/Settings/Page.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/Engine/Admin/Settings/Page.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 @@ -80,16 +95,41 @@ parameters: count: 6 path: inc/Engine/CDN/CDN.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 3 + path: inc/Engine/CDN/RocketCDN/APIClient.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: inc/Engine/CDN/RocketCDN/AdminPageSubscriber.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/CDN/RocketCDN/AdminPageSubscriber.php + + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/CDN/RocketCDN/CDNOptionsManager.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 3 + path: inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/Engine/CDN/RocketCDN/DataManagerSubscriber.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 3 @@ -100,6 +140,11 @@ parameters: count: 2 path: inc/Engine/CDN/RocketCDN/NoticesSubscriber.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/Engine/CDN/RocketCDN/NoticesSubscriber.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -125,6 +170,11 @@ parameters: count: 1 path: inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Cache/PurgeExpired/PurgeExpiredCache.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -145,6 +195,11 @@ parameters: count: 1 path: inc/Engine/Common/Clock/WPRClock.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Common/Database/Tables/AbstractTable.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -160,6 +215,11 @@ parameters: count: 1 path: inc/Engine/Common/JobManager/APIHandler/APIClient.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Common/PerformanceHints/Database/Table/AbstractTable.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 2 @@ -180,6 +240,11 @@ parameters: count: 1 path: inc/Engine/CriticalPath/Admin/Admin.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/CriticalPath/Admin/Settings.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 @@ -190,11 +255,21 @@ parameters: count: 5 path: inc/Engine/CriticalPath/CriticalCSS.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 4 + path: inc/Engine/CriticalPath/CriticalCSS.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 2 path: inc/Engine/CriticalPath/CriticalCSSSubscriber.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/Engine/CriticalPath/CriticalCSSSubscriber.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 5 @@ -210,11 +285,21 @@ parameters: count: 1 path: inc/Engine/Heartbeat/HeartbeatSubscriber.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/License/Renewal.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 3 path: inc/Engine/Media/AboveTheFold/AJAX/Controller.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Media/AboveTheFold/Context/Context.php + - message: "#^Hooks should not be used in ORM classes\\: WP_Rocket\\\\Engine\\\\Media\\\\AboveTheFold\\\\Database\\\\Queries\\\\AboveTheFold\\:\\:apply_filters$#" count: 1 @@ -285,6 +370,11 @@ parameters: count: 3 path: inc/Engine/Optimization/DeferJS/DeferJS.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Optimization/DeferJS/DeferJS.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -295,6 +385,11 @@ parameters: count: 1 path: inc/Engine/Optimization/DelayJS/Admin/SiteList.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/Engine/Optimization/DelayJS/Admin/SiteList.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -320,6 +415,11 @@ parameters: count: 1 path: inc/Engine/Optimization/LazyRenderContent/AJAX/Controller.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Optimization/LazyRenderContent/Context/Context.php + - message: "#^Hooks should not be used in ORM classes\\: WP_Rocket\\\\Engine\\\\Optimization\\\\LazyRenderContent\\\\Database\\\\Queries\\\\LazyRenderContent\\:\\:apply_filters$#" count: 1 @@ -365,11 +465,26 @@ parameters: count: 1 path: inc/Engine/Optimization/Minify/JS/Subscriber.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Optimization/RUCSS/Admin/Database.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/Engine/Optimization/RUCSS/Admin/Settings.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 path: inc/Engine/Optimization/RUCSS/Admin/Settings.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Optimization/RUCSS/Admin/Subscriber.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 2 @@ -410,6 +525,11 @@ parameters: count: 5 path: inc/Engine/Preload/Controller/LoadInitialSitemap.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Preload/Controller/LoadInitialSitemap.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 8 @@ -430,6 +550,11 @@ parameters: count: 4 path: inc/Engine/Preload/Database/Queries/Cache.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Preload/Database/Tables/Cache.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 2 @@ -445,41 +570,126 @@ parameters: count: 2 path: inc/Engine/Preload/Subscriber.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Preload/Subscriber.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/Engine/Saas/Admin/Notices.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: inc/ThirdParty/Hostings/Godaddy.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/ThirdParty/Hostings/OneCom.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Hostings/ProIsp.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/Ads/Adthrive.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: inc/ThirdParty/Plugins/Ads/Adthrive.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 5 + path: inc/ThirdParty/Plugins/CDN/Cloudflare.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: inc/ThirdParty/Plugins/ContactForm7.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 13 + path: inc/ThirdParty/Plugins/Ecommerce/BigCommerce.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 3 path: inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 3 + path: inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/I18n/WPML.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: inc/ThirdParty/Plugins/ModPagespeed.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/ThirdParty/Plugins/Optimization/AMP.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 5 + path: inc/ThirdParty/Plugins/Optimization/Autoptimize.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/Optimization/Perfmatters.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/Optimization/RapidLoad.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/Optimization/WPMeteor.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: inc/ThirdParty/Plugins/Optimization/WPMeteor.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/PageBuilder/Elementor.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 2 path: inc/ThirdParty/Plugins/SEO/AllInOneSEOPack.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/SEO/AllInOneSEOPack.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/ThirdParty/Plugins/SEO/Yoast.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -490,16 +700,41 @@ parameters: count: 6 path: inc/ThirdParty/Plugins/SimpleCustomCss.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/SimpleCustomCss.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: inc/ThirdParty/Plugins/ThirstyAffiliates.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: inc/ThirdParty/Plugins/WPGeotargeting.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/WPGeotargeting.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/WPGeotargeting.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: inc/ThirdParty/Plugins/WPGeotargeting.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Themes/Avada.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -600,6 +835,11 @@ parameters: count: 1 path: tests/Integration/inc/Addon/Cloudflare/Subscriber/addCdnHelperMessage.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Addon/Cloudflare/Subscriber/deactivateDevMode.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -640,11 +880,26 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Admin/Deactivation/DeactivationIntent/activateSafeMode.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Admin/Deactivation/DeactivationIntent/activateSafeMode.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: tests/Integration/inc/Engine/Admin/Deactivation/Subscriber/addDataAttribute.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Admin/Deactivation/Subscriber/addModalAssets.php + + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Admin/Deactivation/Subscriber/insertDeactivationIntentForm.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -660,11 +915,21 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Admin/Settings/Subscriber/asyncWistiaScript.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/Admin/Settings/Subscriber/enableMobileCache.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: tests/Integration/inc/Engine/Admin/Settings/Subscriber/enableMobileCache.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/Admin/Settings/Subscriber/enableSeparateCacheFilesMobile.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -680,26 +945,56 @@ parameters: count: 1 path: tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/preserveAuthorizationToken.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/preserveAuthorizationToken.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: tests/Integration/inc/Engine/CDN/RocketCDN/AdminPageSubscriber/rocketcdnField.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CDN/RocketCDN/CDNOptionsManager/TestCase.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/CDN/RocketCDN/CDNOptionsManager/TestCase.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: tests/Integration/inc/Engine/CDN/RocketCDN/CDNOptionsManager/TestCase.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CDN/RocketCDN/CDNOptionsManager/disable.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: tests/Integration/inc/Engine/CDN/RocketCDN/NoticesSubscriber/displayRocketcdnCta.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CDN/RocketCDN/RESTSubscriber/disable.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: tests/Integration/inc/Engine/CDN/RocketCDN/RESTSubscriber/disable.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CDN/RocketCDN/RESTSubscriber/enable.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -760,6 +1055,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Cache/Config/ConfigSubscriber/changeCacheRejectUriWithPermalink.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Cache/PurgeActionsSubscriber/purgeCacheOnPublicSettingChange.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 @@ -775,6 +1075,11 @@ parameters: count: 2 path: tests/Integration/inc/Engine/Cache/PurgeExpired/Subscriber/scheduleEvent.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/Cache/PurgeExpired/Subscriber/updateLifespanOptionOnUpdate.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -835,6 +1140,16 @@ parameters: count: 1 path: tests/Integration/inc/Engine/CriticalPath/Admin/Subscriber/addHiddenAsyncCssMobile.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/CriticalPath/Admin/Subscriber/enableMobileCpcss.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CriticalPath/Admin/Subscriber/setAsyncCssMobileDefaultValue.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -845,6 +1160,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/CriticalPath/CriticalCSS/getCriticalCssContent.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CriticalPath/CriticalCSS/getCriticalCssContent.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -855,6 +1175,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/CriticalPath/CriticalCSS/getCurrentPageCriticalCss.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/deleteCpcss.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -875,6 +1200,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/insertCriticalCssBuffer.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/insertCriticalCssBuffer.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 @@ -890,6 +1220,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/stopCpcssProcess.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/CriticalPath/CriticalCSSSubscriber/stopCpcssProcess.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1045,6 +1380,16 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/DeferJS/AdminSubscriber/addDeferJsOption.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/DeferJS/AdminSubscriber/excludeJqueryDefer.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/Optimization/DeferJS/AdminSubscriber/excludeJqueryDefer.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1055,6 +1400,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/DeferJS/Subscriber/deferInlineJs.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/DeferJS/Subscriber/deferInlineJs.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1065,6 +1415,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/DeferJS/Subscriber/deferJs.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/DeferJS/Subscriber/deferJs.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1075,6 +1430,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/DeferJS/Subscriber/excludeJqueryCombine.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/DeferJS/Subscriber/excludeJqueryCombine.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1095,6 +1455,11 @@ parameters: count: 2 path: tests/Integration/inc/Engine/Optimization/DelayJS/Admin/Subscriber/sanitizeOptions.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/DelayJS/Admin/Subscriber/setOptionOnUpdate.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1105,6 +1470,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/DelayJS/Subscriber/delayJs.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/DelayJS/Subscriber/delayJs.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1160,6 +1530,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/DynamicLists/Subscriber/updateLists.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/Optimization/GoogleFonts/Admin/Subscriber/enableGoogleFonts.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1190,6 +1565,11 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/LazyRenderContent/Frontend/Subscriber/add_hashes_when_allowed.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/Minify/CSS/AdminSubscriber/regenerateMinifyCssKey.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1250,16 +1630,36 @@ parameters: count: 1 path: tests/Integration/inc/Engine/Optimization/RUCSS/Admin/Subscriber/truncateUsedCss.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/RUCSS/Admin/Subscriber/updateSafelistItems.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 path: tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/maybeDisablePreloadFonts.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/maybeDisablePreloadFonts.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 path: tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/maybeDisablePreloadFonts.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/onUpdate.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/Engine/Optimization/RUCSS/Frontend/Subscriber/onUpdate.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1290,6 +1690,16 @@ parameters: count: 1 path: tests/Integration/inc/Engine/WPRocketUninstall/uninstall.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/WPRocketUninstall/uninstall.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/Engine/WPRocketUninstall/uninstall.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1410,6 +1820,11 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Hostings/WPXCloud/varnishIP.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Ads/Adthrive/addDelayJsExclusion.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1465,6 +1880,16 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/Jetpack/addJetpackSitemap.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Optimization/AMP/disableOptionsOnAmp.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Optimization/AMP/disableOptionsOnAmp.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1475,6 +1900,16 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Optimization/AMP/isAmpCompatibleCallback.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 3 @@ -1495,6 +1930,11 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/Optimization/Ezoic/addExplanations.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Optimization/Hummingbird/warningNotice.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1515,6 +1955,11 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/Optimization/RocketLazyLoad/excludeRocketLazyLoadScript.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/Optimization/WPMeteor/disableDelayJs.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1540,6 +1985,11 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/PageBuilder/Elementor/addFixAnimationsScript.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/PageBuilder/Elementor/clearCache.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1550,6 +2000,11 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/PageBuilder/Elementor/excludePostCss.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Plugins/PageBuilder/Elementor/excludePostCss.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1585,6 +2040,11 @@ parameters: count: 1 path: tests/Integration/inc/ThirdParty/Plugins/Smush/SmushSubscriberTestCase.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/ThirdParty/Plugins/Smush/maybeDeactivateRocketLazyload.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 1 @@ -1630,6 +2090,11 @@ parameters: count: 2 path: tests/Integration/inc/ThirdParty/Themes/Bridge/maybeClearCache.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: tests/Integration/inc/ThirdParty/Themes/Bridge/maybeClearCache.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -1700,6 +2165,16 @@ parameters: count: 1 path: tests/Integration/inc/admin/rocketAfterSaveOptions.php + - + message: "#^Usage of delete_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 2 + path: tests/Integration/inc/admin/rocketFirstInstall.php + + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 3 + path: tests/Integration/inc/admin/rocketFirstInstall.php + - message: "#^Usage of update_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 2 From 242486361f1a1693fb148986431502bd17d9540f Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 8 Jan 2025 14:53:13 +0200 Subject: [PATCH 4/7] simplify the message generation --- tests/phpstan/Rules/DiscourageWPOptionUsage.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpstan/Rules/DiscourageWPOptionUsage.php b/tests/phpstan/Rules/DiscourageWPOptionUsage.php index aadc0d5576..9d020c2ae8 100644 --- a/tests/phpstan/Rules/DiscourageWPOptionUsage.php +++ b/tests/phpstan/Rules/DiscourageWPOptionUsage.php @@ -24,14 +24,14 @@ public function processNode( Node $node, Scope $scope ): array $functionName = $node->name instanceof Node\Name ? $node->name->toString() : ''; $discouragedFunctions = [ - 'update_option' => 'Usage of update_option() is discouraged. Use the Option object instead.', - 'get_option' => 'Usage of get_option() is discouraged. Use the Option object instead.', - 'delete_option' => 'Usage of delete_option() is discouraged. Use the Option object instead.', + 'update_option' => true, + 'get_option' => true, + 'delete_option' => true, ]; if (isset($discouragedFunctions[$functionName])) { return [ - RuleErrorBuilder::message($discouragedFunctions[$functionName]) + RuleErrorBuilder::message( sprintf( 'Usage of %1$s() is discouraged. Use the Option object instead.', $functionName ) ) ->identifier('custom.rules.discourageOptionUsage') ->build(), ]; From a62afff674371d2a7e46c3be278cf59dd3280950 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 8 Jan 2025 16:13:19 +0200 Subject: [PATCH 5/7] try changing the command to show the whole details about the error --- .github/workflows/lint_phpstan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_phpstan.yml b/.github/workflows/lint_phpstan.yml index 73bf07c680..16b4ac40ed 100644 --- a/.github/workflows/lint_phpstan.yml +++ b/.github/workflows/lint_phpstan.yml @@ -35,5 +35,5 @@ jobs: run: composer install --prefer-dist --no-interaction --no-scripts - name: Lint with PHP Stan - run: composer run-stan -- --error-format=github + run: composer run-stan From 991ae9c31ef09f38e007018d8cd758e5ba7df802 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Wed, 8 Jan 2025 16:29:28 +0200 Subject: [PATCH 6/7] update the baseline after merging develop --- .github/workflows/lint_phpstan.yml | 2 +- phpstan-baseline.neon | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/lint_phpstan.yml b/.github/workflows/lint_phpstan.yml index 790e90fb01..f9dd138bb2 100644 --- a/.github/workflows/lint_phpstan.yml +++ b/.github/workflows/lint_phpstan.yml @@ -36,5 +36,5 @@ jobs: run: composer install --prefer-dist --no-interaction --no-scripts - name: Lint with PHP Stan - run: composer run-stan + run: composer run-stan -- --error-format=github diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5a77ceeecf..6e027d3e20 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -395,11 +395,6 @@ parameters: count: 1 path: inc/Engine/Optimization/DelayJS/Admin/SiteList.php - - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 1 - path: inc/Engine/Optimization/DelayJS/HTML.php - - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 1 @@ -487,7 +482,7 @@ parameters: - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" - count: 2 + count: 1 path: inc/Engine/Optimization/RUCSS/Controller/Filesystem.php - @@ -615,6 +610,11 @@ parameters: count: 1 path: inc/ThirdParty/Plugins/ContactForm7.php + - + message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" + count: 1 + path: inc/ThirdParty/Plugins/Cookie/Termly.php + - message: "#^Usage of get_option\\(\\) is discouraged\\. Use the Option object instead\\.$#" count: 13 @@ -2185,6 +2185,11 @@ parameters: count: 1 path: tests/Integration/inc/functions/rocketIsPluginActive.php + - + message: "#^Path in include_once\\(\\) \"vfs\\://public/wp\\-content/plugins/wp\\-rocket/inc/classes/dependencies/mobiledetect/mobiledetectlib/Mobile_Detect\\.php\" is not a file or it does not exist\\.$#" + count: 1 + path: tests/Integration/vfs:/public/wp-content/advanced-cache.php + - message: "#^Usage of apply_filters\\(\\) is discouraged\\. Use wpm_apply_filters_typed\\(\\) instead\\.$#" count: 5 From 9b7d05f628db652f6d592e5ef2b95be062984c09 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Fri, 10 Jan 2025 17:08:09 +0200 Subject: [PATCH 7/7] fix file formatting --- tests/phpstan/Rules/DiscourageWPOptionUsage.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/phpstan/Rules/DiscourageWPOptionUsage.php b/tests/phpstan/Rules/DiscourageWPOptionUsage.php index 9d020c2ae8..97888c9c4e 100644 --- a/tests/phpstan/Rules/DiscourageWPOptionUsage.php +++ b/tests/phpstan/Rules/DiscourageWPOptionUsage.php @@ -8,16 +8,13 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; -class DiscourageWPOptionUsage implements Rule -{ - public function getNodeType(): string - { +class DiscourageWPOptionUsage implements Rule { + public function getNodeType(): string { return FuncCall::class; } - public function processNode( Node $node, Scope $scope ): array - { - if (!$node instanceof FuncCall) { + public function processNode( Node $node, Scope $scope ): array { + if ( !$node instanceof FuncCall ) { return []; } @@ -29,7 +26,7 @@ public function processNode( Node $node, Scope $scope ): array 'delete_option' => true, ]; - if (isset($discouragedFunctions[$functionName])) { + if ( isset( $discouragedFunctions[ $functionName ] ) ) { return [ RuleErrorBuilder::message( sprintf( 'Usage of %1$s() is discouraged. Use the Option object instead.', $functionName ) ) ->identifier('custom.rules.discourageOptionUsage')