NoSuchClass::couldNotLoad()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Stratadox\Hydration\Mapper;
5
6
use RuntimeException;
7
use function sprintf as withMessage;
8
use Stratadox\HydrationMapper\InvalidMapperConfiguration as InvalidMapper;
9
10
/**
11
 * Indicates that a class was not found.
12
 *
13
 * @package Stratadox\Hydrate
14
 * @author  Stratadox
15
 */
16
final class NoSuchClass extends RuntimeException implements InvalidMapper
17
{
18
    /**
19
     * Produces an exception for when a class could not be loaded.
20
     *
21
     * @param string $className The name of the class that could not be loaded.
22
     * @return InvalidMapper    The exception object.
23
     */
24
    public static function couldNotLoad(string $className): InvalidMapper
25
    {
26
        return new NoSuchClass(withMessage(
27
            'Could not produce mapping for non-existing class `%s`',
28
            $className
29
        ));
30
    }
31
32
    /**
33
     * Produces an exception for when a container class could not be loaded.
34
     *
35
     * @param string $className The name of the class that could not be loaded.
36
     * @return InvalidMapper    The exception object.
37
     */
38
    public static function couldNotLoadCollection(string $className): InvalidMapper
39
    {
40
        return new NoSuchClass(withMessage(
41
            'Could not produce mapping for non-existing container class `%s`',
42
            $className
43
        ));
44
    }
45
}
46