-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWarning.php
More file actions
74 lines (60 loc) · 1.58 KB
/
Copy pathWarning.php
File metadata and controls
74 lines (60 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Dbal;
use Stringable;
use function in_array;
use function is_numeric;
use function is_string;
/**
* @see https://mariadb.com/kb/en/show-warnings/
* @see https://dev.mysql.com/doc/refman/en/show-warnings.html
*
* @psalm-immutable
*/
final class Warning implements Stringable
{
/**
* @var string
* @psalm-var 'Note'|'Warning'|'Error'|'?'
*/
public $level;
/**
* @var int
* @psalm-var 0|positive-int
*/
public $code;
/** @var string */
public $message;
private function __construct(string $level, int $code, string $message)
{
$this->level = in_array($level, ['Note', 'Warning', 'Error'], true) ? $level : '?';
$this->code = $code >= 1 ? $code : 0;
$this->message = $message;
}
/**
* @param mixed[] $row
*/
public static function fromArray(array $row): self
{
$level = '';
$code = 0;
$message = '';
if (isset($row['Level']) && is_string($row['Level'])) {
$level = $row['Level'];
}
if (isset($row['Code']) && is_numeric($row['Code'])) {
$code = (int) $row['Code'];
}
if (isset($row['Message']) && is_string($row['Message'])) {
$message = $row['Message'];
}
return new self($level, $code, $message);
}
/**
* @psalm-return non-empty-string
*/
public function __toString(): string
{
return $this->level . ': #' . $this->code . ($this->message !== '' ? ' ' . $this->message : '');
}
}