Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DisallowConstructorPropertyPromotionSniff.php

class DisallowConstructorPropertyPromotionSniff

Hierarchy

  • class \SlevomatCodingStandard\Sniffs\Classes\DisallowConstructorPropertyPromotionSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of DisallowConstructorPropertyPromotionSniff

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/DisallowConstructorPropertyPromotionSniff.php, line 17

Namespace

SlevomatCodingStandard\Sniffs\Classes
View source
class DisallowConstructorPropertyPromotionSniff implements Sniff {
    public const CODE_DISALLOWED_CONSTRUCTOR_PROPERTY_PROMOTION = 'DisallowedConstructorPropertyPromotion';
    
    /**
     * @return array<int, (int|string)>
     */
    public function register() : array {
        return [
            T_FUNCTION,
        ];
    }
    
    /**
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
     * @param int $functionPointer
     */
    public function process(File $phpcsFile, $functionPointer) : void {
        $tokens = $phpcsFile->getTokens();
        $namePointer = TokenHelper::findNextEffective($phpcsFile, $functionPointer + 1);
        if (strtolower($tokens[$namePointer]['content']) !== '__construct') {
            return;
        }
        $modifierPointers = TokenHelper::findNextAll($phpcsFile, [
            T_PUBLIC,
            T_PROTECTED,
            T_PRIVATE,
            T_READONLY,
        ], $tokens[$functionPointer]['parenthesis_opener'] + 1, $tokens[$functionPointer]['parenthesis_closer']);
        if ($modifierPointers === []) {
            return;
        }
        foreach ($modifierPointers as $modifierPointer) {
            $variablePointer = TokenHelper::findNext($phpcsFile, T_VARIABLE, $modifierPointer + 1);
            $phpcsFile->addError(sprintf('Constructor property promotion is disallowed, promotion of property %s found.', $tokens[$variablePointer]['content']), $variablePointer, self::CODE_DISALLOWED_CONSTRUCTOR_PROPERTY_PROMOTION);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DisallowConstructorPropertyPromotionSniff::CODE_DISALLOWED_CONSTRUCTOR_PROPERTY_PROMOTION public constant
DisallowConstructorPropertyPromotionSniff::process public function * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
*
Overrides Sniff::process
DisallowConstructorPropertyPromotionSniff::register public function * Overrides Sniff::register

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal