From b3a6dd636405d5125f9ef1198b560822b6a40f17 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 19 Oct 2025 19:57:04 +0200 Subject: [PATCH 1/5] refactor(VariableAnalysis): Replace sniff with upstream sniff --- .../CodeAnalysis/VariableAnalysisSniff.php | 26 ----- coder_sniffer/DrupalPractice/ruleset.xml | 4 +- .../CodeAnalysis/VariableAnalysisUnitTest.php | 56 ---------- tests/DrupalPractice/bad/BadUnitTest.php | 100 ++++++++++++++++++ .../VariableAnalysisUnitTest.inc | 0 5 files changed, 102 insertions(+), 84 deletions(-) delete mode 100644 coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php delete mode 100644 tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.php create mode 100644 tests/DrupalPractice/bad/BadUnitTest.php rename tests/DrupalPractice/{CodeAnalysis => bad}/VariableAnalysisUnitTest.inc (100%) diff --git a/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php b/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php deleted file mode 100644 index bd2ed5ce..00000000 --- a/coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php +++ /dev/null @@ -1,26 +0,0 @@ -* - + *.tpl.php - + 0 diff --git a/tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.php b/tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.php deleted file mode 100644 index 6a657439..00000000 --- a/tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - protected function getErrorList(string $testFile): array - { - return []; - - }//end getErrorList() - - - /** - * 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. - * - * @param string $testFile The name of the file being tested. - * - * @return array - */ - protected function getWarningList(string $testFile): array - { - return [ - 4 => 1, - 8 => 1, - 17 => 1, - 61 => 1, - ]; - - }//end getWarningList() - - -}//end class diff --git a/tests/DrupalPractice/bad/BadUnitTest.php b/tests/DrupalPractice/bad/BadUnitTest.php new file mode 100644 index 00000000..17dbd2cc --- /dev/null +++ b/tests/DrupalPractice/bad/BadUnitTest.php @@ -0,0 +1,100 @@ + + */ + protected function getErrorList(string $testFile): array + { + return []; + + }//end getErrorList() + + + /** + * 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. + * + * @param string $testFile The name of the file being tested. + * + * @return array + */ + protected function getWarningList(string $testFile): array + { + switch ($testFile) { + case 'VariableAnalysisUnitTest.inc': + return [ + 4 => 1, + 8 => 1, + 17 => 1, + 61 => 1, + ]; + } + + return []; + + }//end getWarningList() + + + /** + * Returns a list of test files that should be checked. + * + * @param string $testFileBase The base path that the unit tests files will have. + * + * @return array + */ + protected function getTestFiles($testFileBase): array + { + $di = new \DirectoryIterator(__DIR__); + $testFiles = []; + + foreach ($di as $file) { + $path = $file->getPathname(); + if ($path !== __FILE__ && $file->isFile() === true && preg_match('/\.fixed$/', $path) !== 1) { + $testFiles[] = $path; + } + } + + // Get them in order. + sort($testFiles); + return $testFiles; + + }//end getTestFiles() + + + /** + * False if just the current sniff should be checked, true if all sniffs should be checked. + * + * @return bool + */ + protected function checkAllSniffCodes() + { + // We want to test all sniffs defined in the standard. + return true; + + }//end checkAllSniffCodes() + + +}//end class diff --git a/tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.inc b/tests/DrupalPractice/bad/VariableAnalysisUnitTest.inc similarity index 100% rename from tests/DrupalPractice/CodeAnalysis/VariableAnalysisUnitTest.inc rename to tests/DrupalPractice/bad/VariableAnalysisUnitTest.inc From db2ec8c9af6ccb276f3ef7041f8d360a873693dc Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 19 Oct 2025 20:03:20 +0200 Subject: [PATCH 2/5] remove FunctionDeclarationSniff --- .../Functions/FunctionDeclarationSniff.php | 70 ------------------- coder_sniffer/Drupal/ruleset.xml | 8 --- 2 files changed, 78 deletions(-) delete mode 100644 coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php diff --git a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php b/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php deleted file mode 100644 index 923ff9fe..00000000 --- a/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php +++ /dev/null @@ -1,70 +0,0 @@ - - */ - public function register() - { - return [T_FUNCTION]; - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token - * in the stack passed in $tokens. - * - * @return void - */ - public function process(File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ($tokens[($stackPtr + 1)]['content'] !== ' ') { - $error = 'Expected exactly one space after the function keyword'; - $phpcsFile->addError($error, ($stackPtr + 1), 'SpaceAfter'); - } - - if (isset($tokens[($stackPtr + 3)]) === true - && $tokens[($stackPtr + 3)]['code'] === T_WHITESPACE - ) { - $error = 'Space before opening parenthesis of function definition prohibited'; - $phpcsFile->addError($error, ($stackPtr + 3), 'SpaceBeforeParenthesis'); - } - - }//end process() - - -}//end class diff --git a/coder_sniffer/Drupal/ruleset.xml b/coder_sniffer/Drupal/ruleset.xml index 7c6ad8d4..4e603e6b 100644 --- a/coder_sniffer/Drupal/ruleset.xml +++ b/coder_sniffer/Drupal/ruleset.xml @@ -23,14 +23,6 @@ *.tpl.php - - - 0 - - - 0 - - From 7a53277767dac1172226604be4e748a74766f074 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 19 Oct 2025 20:06:51 +0200 Subject: [PATCH 3/5] rm UnnecessaryStringConcatSniff --- .../Strings/UnnecessaryStringConcatSniff.php | 97 ------------------- 1 file changed, 97 deletions(-) delete mode 100644 coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php diff --git a/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php b/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php deleted file mode 100644 index 005021c6..00000000 --- a/coder_sniffer/Drupal/Sniffs/Strings/UnnecessaryStringConcatSniff.php +++ /dev/null @@ -1,97 +0,0 @@ - - */ - public function register() - { - return [T_OPEN_TAG]; - - }//end register() - - - /** - * Processes the tokens that this sniff is interested in. - * - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return int - */ - public function process(File $phpcsFile, $stackPtr) - { - // This sniff is deprecated and disabled - do nothing. - return ($phpcsFile->numTokens + 1); - - }//end process() - - - /** - * {@inheritdoc} - * - * @return string - */ - public function getDeprecationVersion(): string - { - return 'Coder 8.3.30'; - - }//end getDeprecationVersion() - - - /** - * {@inheritdoc} - * - * @return string - */ - public function getRemovalVersion(): string - { - return 'Coder 9.0.0'; - - }//end getRemovalVersion() - - - /** - * {@inheritdoc} - * - * @return string - */ - public function getDeprecationMessage(): string - { - return 'The custom UnnecessaryStringConcatSniff is deprecated and will be removed in Coder 9.0.0. Use Generic.Strings.UnnecessaryStringConcat instead.'; - - }//end getDeprecationMessage() - - -}//end class From 3daa5b998ade7c3b3108521cd29b1ecae2d695e5 Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 19 Oct 2025 20:23:28 +0200 Subject: [PATCH 4/5] drupal core config fixing --- .github/workflows/testing.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 8257b73c..1e50a5ad 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -92,4 +92,7 @@ jobs: find . -type f -exec sed -i '/\/\/ phpcs:ignore/ s/, /,/g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreStart#// phpcs:disable#g' {} + find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreEnd#// phpcs:enable#g' {} + + sed -i '//d' phpcs.xml.dist + sed -i 's/DrupalPractice.CodeAnalysis.VariableAnalysis/VariableAnalysis.CodeAnalysis.VariableAnalysis/g' phpcs.xml.dist + find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable#// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable#g' {} + ../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php From 49298ed42c1c071128f9b07e3f3759e0496fff0d Mon Sep 17 00:00:00 2001 From: Klaus Purer Date: Sun, 19 Oct 2025 20:29:22 +0200 Subject: [PATCH 5/5] fix find command --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 1e50a5ad..a27c22b9 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -94,5 +94,5 @@ jobs: find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreEnd#// phpcs:enable#g' {} + sed -i '//d' phpcs.xml.dist sed -i 's/DrupalPractice.CodeAnalysis.VariableAnalysis/VariableAnalysis.CodeAnalysis.VariableAnalysis/g' phpcs.xml.dist - find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable#// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable#g' {} + + find .. -type f -name "*.php" -exec sed -i 's#// phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis#// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis#g' {} + ../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php