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

Breadcrumb

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

function AbstractPatternSniff::createSkipPattern

Creates a skip pattern.

Parameters

string $pattern The pattern being parsed.:

int $from The token position that the skip pattern starts from.:

Return value

array The pattern step.

See also

createTokenPattern()

parse()

1 call to AbstractPatternSniff::createSkipPattern()
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 864

Class

AbstractPatternSniff

Namespace

PHP_CodeSniffer\Sniffs

Code

private function createSkipPattern($pattern, $from) {
    $skip = [
        'type' => 'skip',
    ];
    $nestedParenthesis = 0;
    $nestedBraces = 0;
    for ($start = $from; $start >= 0; $start--) {
        switch ($pattern[$start]) {
            case '(':
                if ($nestedParenthesis === 0) {
                    $skip['to'] = 'parenthesis_closer';
                }
                $nestedParenthesis--;
                break;
            case '{':
                if ($nestedBraces === 0) {
                    $skip['to'] = 'scope_closer';
                }
                $nestedBraces--;
                break;
            case '}':
                $nestedBraces++;
                break;
            case ')':
                $nestedParenthesis++;
                break;
        }
        
        //end switch
        if (isset($skip['to']) === true) {
            break;
        }
    }
    
    //end for
    if (isset($skip['to']) === false) {
        $skip['to'] = 'unknown';
    }
    return $skip;
}

API Navigation

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