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

Breadcrumb

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

function AttributeHelper::getAttributes

*

Return value

list<Attribute>

2 calls to AttributeHelper::getAttributes()
AttributesOrderSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Attributes/AttributesOrderSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
DisallowAttributesJoiningSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Attributes/DisallowAttributesJoiningSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AttributeHelper.php, line 46

Class

AttributeHelper
@internal

Namespace

SlevomatCodingStandard\Helpers

Code

public static function getAttributes(File $phpcsFile, int $attributeOpenerPointer) : array {
    $tokens = $phpcsFile->getTokens();
    if ($tokens[$attributeOpenerPointer]['code'] !== T_ATTRIBUTE) {
        throw new InvalidArgumentException(sprintf('Token %d must be attribute, %s given.', $attributeOpenerPointer, $tokens[$attributeOpenerPointer]['type']));
    }
    $attributeCloserPointer = $tokens[$attributeOpenerPointer]['attribute_closer'];
    $actualPointer = $attributeOpenerPointer;
    $attributes = [];
    do {
        $attributeNameStartPointer = TokenHelper::findNextEffective($phpcsFile, $actualPointer + 1, $attributeCloserPointer);
        if ($attributeNameStartPointer === null) {
            break;
        }
        $attributeNameEndPointer = TokenHelper::findNextExcluding($phpcsFile, TokenHelper::getNameTokenCodes(), $attributeNameStartPointer + 1) - 1;
        $attributeName = TokenHelper::getContent($phpcsFile, $attributeNameStartPointer, $attributeNameEndPointer);
        $pointerAfterAttributeName = TokenHelper::findNextEffective($phpcsFile, $attributeNameEndPointer + 1, $attributeCloserPointer);
        if ($pointerAfterAttributeName === null) {
            $attributes[] = new Attribute($attributeOpenerPointer, $attributeName, $attributeNameStartPointer, $attributeNameEndPointer);
            break;
        }
        if ($tokens[$pointerAfterAttributeName]['code'] === T_COMMA) {
            $attributes[] = new Attribute($attributeOpenerPointer, $attributeName, $attributeNameStartPointer, $attributeNameEndPointer);
            $actualPointer = $pointerAfterAttributeName;
        }
        if ($tokens[$pointerAfterAttributeName]['code'] === T_OPEN_PARENTHESIS) {
            $attributes[] = new Attribute($attributeOpenerPointer, $attributeName, $attributeNameStartPointer, $tokens[$pointerAfterAttributeName]['parenthesis_closer'], TokenHelper::getContent($phpcsFile, $pointerAfterAttributeName, $tokens[$pointerAfterAttributeName]['parenthesis_closer']));
            $actualPointer = TokenHelper::findNextEffective($phpcsFile, $tokens[$pointerAfterAttributeName]['parenthesis_closer'] + 1, $attributeCloserPointer);
            continue;
        }
    } while ($actualPointer !== null);
    return $attributes;
}

API Navigation

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