DuplicationDetected::in()   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 InvalidArgumentException as InvalidArgument;
7
use function sprintf as withMessage;
8
9
final class DuplicationDetected extends InvalidArgument implements AlreadyThere
10
{
11
    /**
12
     * Produces an exception for when the object is already in the map.
13
     *
14
     * @param string $class The class of the proposed object.
15
     * @param string $id    The identity that is already there.
16
     * @return AlreadyThere The exception to throw.
17
     */
18
    public static function in(string $class, string $id): AlreadyThere
19
    {
20
        return new DuplicationDetected(withMessage(
21
            'The object with id `%s` of class `%s` is already in the identity map.',
22
            $id,
23
            $class
24
        ));
25
    }
26
}
27