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

IdentityNotFound   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

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;
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