NoSuchClass   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A couldNotLoadCollection() 0 5 1
A couldNotLoad() 0 5 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