Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ContainerException
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 forInvalidService
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/container.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/container
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Container\Exception;
20
21use Exception;
22use Throwable;
23use Psr\Container\ContainerExceptionInterface;
24
25/**
26 * Exception type for container-related errors while resolving services.
27 *
28 * This class MUST be used to signal problems occurring during service resolution
29 * from a container that complies with PSR-11.
30 */
31 class ContainerException extends Exception implements ContainerExceptionInterface
32{
33    /**
34     * Creates an exception for an invalid or unresolvable service identifier.
35     *
36     * This factory method MUST be invoked when a service ID fails to resolve
37     * or the resolved service is invalid in the current context.
38     *
39     * @param string $id the identifier of the service that caused the failure
40     * @param Throwable $previous the previous exception thrown during resolution
41     *
42     * @return self an instance of ContainerException describing the issue
43     */
44    public static function forInvalidService(string $id, Throwable $previous): self
45    {
46        return new self(\sprintf('Invalid service "%s".', $id), $previous->getCode(), $previous);
47    }
48}