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

Breadcrumb

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

function Common::getSniffCode

Given a sniff class name, returns the code for the sniff.

Parameters

string $sniffClass The fully qualified sniff class name.:

Return value

string

Throws

\InvalidArgumentException When $sniffClass is not a non-empty string.

\InvalidArgumentException When $sniffClass is not a FQN for a sniff(test) class.

9 calls to Common::getSniffCode()
File::addMessage in vendor/squizlabs/php_codesniffer/src/Files/File.php
Adds an error to the error stack.
Fixer::beginChangeset in vendor/squizlabs/php_codesniffer/src/Fixer.php
Start recording actions for a changeset.
Fixer::replaceToken in vendor/squizlabs/php_codesniffer/src/Fixer.php
Replace the entire contents of a token.
Fixer::revertToken in vendor/squizlabs/php_codesniffer/src/Fixer.php
Reverts the previous fix made to a token.
Fixer::rollbackChangeset in vendor/squizlabs/php_codesniffer/src/Fixer.php
Stop recording actions for a changeset, and discard logged changes.

... See full list

File

vendor/squizlabs/php_codesniffer/src/Util/Common.php, line 537

Class

Common

Namespace

PHP_CodeSniffer\Util

Code

public static function getSniffCode($sniffClass) {
    if (is_string($sniffClass) === false || $sniffClass === '') {
        throw new InvalidArgumentException('The $sniffClass parameter must be a non-empty string');
    }
    $parts = explode('\\', $sniffClass);
    $partsCount = count($parts);
    $sniff = $parts[$partsCount - 1];
    if (substr($sniff, -5) === 'Sniff') {
        // Sniff class name.
        $sniff = substr($sniff, 0, -5);
    }
    else {
        if (substr($sniff, -8) === 'UnitTest') {
            // Unit test class name.
            $sniff = substr($sniff, 0, -8);
        }
        else {
            throw new InvalidArgumentException('The $sniffClass parameter was not passed a fully qualified sniff(test) class name. Received: ' . $sniffClass);
        }
    }
    $standard = '';
    if (isset($parts[$partsCount - 4]) === true) {
        $standard = $parts[$partsCount - 4];
    }
    $category = '';
    if (isset($parts[$partsCount - 2]) === true) {
        $category = $parts[$partsCount - 2];
    }
    return $standard . '.' . $category . '.' . $sniff;
}
RSS feed
Powered by Drupal