Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dd0815f
refactor(phpcs): Upgrade to 4.x in composer
klausi Oct 16, 2025
6a1ab87
fork our own get sniff code method
klausi Oct 17, 2025
d9a8bfe
property and tokenizer type fixes
klausi Oct 17, 2025
869cb6e
type hint
klausi Oct 17, 2025
a86e689
fix namespace detection
klausi Oct 17, 2025
f80f514
fix GlobalDrupal sniff
klausi Oct 17, 2025
469b172
fix global class sniff
klausi Oct 17, 2025
fecc520
class create sniff
klausi Oct 17, 2025
d3691c1
some namespace fixing
klausi Oct 17, 2025
69fe1dd
file name fix
klausi Oct 17, 2025
64a80fc
fix part 1 unused use statements
klausi Oct 17, 2025
fa946e7
fix unused use test
klausi Oct 17, 2025
c28645c
data type fixing
klausi Oct 17, 2025
0e38b85
fix good tests
klausi Oct 18, 2025
efb89c5
partial use statement fix
klausi Oct 18, 2025
84c9ad6
fix muktiline use statements
klausi Oct 18, 2025
81e6360
refactor to use SlevomatCodingStandard.ControlStructures.NewWithParen…
klausi Oct 18, 2025
7d9cbaf
refactor to SlevomatCodingStandard.Namespaces.UnusedUses
klausi Oct 18, 2025
6b7c9d0
refactor to use SlevomatCodingStandard.Namespaces.UseFromSameNamespace
klausi Oct 18, 2025
8000cd5
fix use statement comparison
klausi Oct 18, 2025
af8c9c7
ignore var fixes
klausi Oct 18, 2025
51d2b9d
fix crlf problem
klausi Oct 18, 2025
25ea8f9
coding standards
klausi Oct 18, 2025
a881e6d
fix phpstan
klausi Oct 18, 2025
94d070e
bump to PHP 7.4 minimum
klausi Oct 18, 2025
b4df5a4
fix phpcs run on core
klausi Oct 19, 2025
2ccf433
fix var type checking
klausi Oct 19, 2025
a08e673
Fix phpcs ignores in core
klausi Oct 19, 2025
b500e99
fixing more ignore comments in core
klausi Oct 19, 2025
6465dee
more ignore replacements
klausi Oct 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
extra-tests: ['0']
# We only need to run PHPStan and Drupal core regression tests once on
# the latest PHP version.
Expand Down Expand Up @@ -82,4 +82,14 @@ jobs:
# ignored temporarily, add them with the --ignore option.
run: |
cd drupal/core
../../vendor/bin/phpcs -p -s --parallel=$(nproc)
# Fix Drupal core PHPCS config by replacing removed sniffs.
sed -i 's/Drupal.Classes.ClassCreateInstance/SlevomatCodingStandard.ControlStructures.NewWithParentheses/g' phpcs.xml.dist
sed -i 's/Drupal.Classes.UnusedUseStatement/SlevomatCodingStandard.Namespaces.UnusedUses/g' phpcs.xml.dist
sed -i '/<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch" \/>/a \ <rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>' phpcs.xml.dist
find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore Drupal.Classes.PropertyDeclaration, Drupal.NamingConventions.ValidVariableName.LowerCamelName, Drupal.Commenting.VariableComment.Missing#// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName,PSR2.Classes.PropertyDeclaration.Underscore#g' {} +
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreLine#// phpcs:ignore#g' {} +
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreFile#// phpcs:ignoreFile#g' {} +
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' {} +
../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php
125 changes: 0 additions & 125 deletions coder_sniffer/Drupal/Sniffs/Classes/ClassCreateInstanceSniff.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;

/**
* Checks that class references do not use FQN but use statements.
Expand All @@ -30,7 +31,10 @@ class FullyQualifiedNamespaceSniff implements Sniff
*/
public function register()
{
return [T_NS_SEPARATOR];
return [
T_NAME_FULLY_QUALIFIED,
T_NAME_QUALIFIED,
];

}//end register()

