SystemException::methodNotExist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tebe\Pvc\Exception;
6
7
use Exception;
8
use Throwable;
9
10
class SystemException extends Exception
11
{
12
13
    /**
14
     * @param string $class
15
     * @param string $format
16
     * @return static
17
     */
18
    public static function classNotExist(string $class, string $format = null): SystemException
19
    {
20
        $format = $format ?? 'Class "%s" does not exist';
21
        $message = sprintf($format, $class);
22
        return new static($message, 500);
23
    }
24
25
    /**
26
     * @param string $method
27
     * @param string $format
28
     * @return static
29
     */
30
    public static function methodNotExist(string $method, string $format = null): SystemException
31
    {
32
        $format = $format ?? 'Method "%s" does not exist';
33
        $message = sprintf($format, $method);
34
        return new static($message, 500);
35
    }
36
37
    /**
38
     * @param string $filepath
39
     * @param string $format
40
     * @return static
41
     */
42
    public static function includeFileNotExist(string $filepath, string $format = null): SystemException
43
    {
44
        $format = $format ?? 'Include file "%s" does not exist';
45
        $message = sprintf($format, $filepath);
46
        return new static($message, 500);
47
    }
48
49
    /**
50
     * @param string $directory
51
     * @param string $format
52
     * @return static
53
     */
54
    public static function directoryNotExist(string $directory, string $format = null): SystemException
55
    {
56
        $format = $format ?? 'Directory "%s" does not exist';
57
        $message = sprintf($format, $directory);
58
        return new static($message, 500);
59
    }
60
61
    /**
62
     * @param string $file
63
     * @param string $format
64
     * @return static
65
     */
66
    public static function fileNotExist(string $file, string $format = null): SystemException
67
    {
68
        $format = $format ?? 'File "%s" does not exist';
69
        $message = sprintf($format, $file);
70
        return new static($message, 500);
71
    }
72
73
    /**
74
     * @param string $message
75
     * @param Throwable $t
76
     * @return static
77
     */
78
    public static function serverError(string $message, Throwable $t = null): SystemException
79
    {
80
        return new static($message, 500, $t);
81
    }
82
}
83