| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class represents an enum of severity levels an event can be associated |
| 8 |
* to. |
| 9 |
* |
| 10 |
* @author Stefano Arlandini <[email protected]> |
| 11 |
*/ |
| 12 |
final class Severity implements \Stringable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* This constant represents the "debug" severity level. |
| 16 |
* |
| 17 |
* @internal |
| 18 |
*/ |
| 19 |
public const DEBUG = 'debug'; |
| 20 |
/** |
| 21 |
* This constant represents the "info" severity level. |
| 22 |
* |
| 23 |
* @internal |
| 24 |
*/ |
| 25 |
public const INFO = 'info'; |
| 26 |
/** |
| 27 |
* This constant represents the "warning" severity level. |
| 28 |
* |
| 29 |
* @internal |
| 30 |
*/ |
| 31 |
public const WARNING = 'warning'; |
| 32 |
/** |
| 33 |
* This constant represents the "error" severity level. |
| 34 |
* |
| 35 |
* @internal |
| 36 |
*/ |
| 37 |
public const ERROR = 'error'; |
| 38 |
/** |
| 39 |
* This constant represents the "fatal" severity level. |
| 40 |
* |
| 41 |
* @internal |
| 42 |
*/ |
| 43 |
public const FATAL = 'fatal'; |
| 44 |
/** |
| 45 |
* This constant contains the list of allowed enum values. |
| 46 |
* |
| 47 |
* @internal |
| 48 |
*/ |
| 49 |
public const ALLOWED_SEVERITIES = [self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::FATAL]; |
| 50 |
/** |
| 51 |
* @var string The value of this enum instance |
| 52 |
*/ |
| 53 |
private $value; |
| 54 |
/** |
| 55 |
* Constructor. |
| 56 |
* |
| 57 |
* @param string $value The value this instance represents |
| 58 |
*/ |
| 59 |
public function __construct(string $value = self::INFO) |
| 60 |
{ |
| 61 |
if (!\in_array($value, self::ALLOWED_SEVERITIES, \true)) { |
| 62 |
throw new \InvalidArgumentException(\sprintf('The "%s" is not a valid enum value.', $value)); |
| 63 |
} |
| 64 |
$this->value = $value; |
| 65 |
} |
| 66 |
/** |
| 67 |
* Translate a PHP Error constant into a Sentry log level group. |
| 68 |
* |
| 69 |
* @param int $severity PHP E_* error constant |
| 70 |
*/ |
| 71 |
public static function fromError(int $severity) : self |
| 72 |
{ |
| 73 |
switch ($severity) { |
| 74 |
case \E_DEPRECATED: |
| 75 |
case \E_USER_DEPRECATED: |
| 76 |
case \E_WARNING: |
| 77 |
case \E_USER_WARNING: |
| 78 |
return self::warning(); |
| 79 |
case \E_ERROR: |
| 80 |
case \E_PARSE: |
| 81 |
case \E_CORE_ERROR: |
| 82 |
case \E_CORE_WARNING: |
| 83 |
case \E_COMPILE_ERROR: |
| 84 |
case \E_COMPILE_WARNING: |
| 85 |
return self::fatal(); |
| 86 |
case \E_RECOVERABLE_ERROR: |
| 87 |
case \E_USER_ERROR: |
| 88 |
return self::error(); |
| 89 |
case \E_NOTICE: |
| 90 |
case \E_USER_NOTICE: |
| 91 |
case 2048: |
| 92 |
// This is \E_STRICT which has been deprecated in PHP 8.4 so we should not reference it directly to prevent deprecation notices |
| 93 |
return self::info(); |
| 94 |
default: |
| 95 |
return self::error(); |
| 96 |
} |
| 97 |
} |
| 98 |
/** |
| 99 |
* Creates a new instance of this enum for the "debug" value. |
| 100 |
*/ |
| 101 |
public static function debug() : self |
| 102 |
{ |
| 103 |
return new self(self::DEBUG); |
| 104 |
} |
| 105 |
/** |
| 106 |
* Creates a new instance of this enum for the "info" value. |
| 107 |
*/ |
| 108 |
public static function info() : self |
| 109 |
{ |
| 110 |
return new self(self::INFO); |
| 111 |
} |
| 112 |
/** |
| 113 |
* Creates a new instance of this enum for the "warning" value. |
| 114 |
*/ |
| 115 |
public static function warning() : self |
| 116 |
{ |
| 117 |
return new self(self::WARNING); |
| 118 |
} |
| 119 |
/** |
| 120 |
* Creates a new instance of this enum for the "error" value. |
| 121 |
*/ |
| 122 |
public static function error() : self |
| 123 |
{ |
| 124 |
return new self(self::ERROR); |
| 125 |
} |
| 126 |
/** |
| 127 |
* Creates a new instance of this enum for the "fatal" value. |
| 128 |
*/ |
| 129 |
public static function fatal() : self |
| 130 |
{ |
| 131 |
return new self(self::FATAL); |
| 132 |
} |
| 133 |
/** |
| 134 |
* Returns whether two object instances of this class are equal. |
| 135 |
* |
| 136 |
* @param self $other The object to compare |
| 137 |
*/ |
| 138 |
public function isEqualTo(self $other) : bool |
| 139 |
{ |
| 140 |
return $this->value === (string) $other; |
| 141 |
} |
| 142 |
/** |
| 143 |
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.tostring |
| 144 |
*/ |
| 145 |
public function __toString() : string |
| 146 |
{ |
| 147 |
return $this->value; |
| 148 |
} |
| 149 |
} |
| 150 |
|