<commit_before><?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\Event;

use PHPUnit\Event\Telemetry\HRTime;

/**
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
 */
final class Facade
{
    private static ?TypeMap $typeMap = null;

    private static ?Emitter $emitter = null;

    private static ?Emitter $suspended = null;

    private static ?DeferredDispatcher $deferredDispatcher = null;

    private static bool $sealed = false;

    /**
     * @throws EventFacadeIsSealedException
     * @throws UnknownSubscriberTypeException
     */
    public static function registerSubscriber(Subscriber $subscriber): void
    {
        if (self::$sealed) {
            throw new EventFacadeIsSealedException;
        }

        self::deferredDispatcher()->registerSubscriber($subscriber);
    }

    /**
     * @throws EventFacadeIsSealedException
     */
    public static function registerTracer(Tracer\Tracer $tracer): void
    {
        if (self::$sealed) {
            throw new EventFacadeIsSealedException;
        }

        self::deferredDispatcher()->registerTracer($tracer);
    }

    /**
     * @internal This method is not covered by the backward compatibility promise for PHPUnit
     */
    public static function emitter(): Emitter
    {
        if (self::$emitter === null) {
            self::$emitter = self::createDispatchingEmitter();
        }

        return self::$emitter;
    }

    /**
     * @throws NoEmitterToSuspendException
     */
    public static function suspend(): void
    {
        if (self::$emitter === null) {
            throw new NoEmitterToSuspendException;
        }

        self::$suspended = self::$emitter;

        self::$emitter = new DispatchingEmitter(
            new CollectingDispatcher,
            self::createTelemetrySystem()
        );
    }

    /**
     * @throws NoEmitterToResumeException
     */
    public static function resume(): void
    {
        if (self::$suspended === null) {
            throw new NoEmitterToResumeException;
        }

        self::$emitter   = self::$suspended;
        self::$suspended = null;
    }

    /**
     * @internal This method is not covered by the backward compatibility promise for PHPUnit
     */
    public static function initForIsolation(HRTime $offset): CollectingDispatcher
    {
        $dispatcher = new CollectingDispatcher;

        self::$emitter = new DispatchingEmitter(
            $dispatcher,
            new Telemetry\System(
                new Telemetry\SystemStopWatchWithOffset($offset),<commit_msg>Mark Facade::suspend() and Facade::resume() as internal<commit_after><?php declare(strict_types=1);
/*
 * This file is part of PHPUnit.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace PHPUnit\Event;

use PHPUnit\Event\Telemetry\HRTime;

/**
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
 */
final class Facade
{
    private static ?TypeMap $typeMap = null;

    private static ?Emitter $emitter = null;

    private static ?Emitter $suspended = null;

    private static ?DeferredDispatcher $deferredDispatcher = null;

    private static bool $sealed = false;

    /**
     * @throws EventFacadeIsSealedException
     * @throws UnknownSubscriberTypeException
     */
    public static function registerSubscriber(Subscriber $subscriber): void
    {
        if (self::$sealed) {
            throw new EventFacadeIsSealedException;
        }

        self::deferredDispatcher()->registerSubscriber($subscriber);
    }

    /**
     * @throws EventFacadeIsSealedException
     */
    public static function registerTracer(Tracer\Tracer $tracer): void
    {
        if (self::$sealed) {
            throw new EventFacadeIsSealedException;
        }

        self::deferredDispatcher()->registerTracer($tracer);
    }

    /**
     * @internal This method is not covered by the backward compatibility promise for PHPUnit
     */
    public static function emitter(): Emitter
    {
        if (self::$emitter === null) {
            self::$emitter = self::createDispatchingEmitter();
        }

        return self::$emitter;
    }

    /**
     * @throws NoEmitterToSuspendException
     *
     * @internal This method is not covered by the backward compatibility promise for PHPUnit
     */
    public static function suspend(): void
    {
        if (self::$emitter === null) {
            throw new NoEmitterToSuspendException;
        }

        self::$suspended = self::$emitter;

        self::$emitter = new DispatchingEmitter(
            new CollectingDispatcher,
            self::createTelemetrySystem()
        );
    }

    /**
     * @throws NoEmitterToResumeException
     *
     * @internal This method is not covered by the backward compatibility promise for PHPUnit
     */
    public static function resume(): void
    {
        if (self::$suspended === null) {
            throw new NoEmitterToResumeException;
        }

        self::$emitter   = self::$suspended;
        self::$suspended = null;
    }

    /**
     * @internal This method is not covered by the backward compatibility promise for PHPUnit
     */
    public static function initForIsolation(HRTime $offset): CollectingDispatcher
    {
        $dispatcher = new CollectingDispatcher;

        self::$emitter = new DispatchingEmitter(
            $dispatcher,
            new Telemetry\System(
                new Telemetry\SystemStopWatchWithOffset($offset),
{'fraction_non_alphanumeric': 0.09645194626248708, 'fraction_numerical': 0.0003444712366517396, 'mean_word_length': 2.571340713407134, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5902683', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1527, 'n_words': 426}