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

Breadcrumb

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

function AbstractPatternSniff::createTokenPattern

Creates a token pattern.

Parameters

string $str The tokens string that the pattern should match.:

Return value

array The pattern step.

See also

createSkipPattern()

parse()

1 call to AbstractPatternSniff::createTokenPattern()
AbstractPatternSniff::parse in vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractPatternSniff.php
Parses a pattern string into an array of pattern steps.

File

vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractPatternSniff.php, line 917

Class

AbstractPatternSniff

Namespace

PHP_CodeSniffer\Sniffs

Code

private function createTokenPattern($str) {
    // Don't add a space after the closing php tag as it will add a new
    // whitespace token.
    $tokenizer = new PHP('<?php ' . $str . '?>', null);
    // Remove the <?php tag from the front and the end php tag from the back.
    $tokens = $tokenizer->getTokens();
    $tokens = array_slice($tokens, 1, count($tokens) - 2);
    $patterns = [];
    foreach ($tokens as $patternInfo) {
        $patterns[] = [
            'type' => 'token',
            'token' => $patternInfo['code'],
            'value' => $patternInfo['content'],
        ];
    }
    return $patterns;
}

API Navigation

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