Passed
Pull Request — master (#315)
by Théo
02:34
created

Exception::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Annotation\Exception;
16
17
use Exception as RootException;
18
19
/**
20
 * Provides additional functional to the Exception class.
21
 *
22
 * @author Kevin Herrera <[email protected]>
23
 */
24
class Exception extends RootException implements ExceptionInterface
25
{
26
    /**
27
     * Creates a new exception using a format and values.
28
     *
29
     * @param string $format    the format
30
     * @param mixed  $value,... The value(s).
31
     *
32
     * @return Exception the exception
33
     */
34
    public static function create($format, $value = null): self
35
    {
36
        if (0 < func_num_args()) {
37
            $format = vsprintf($format, array_slice(func_get_args(), 1));
38
        }
39
40
        return new static($format);
41
    }
42
43
    /**
44
     * Creates an exception for the last error message.
45
     *
46
     * @return Exception the exception
47
     */
48
    public static function lastError(): self
49
    {
50
        $error = error_get_last();
51
52
        return new static($error['message']);
53
    }
54
}
55