From 172405e182e17996455b80c7bdea1af103c26e40 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 16 Mar 2020 06:37:01 +0100 Subject: [PATCH 1/3] BadFunctions/NoEvals: add unit tests --- .../Tests/BadFunctions/NoEvalsUnitTest.inc | 5 +++ .../Tests/BadFunctions/NoEvalsUnitTest.php | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Security/Tests/BadFunctions/NoEvalsUnitTest.inc create mode 100644 Security/Tests/BadFunctions/NoEvalsUnitTest.php diff --git a/Security/Tests/BadFunctions/NoEvalsUnitTest.inc b/Security/Tests/BadFunctions/NoEvalsUnitTest.inc new file mode 100644 index 0000000..5584268 --- /dev/null +++ b/Security/Tests/BadFunctions/NoEvalsUnitTest.inc @@ -0,0 +1,5 @@ + + */ + public function getErrorList() + { + return [ + 3 => 1, + 4 => 1, + 5 => 1, + ]; + } + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array + */ + public function getWarningList() + { + return []; + } +} From d14203a90503a5a296c816ba43c95db3aea1fae6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 16 Mar 2020 06:37:59 +0100 Subject: [PATCH 2/3] BadFunctions/NoEvals: error message precision `eval()` is a language construct, not a function. Ref: https://www.php.net/manual/en/function.eval.php --- Security/Sniffs/BadFunctions/NoEvalsSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Security/Sniffs/BadFunctions/NoEvalsSniff.php b/Security/Sniffs/BadFunctions/NoEvalsSniff.php index 80e0b62..f3902d3 100644 --- a/Security/Sniffs/BadFunctions/NoEvalsSniff.php +++ b/Security/Sniffs/BadFunctions/NoEvalsSniff.php @@ -27,7 +27,7 @@ public function register() { */ public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); - $error = 'Please do not use eval() functions'; + $error = 'Please do not use eval()'; $phpcsFile->addError($error, $stackPtr, 'NoEvals'); } From 0c57997b1321701be954fdc440f4a2705386fd9a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 16 Mar 2020 06:42:23 +0100 Subject: [PATCH 3/3] BadFunctions/NoEvals: remove redundant function call `$tokens` is not used, so no need to declare it. --- Security/Sniffs/BadFunctions/NoEvalsSniff.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Security/Sniffs/BadFunctions/NoEvalsSniff.php b/Security/Sniffs/BadFunctions/NoEvalsSniff.php index f3902d3..c369686 100644 --- a/Security/Sniffs/BadFunctions/NoEvalsSniff.php +++ b/Security/Sniffs/BadFunctions/NoEvalsSniff.php @@ -26,7 +26,6 @@ public function register() { * @return void */ public function process(File $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); $error = 'Please do not use eval()'; $phpcsFile->addError($error, $stackPtr, 'NoEvals'); }