From f9eb45e14365f4bc9b558c714d79959d7ebfbb08 Mon Sep 17 00:00:00 2001 From: Shyamsundar Gadde Date: Fri, 10 Jan 2025 01:12:12 +0530 Subject: [PATCH] Add custom sniff to warn about `empty()` Signed-off-by: Shyamsundar Gadde --- .../PHP/RestrictedEmptyConstructSniff.php | 40 +++++++++++++++++++ tools/phpcs/phpcs.ruleset.xml | 8 ++++ 2 files changed, 48 insertions(+) create mode 100644 tools/phpcs/Sniffs/PHP/RestrictedEmptyConstructSniff.php diff --git a/tools/phpcs/Sniffs/PHP/RestrictedEmptyConstructSniff.php b/tools/phpcs/Sniffs/PHP/RestrictedEmptyConstructSniff.php new file mode 100644 index 0000000000..3963eb20cf --- /dev/null +++ b/tools/phpcs/Sniffs/PHP/RestrictedEmptyConstructSniff.php @@ -0,0 +1,40 @@ +addWarning( + 'Usage of empty() can mask code problems. Consider explicit checks instead.', + $stackPtr, + 'EmptyConstructUsage' + ); + } +} diff --git a/tools/phpcs/phpcs.ruleset.xml b/tools/phpcs/phpcs.ruleset.xml index 5d00f48b6d..f19fbbd484 100644 --- a/tools/phpcs/phpcs.ruleset.xml +++ b/tools/phpcs/phpcs.ruleset.xml @@ -113,6 +113,14 @@ + + + ./Sniffs/* + + + ./Sniffs/* + + ./build/*