clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
/**
* \Drupal\Sniffs\Functions\DiscouragedFunctionsSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\Functions;
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
/**
* Discourage the use of debug functions.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class DiscouragedFunctionsSniff extends ForbiddenFunctionsSniff
{
/**
* A list of forbidden functions with their alternatives.
*
* The value is NULL if no alternative exists, i.e., the function should
* just not be used.
*
* cspell:disable
*
* @var array<string, null>
*/
public $forbiddenFunctions = [
// Devel module debugging functions.
'dargs' => null,
'dcp' => null,
'dd' => null,
'ddebug_backtrace' => null,
'ddm' => null,
'dfb' => null,
'dfbt' => null,
'dpm' => null,
'dpq' => null,
'dpr' => null,
'dprint_r' => null,
'drupal_debug' => null,
'dsm' => null,
'dvm' => null,
'dvr' => null,
'kdevel_print_object' => null,
'kint' => null,
'ksm' => null,
'kpr' => null,
'kprint_r' => null,
'sdpm' => null,
// Functions which are not available on all
// PHP builds.
'fnmatch' => null,
// Functions which are a security risk.
'eval' => null,
// cspell:enable
];
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var boolean
*/
public $error = false;
}//end class

View File

@@ -0,0 +1,70 @@
<?php
/**
* \Drupal\Sniffs\Functions\FunctionDeclarationSniff.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\Functions;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
/**
* Ensure that there is only one space after the function keyword and no space
* before the opening parenthesis.
*
* @deprecated in Coder 8.x, will be removed in Coder 9.x.
* MultiLineFunctionDeclarationSniff is used instead.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class FunctionDeclarationSniff implements Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
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

View File

@@ -0,0 +1,129 @@
<?php
/**
* \Drupal\Sniffs\Functions\MultiLineFunctionDeclarationSniff
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
namespace Drupal\Sniffs\Functions;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\OpeningFunctionBraceKernighanRitchieSniff;
use PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\FunctionDeclarationSniff as PearFunctionDeclarationSniff;
use PHP_CodeSniffer\Standards\Squiz\Sniffs\Functions\MultiLineFunctionDeclarationSniff as SquizFunctionDeclarationSniff;
use PHP_CodeSniffer\Util\Tokens;
/**
* Multi-line function declarations need to have a trailing comma on the last
* parameter. Modified from Squiz, whenever there is a function declaration
* closing parenthesis on a new line we treat it as multi-line.
*
* @category PHP
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class MultiLineFunctionDeclarationSniff extends SquizFunctionDeclarationSniff
{
/**
* The number of spaces code should be indented.
*
* @var integer
*/
public $indent = 2;
/**
* Processes single-line declarations.
*
* Just uses the Generic Kernighan Ritchie sniff.
*
* @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.
* @param array<int, array<string, mixed>> $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens)
{
$sniff = new OpeningFunctionBraceKernighanRitchieSniff();
$sniff->checkClosures = true;
$sniff->process($phpcsFile, $stackPtr);
}//end processSingleLineDeclaration()
/**
* Determine if this is a multi-line function declaration.
*
* @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.
* @param int $openBracket The position of the opening bracket
* in the stack passed in $tokens.
* @param array<int, array<string, mixed>> $tokens The stack of tokens that make up
* the file.
*
* @return bool
*/
public function isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens)
{
$function = $tokens[$stackPtr];
if ($tokens[$function['parenthesis_opener']]['line'] === $tokens[$function['parenthesis_closer']]['line']) {
return false;
}
return true;
}//end isMultiLineDeclaration()
/**
* Processes multi-line declarations.
*
* @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.
* @param array<int, array<string, mixed>> $tokens The stack of tokens that make up
* the file.
*
* @return void
*/
public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens)
{
// We do everything the grandparent sniff does, and a bit more.
PearFunctionDeclarationSniff::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
$this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
// Trailing commas on the last function parameter are only possible in
// PHP 8.0+.
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
return;
}
$function = $tokens[$stackPtr];
$lastTrailingComma = $phpcsFile->findPrevious(
Tokens::$emptyTokens,
($function['parenthesis_closer'] - 1),
$function['parenthesis_opener'],
true
);
if ($tokens[$lastTrailingComma]['code'] !== T_COMMA) {
$error = 'Multi-line function declarations must have a trailing comma after the last parameter';
$fix = $phpcsFile->addFixableError($error, $lastTrailingComma, 'MissingTrailingComma');
if ($fix === true) {
$phpcsFile->fixer->addContent($lastTrailingComma, ',');
}
}
}//end processMultiLineDeclaration()
}//end class