ConnectionException::setBefore()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Silviooosilva\CacheerPhp\Exceptions;
4
5
use Exception;
6
7
class ConnectionException extends BaseException
8
{
9
    private static string $before = "<Connection Exception>";
10
11
    /**
12
     * Creates a new instance of ConnectionException.
13
     * 
14
     * @param string $message
15
     * @param int $code
16
     * @param Exception|null $previous
17
     * @param array $details
18
     * @return self
19
     */
20
    public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = [])
21
    {
22
        return new self(self::getBefore() . ": " . $message, $code, $previous, $details);
23
    }
24
25
    /**
26
     * Gets the static text that will be prepended to the exception message.
27
     *  
28
     * @return string
29
     */
30
    public static function getBefore(): string
31
    {
32
        return self::$before;
33
    }
34
35
    /**
36
     * Sets the static text that will be prepended to the exception message.
37
     * 
38
     * @param string $text
39
     */
40
    public static function setBefore(string $text): void
41
    {
42
        self::$before = $text;
43
    }
44
45
    /*
46
    * Converts the exception to an array representation.
47
    *
48
    * @return array
49
    */
50
    public function toArray()
51
    {
52
        return parent::toArray();
53
    }
54
    
55
    /**
56
    * Converts the exception to a JSON serializable format.
57
    * 
58
    * @return string
59
    */
60
    public function jsonSerialize(): array
61
    {
62
        return parent::jsonSerialize();
63
    }
64
65
    /**
66
    * Converts the exception to a JSON string.
67
    *
68
    * @param int $options
69
    * @return string
70
    */
71
    public function toJson(int $options = 0)
72
    {
73
      return parent::toJson($options);
74
    }
75
}
76