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

Breadcrumb

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

function TestCase::checkFile

*

Parameters

array<string, string|int|bool|array<int|string, (string|int|bool|null)>> $sniffProperties: * @param list<string> $codesToCheck * @param list<string> $cliArgs

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TestCase.php, line 38

Class

TestCase
@codeCoverageIgnore

Namespace

SlevomatCodingStandard\Sniffs

Code

protected static function checkFile(string $filePath, array $sniffProperties = [], array $codesToCheck = [], array $cliArgs = []) : File {
    if (defined('PHP_CODESNIFFER_CBF') === false) {
        define('PHP_CODESNIFFER_CBF', false);
    }
    $codeSniffer = new Runner();
    $codeSniffer->config = new Config(array_merge([
        '-s',
    ], $cliArgs));
    $codeSniffer->init();
    if (count($sniffProperties) > 0) {
        
        /** @phpstan-ignore-next-line */
        if (version_compare(Config::VERSION, '3.8.0', '>=')) {
            foreach ($sniffProperties as $name => $value) {
                $sniffProperties[$name] = [
                    'value' => $value,
                    'scope' => 'sniff',
                ];
            }
        }
        $codeSniffer->ruleset->ruleset[self::getSniffName()]['properties'] = $sniffProperties;
    }
    $sniffClassName = static::getSniffClassName();
    
    /** @var Sniff $sniff */
    $sniff = new $sniffClassName();
    $codeSniffer->ruleset->sniffs = [
        $sniffClassName => $sniff,
    ];
    if (count($codesToCheck) > 0) {
        foreach (self::getSniffClassReflection()->getConstants() as $constantName => $constantValue) {
            if (strpos($constantName, 'CODE_') !== 0 || in_array($constantValue, $codesToCheck, true)) {
                continue;
            }
            $codeSniffer->ruleset->ruleset[sprintf('%s.%s', self::getSniffName(), $constantValue)]['severity'] = 0;
        }
    }
    $codeSniffer->ruleset
        ->populateTokenListeners();
    $file = new LocalFile($filePath, $codeSniffer->ruleset, $codeSniffer->config);
    $file->process();
    return $file;
}
RSS feed
Powered by Drupal