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

Breadcrumb

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

class RequireOneLinePropertyDocCommentSniff

Hierarchy

  • class \SlevomatCodingStandard\Sniffs\Commenting\AbstractRequireOneLineDocComment implements \PHP_CodeSniffer\Sniffs\Sniff
    • class \SlevomatCodingStandard\Sniffs\Commenting\RequireOneLinePropertyDocCommentSniff extends \SlevomatCodingStandard\Sniffs\Commenting\AbstractRequireOneLineDocComment

Expanded class hierarchy of RequireOneLinePropertyDocCommentSniff

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Commenting/RequireOneLinePropertyDocCommentSniff.php, line 12

Namespace

SlevomatCodingStandard\Sniffs\Commenting
View source
class RequireOneLinePropertyDocCommentSniff extends AbstractRequireOneLineDocComment {
    public const CODE_MULTI_LINE_PROPERTY_COMMENT = 'MultiLinePropertyComment';
    
    /**
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
     * @param int $docCommentStartPointer
     */
    public function process(File $phpcsFile, $docCommentStartPointer) : void {
        $propertyPointer = TokenHelper::findNext($phpcsFile, T_VARIABLE, $docCommentStartPointer + 1);
        if ($propertyPointer === null) {
            return;
        }
        // Not a property
        if (!PropertyHelper::isProperty($phpcsFile, $propertyPointer)) {
            return;
        }
        // Check that doc comment belongs to the found property
        $propertyDocCommentStartPointer = DocCommentHelper::findDocCommentOpenPointer($phpcsFile, $propertyPointer);
        if ($propertyDocCommentStartPointer !== $docCommentStartPointer) {
            return;
        }
        // Only validate properties without description
        if (DocCommentHelper::hasDocCommentDescription($phpcsFile, $propertyPointer)) {
            return;
        }
        parent::process($phpcsFile, $docCommentStartPointer);
    }
    protected function addError(File $phpcsFile, int $docCommentStartPointer) : bool {
        $error = 'Found multi-line comment for property %s with single line content, use one-line comment instead.';
        
        /** @var int $propertyPointer */
        $propertyPointer = $phpcsFile->findNext(T_VARIABLE, $docCommentStartPointer);
        return $phpcsFile->addFixableError(sprintf($error, PropertyHelper::getFullyQualifiedName($phpcsFile, $propertyPointer)), $docCommentStartPointer, self::CODE_MULTI_LINE_PROPERTY_COMMENT);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractRequireOneLineDocComment::register public function * Overrides Sniff::register
RequireOneLinePropertyDocCommentSniff::addError protected function Overrides AbstractRequireOneLineDocComment::addError
RequireOneLinePropertyDocCommentSniff::CODE_MULTI_LINE_PROPERTY_COMMENT public constant
RequireOneLinePropertyDocCommentSniff::process public function * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
*
Overrides AbstractRequireOneLineDocComment::process
RSS feed
Powered by Drupal