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

Breadcrumb

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

function PropertySpacingSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $pointer:

Overrides AbstractPropertyConstantAndEnumCaseSpacing::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/PropertySpacingSniff.php, line 39

Class

PropertySpacingSniff

Namespace

SlevomatCodingStandard\Sniffs\Classes

Code

public function process(File $phpcsFile, $pointer) : int {
    $tokens = $phpcsFile->getTokens();
    $asPointer = TokenHelper::findPreviousEffective($phpcsFile, $pointer - 1);
    if ($tokens[$asPointer]['code'] === T_AS) {
        return $pointer;
    }
    $nextPointer = TokenHelper::findNextEffective($phpcsFile, $pointer + 1);
    if (in_array($tokens[$nextPointer]['code'], [
        T_VAR,
        T_PUBLIC,
        T_PROTECTED,
        T_PRIVATE,
        T_READONLY,
        T_STATIC,
    ], true)) {
        // We don't want to report the same property twice
        return $nextPointer;
    }
    $propertyPointer = TokenHelper::findNext($phpcsFile, [
        T_VARIABLE,
        T_FUNCTION,
        T_CONST,
        T_USE,
    ], $pointer + 1);
    if ($propertyPointer === null || $tokens[$propertyPointer]['code'] !== T_VARIABLE || !PropertyHelper::isProperty($phpcsFile, $propertyPointer)) {
        return $propertyPointer ?? $pointer;
    }
    return parent::process($phpcsFile, $propertyPointer);
}
RSS feed
Powered by Drupal