Completed
Push — master ( bc7d7f...7a9596 )
by Théo
02:46
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
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 3
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\Exception;
16
17
/**
18
 * Provides additional functional to the Exception class.
19
 *
20
 * @author Kevin Herrera <[email protected]>
21
 */
22
class Exception extends \Exception implements ExceptionInterface
23
{
24
    /**
25
     * Creates a new exception using a format and values.
26
     *
27
     * @param string $format    the format
28
     * @param mixed  $value,... The value(s).
29
     *
30
     * @return Exception the exception
31
     */
32
    public static function create($format, $value = null)
33
    {
34
        if (0 < func_num_args()) {
35
            $format = vsprintf($format, array_slice(func_get_args(), 1));
36
        }
37
38
        return new static($format);
39
    }
40
41
    /**
42
     * Creates an exception for the last error message.
43
     *
44
     * @return Exception the exception
45
     */
46
    public static function lastError()
47
    {
48
        $error = error_get_last();
49
50
        return new static($error['message']);
51
    }
52
}
53