Completed
Push — master ( 361c1c...8b1848 )
by Jesse
02:31
created

IdentityNotFound::requesting()   A

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;
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
    public static function forThe(object $object): self
34
    {
35
        return new IdentityNotFound(withMessage(
36
            'The object of class `%s` is not in the identity map.',
37
            get_class($object)
38
        ));
39
    }
40
}
41