IdentityNotFound   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A requesting() 0 8 1
A forThe() 0 7 1
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