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

Breadcrumb

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

class PropertySpacingSniff

Hierarchy

  • class \SlevomatCodingStandard\Sniffs\Classes\AbstractPropertyConstantAndEnumCaseSpacing implements \PHP_CodeSniffer\Sniffs\Sniff
    • class \SlevomatCodingStandard\Sniffs\Classes\PropertySpacingSniff extends \SlevomatCodingStandard\Sniffs\Classes\AbstractPropertyConstantAndEnumCaseSpacing

Expanded class hierarchy of PropertySpacingSniff

File

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

Namespace

SlevomatCodingStandard\Sniffs\Classes
View source
class PropertySpacingSniff extends AbstractPropertyConstantAndEnumCaseSpacing {
    public const CODE_INCORRECT_COUNT_OF_BLANK_LINES_AFTER_PROPERTY = 'IncorrectCountOfBlankLinesAfterProperty';
    
    /**
     * @return array<int, (int|string)>
     */
    public function register() : array {
        return [
            T_VAR,
            T_PUBLIC,
            T_PROTECTED,
            T_PRIVATE,
            T_READONLY,
            T_STATIC,
        ];
    }
    
    /**
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
     * @param int $pointer
     */
    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);
    }
    protected function isNextMemberValid(File $phpcsFile, int $pointer) : bool {
        $nextPointer = TokenHelper::findNext($phpcsFile, [
            T_FUNCTION,
            T_VARIABLE,
        ], $pointer + 1);
        return $nextPointer !== null && $phpcsFile->getTokens()[$nextPointer]['code'] === T_VARIABLE;
    }
    protected function addError(File $phpcsFile, int $pointer, int $minExpectedLines, int $maxExpectedLines, int $found) : bool {
        if ($minExpectedLines === $maxExpectedLines) {
            $errorMessage = $minExpectedLines === 1 ? 'Expected 1 blank line after property, found %3$d.' : 'Expected %2$d blank lines after property, found %3$d.';
        }
        else {
            $errorMessage = 'Expected %1$d to %2$d blank lines after property, found %3$d.';
        }
        $error = sprintf($errorMessage, $minExpectedLines, $maxExpectedLines, $found);
        return $phpcsFile->addFixableError($error, $pointer, self::CODE_INCORRECT_COUNT_OF_BLANK_LINES_AFTER_PROPERTY);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractPropertyConstantAndEnumCaseSpacing::$maxLinesCountBeforeWithComment public property @var int
AbstractPropertyConstantAndEnumCaseSpacing::$maxLinesCountBeforeWithoutComment public property @var int
AbstractPropertyConstantAndEnumCaseSpacing::$minLinesCountBeforeWithComment public property @var int
AbstractPropertyConstantAndEnumCaseSpacing::$minLinesCountBeforeWithoutComment public property @var int
PropertySpacingSniff::addError protected function Overrides AbstractPropertyConstantAndEnumCaseSpacing::addError
PropertySpacingSniff::CODE_INCORRECT_COUNT_OF_BLANK_LINES_AFTER_PROPERTY public constant
PropertySpacingSniff::isNextMemberValid protected function Overrides AbstractPropertyConstantAndEnumCaseSpacing::isNextMemberValid
PropertySpacingSniff::process public function * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
*
Overrides AbstractPropertyConstantAndEnumCaseSpacing::process
PropertySpacingSniff::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