Completed
Push — master ( bc7d7f...7a9596 )
by Théo
02:46
created

Exception   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 29
c 0
b 0
f 0
rs 10

2 Methods

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