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-plugin-arch/src/Expectations/ToOnlyBeUsedIn.php
<?php

declare(strict_types=1);

namespace Pest\Arch\Expectations;

use Pest\Arch\Blueprint;
use Pest\Arch\Collections\Dependencies;
use Pest\Arch\Exceptions\ArchExpectationFailedException;
use Pest\Arch\GroupArchExpectation;
use Pest\Arch\Options\LayerOptions;
use Pest\Arch\SingleArchExpectation;
use Pest\Arch\ValueObjects\Targets;
use Pest\Arch\ValueObjects\Violation;
use Pest\Expectation;
use PHPUnit\Framework\ExpectationFailedException;

/**
 * @internal
 */
final class ToOnlyBeUsedIn
{
    /**
     * Creates an "ToOnlyBeUsedIn" expectation.
     *
     * @param  array<int, string>|string  $targets
     */
    public static function make(Expectation $expectation, array|string $targets): GroupArchExpectation
    {
        assert(is_string($expectation->value) || is_array($expectation->value));

        /** @var Expectation<array<int, string>|string> $expectation */
        $blueprint = Blueprint::make(
            Targets::fromExpectation($expectation),
            Dependencies::fromExpectationInput($targets),
        );

        return GroupArchExpectation::fromExpectations($expectation, [
            SingleArchExpectation::fromExpectation(
                $expectation,
                static function (LayerOptions $options) use ($blueprint): void {
                    $blueprint->expectToOnlyBeUsedIn(
                        $options,
                        static function (string $value, string $notAllowedDependOn, ?Violation $violation): void {
                            if (! $violation instanceof Violation) {
                                throw new ExpectationFailedException(
                                    "Expecting '$value' not to be used on '$notAllowedDependOn'.",
                                );
                            }

                            throw new ArchExpectationFailedException($violation, "Expecting '$value' not to be used on '$notAllowedDependOn'.");
                        },
                    );
                },
            ),
        ]);
    }
}