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

Breadcrumb

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

class ExcludeList

Same name in this branch
  1. 11.1.x vendor/sebastian/global-state/src/ExcludeList.php \SebastianBergmann\GlobalState\ExcludeList

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Util\ExcludeList

Expanded class hierarchy of ExcludeList

1 file declares its use of ExcludeList
ErrorHandler.php in vendor/phpunit/phpunit/src/Runner/ErrorHandler.php

File

vendor/phpunit/phpunit/src/Util/ExcludeList.php, line 52

Namespace

PHPUnit\Util
View source
final class ExcludeList {
    
    /**
     * @psalm-var array<string,int>
     */
    private const EXCLUDED_CLASS_NAMES = [
        // composer
ClassLoader::class => 1,
        // myclabs/deepcopy
DeepCopy::class => 1,
        // nikic/php-parser
Parser::class => 1,
        // phar-io/manifest
Manifest::class => 1,
        // phar-io/version
PharIoVersion::class => 1,
        // phpunit/phpunit
TestCase::class => 2,
        // phpunit/php-code-coverage
CodeCoverage::class => 1,
        // phpunit/php-file-iterator
FileIteratorFacade::class => 1,
        // phpunit/php-invoker
Invoker::class => 1,
        // phpunit/php-text-template
Template::class => 1,
        // phpunit/php-timer
Timer::class => 1,
        // sebastian/cli-parser
CliParser::class => 1,
        // sebastian/code-unit
CodeUnit::class => 1,
        // sebastian/code-unit-reverse-lookup
Wizard::class => 1,
        // sebastian/comparator
Comparator::class => 1,
        // sebastian/complexity
Calculator::class => 1,
        // sebastian/diff
Diff::class => 1,
        // sebastian/environment
Runtime::class => 1,
        // sebastian/exporter
Exporter::class => 1,
        // sebastian/global-state
Snapshot::class => 1,
        // sebastian/lines-of-code
Counter::class => 1,
        // sebastian/object-enumerator
Enumerator::class => 1,
        // sebastian/object-reflector
ObjectReflector::class => 1,
        // sebastian/recursion-context
Context::class => 1,
        // sebastian/type
TypeName::class => 1,
        // sebastian/version
Version::class => 1,
        // theseer/tokenizer
Tokenizer::class => 1,
    ];
    
    /**
     * @psalm-var list<string>
     */
    private static array $directories = [];
    private static bool $initialized = false;
    private readonly bool $enabled;
    
    /**
     * @psalm-param non-empty-string $directory
     *
     * @throws InvalidDirectoryException
     */
    public static function addDirectory(string $directory) : void {
        if (!is_dir($directory)) {
            throw new InvalidDirectoryException($directory);
        }
        self::$directories[] = realpath($directory);
    }
    public function __construct(?bool $enabled = null) {
        if ($enabled === null) {
            $enabled = !defined('PHPUNIT_TESTSUITE');
        }
        $this->enabled = $enabled;
    }
    
    /**
     * @psalm-return list<string>
     */
    public function getExcludedDirectories() : array {
        self::initialize();
        return self::$directories;
    }
    public function isExcluded(string $file) : bool {
        if (!$this->enabled) {
            return false;
        }
        self::initialize();
        foreach (self::$directories as $directory) {
            if (str_starts_with($file, $directory)) {
                return true;
            }
        }
        return false;
    }
    private static function initialize() : void {
        if (self::$initialized) {
            return;
        }
        foreach (self::EXCLUDED_CLASS_NAMES as $className => $parent) {
            if (!class_exists($className)) {
                continue;
            }
            $directory = (new ReflectionClass($className))->getFileName();
            for ($i = 0; $i < $parent; $i++) {
                $directory = dirname($directory);
            }
            self::$directories[] = $directory;
        }
        
        /**
         * Hide process isolation workaround on Windows:
         * tempnam() prefix is limited to first 3 characters.
         *
         * @see https://php.net/manual/en/function.tempnam.php
         */
        if (PHP_OS_FAMILY === 'Windows') {
            // @codeCoverageIgnoreStart
            self::$directories[] = sys_get_temp_dir() . '\\PHP';
            // @codeCoverageIgnoreEnd
        }
        self::$initialized = true;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ExcludeList::$directories private static property @psalm-var list&lt;string&gt;
ExcludeList::$enabled private property
ExcludeList::$initialized private static property
ExcludeList::addDirectory public static function @psalm-param non-empty-string $directory
ExcludeList::EXCLUDED_CLASS_NAMES private constant @psalm-var array&lt;string,int&gt;
ExcludeList::getExcludedDirectories public function @psalm-return list&lt;string&gt;
ExcludeList::initialize private static function
ExcludeList::isExcluded public function
ExcludeList::__construct public function

API Navigation

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