UnresolvableBuilderException   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 63
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A forType() 0 8 1
1
<?php
2
/**
3
 * Incoming
4
 *
5
 * @author    Trevor Suarez (Rican7)
6
 * @copyright (c) Trevor Suarez
7
 * @link      https://github.com/Rican7/incoming
8
 * @license   MIT
9
 */
10
11
declare(strict_types=1);
12
13
namespace Incoming\Hydrator\Exception;
14
15
use Throwable;
16
use UnexpectedValueException;
17
18
/**
19
 * An exception to be thrown when a builder can't be resolved, whether by
20
 * automatic lookup or not, and usually for a given type.
21
 */
22
class UnresolvableBuilderException extends UnexpectedValueException
23
{
24
25
    /**
26
     * Constants
27
     */
28
29
    /**
30
     * The default exception message.
31
     *
32
     * @var string
33
     */
34
    const DEFAULT_MESSAGE = 'Unable to resolve a builder';
35
36
    /**
37
     * The exception code for when a type is used as the resolver argument.
38
     *
39
     * @var int
40
     */
41
    const CODE_FOR_TYPE = 1;
42
43
    /**
44
     * The message extension (appended to the default message) for when a type
45
     * is used as the builder resolver argument.
46
     *
47
     * @var string
48
     */
49
    const MESSAGE_EXTENSION_FOR_TYPE = ' for the given type `%s`';
50
51
52
    /**
53
     * Properties
54
     */
55
56
    /**
57
     * The exception message.
58
     *
59
     * @var string
60
     */
61
    protected $message = self::DEFAULT_MESSAGE;
62
63
64
    /**
65
     * Methods
66
     */
67
68
    /**
69
     * Create an exception instance for a problem resolving a builder for a
70
     * given type.
71
     *
72
     * @param string $type The type to build.
73
     * @param int $code The exception code.
74
     * @param Throwable|null $previous A previous exception used for chaining.
75
     * @return static The newly created exception.
76
     */
77 9
    public static function forType(
78
        string $type,
79
        int $code = self::CODE_FOR_TYPE,
80
        Throwable $previous = null
81
    ): self {
82 9
        $message = self::DEFAULT_MESSAGE . sprintf(self::MESSAGE_EXTENSION_FOR_TYPE, $type);
83
84 9
        return new static($message, $code, $previous);
85
    }
86
}
87