Expand Down Expand Up @@ -61,7 +65,9 @@ public function process(File $phpcsFile, $stackPtr)

// We are only interested in a backslash embedded between strings, which
// means this is a class reference with more than one namespace part.
if ($tokens[($stackPtr - 1)]['code'] !== T_STRING || $tokens[($stackPtr + 1)]['code'] !== T_STRING) {
if (substr_count($tokens[$stackPtr]['content'], '\\') === 1
&& strpos($tokens[$stackPtr]['content'], '\\') === 0
) {
return;
}

Expand All @@ -71,25 +77,12 @@ public function process(File $phpcsFile, $stackPtr)
}

// Check if this is a use statement and ignore those.
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], $stackPtr, null, true);
$before = $phpcsFile->findPrevious((Tokens::EMPTY_TOKENS + Tokens::NAME_TOKENS + [T_COMMA => T_COMMA, T_AS => T_AS]), ($stackPtr - 1), null, true);
if ($tokens[$before]['code'] === T_USE || $tokens[$before]['code'] === T_NAMESPACE) {
return $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], ($stackPtr + 1), null, true);
} else {
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], $stackPtr, null, true);
}

// If this is a namespaced function call then ignore this because use
// statements for functions are not possible in PHP 5.5 and lower.
$after = $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], $stackPtr, null, true);
if ($tokens[$after]['code'] === T_OPEN_PARENTHESIS
&& $tokens[$before]['code'] !== T_NEW
&& $tokens[$before]['code'] !== T_ATTRIBUTE
) {
return ($after + 1);
return;
}

$fullName = $phpcsFile->getTokensAsString(($before + 1), ($after - 1 - $before));
$fullName = trim($fullName, "\ \n");
$fullName = trim($tokens[$stackPtr]['content'], '\\ ');
$parts = explode('\\', $fullName);
$className = end($parts);

Expand All @@ -101,7 +94,7 @@ public function process(File $phpcsFile, $stackPtr)
$useStatement = $phpcsFile->findNext(T_USE, 0);
while ($useStatement !== false && empty($tokens[$useStatement]['conditions']) === true) {
$endPtr = $phpcsFile->findEndOfStatement($useStatement);
$useEnd = ($phpcsFile->findNext([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], ($useStatement + 1), null, true) - 1);
$useEnd = ($phpcsFile->findNext((Tokens::EMPTY_TOKENS + Tokens::NAME_TOKENS), ($useStatement + 1), null, true) - 1);
$useFullName = trim($phpcsFile->getTokensAsString(($useStatement + 1), ($useEnd - $useStatement)));

// Check if use statement contains an alias.
Expand Down Expand Up @@ -163,18 +156,11 @@ public function process(File $phpcsFile, $stackPtr)
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();

// Replace the fully qualified name with the local name.
for ($i = ($before + 1); $i < $after; $i++) {
if ($tokens[$i]['code'] !== T_WHITESPACE) {
$phpcsFile->fixer->replaceToken($i, '');
}
}

// Use alias name if available.
if ($aliasName !== false) {
$phpcsFile->fixer->addContentBefore(($after - 1), $aliasName);
$phpcsFile->fixer->replaceToken($stackPtr, $aliasName);
} else {
$phpcsFile->fixer->addContentBefore(($after - 1), $className);
$phpcsFile->fixer->replaceToken($stackPtr, $className);
}

// Insert use statement at the beginning of the file if it is not there
Expand Down Expand Up @@ -216,10 +202,6 @@ public function process(File $phpcsFile, $stackPtr)
$phpcsFile->fixer->endChangeset();
}//end if

// Continue after this class reference so that errors for this are not
// flagged multiple times.
return $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR], ($stackPtr + 1), null, true);

}//end process()


Expand Down
Loading