IdentityNotFound::requesting()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\IdentityMap;
5
6
use function get_class as theClassOfThe;
7
use InvalidArgumentException as InvalidArgument;
8
use function sprintf as withMessage;
9
10
/**
11
 * Notifies the client code that the requested object is not in the map.
12
 *
13
 * @author Stratadox
14
 */
15
final class IdentityNotFound extends InvalidArgument implements NoSuchObject
16
{
17
    /**
18
     * Produces an exception for when the object is not in the map.
19
     *
20
     * @param string $class     The class of the requested object.
21
     * @param string $id        The identity that is not there.
22
     * @return IdentityNotFound The exception to throw.
23
     */
24
    public static function requesting(string $class, string $id): self
25
    {
26
        return new IdentityNotFound(withMessage(
27
            'The object with id `%s` of class `%s` is not in the identity map.',
28
            $id,
29
            $class
30
        ));
31
    }
32
33
    /**
34
     * Produces an exception for when the object instance is not in the map.
35
     *
36
     * @param object $object    The requested object that is not registered.
37
     * @return IdentityNotFound The exception to throw.
38
     */
39
    public static function forThe(object $object): self
40
    {
41
        return new IdentityNotFound(withMessage(
42
            'The object of class `%s` is not in the identity map.',
43
            theClassOfThe($object)
44
        ));
45
    }
46
}
47