ContainerException::instanceProtected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Container\Exception;
6
7
use Exception;
8
use Psr\Container\ContainerExceptionInterface;
9
10
final class ContainerException extends Exception implements ContainerExceptionInterface
11
{
12 1
    public static function instanceNotExtendable(): self
13
    {
14 1
        $message = <<<TXT
15
The passed instance is not extendable.
16
Only objects, arrays, and callables can be extended.
17
18
Ensure the service is one of these types before calling extend().
19 1
TXT;
20 1
        return new self($message);
21
    }
22
23 4
    public static function frozenInstanceExtend(string $id): self
24
    {
25 4
        $message = <<<TXT
26 4
The instance '{$id}' is frozen and cannot be extended.
27
Services become frozen after being accessed via get() to ensure consistency.
28
29
Extend the service before accessing it, or use remove() to unfreeze it first.
30 4
TXT;
31 4
        return new self($message);
32
    }
33
34 1
    public static function frozenInstanceOverride(string $id): self
35
    {
36 1
        $message = <<<TXT
37 1
The instance '{$id}' is frozen and cannot be overridden.
38
Services become frozen after being accessed via get() to ensure consistency.
39
40 1
Call remove('{$id}') before setting a new value, or avoid accessing it before replacement.
41 1
TXT;
42 1
        return new self($message);
43
    }
44
45 1
    public static function instanceProtected(string $id): self
46
    {
47 1
        $message = <<<TXT
48 1
The instance '{$id}' is protected and cannot be extended.
49
Protected closures are treated as values, not as service factories.
50
51
Remove the protect() wrapper if you need to extend this service.
52 1
TXT;
53 1
        return new self($message);
54
    }
55
}
56