forked from danog/MadelineProto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventHandlerIssue.php
62 lines (55 loc) · 2.14 KB
/
EventHandlerIssue.php
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
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <[email protected]>
* @copyright 2016-2023 Daniil Gentili <[email protected]>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto;
/**
* Represents an event handler issue.
*/
final class EventHandlerIssue
{
public function __construct(
/** Issue message */
public readonly string $message,
/** Issue file */
public readonly string $file,
/** Issue line */
public readonly int $line,
/** Whether the issue is severe enough to block inclusion */
public readonly bool $severe,
) {
}
public function __toString(): string
{
return sprintf(
Lang::$current_lang[$this->severe ? 'static_analysis_severe' : 'static_analysis_minor'],
"{$this->file}:{$this->line}",
$this->message
);
}
public function log(): void
{
Logger::log((string) $this, $this->severe ? Logger::FATAL_ERROR : Logger::ERROR);
}
public function getHTML(): string
{
$issueStr = htmlentities((string) $this);
$color = $this->severe ? 'red' : 'orange';
$warning = "<h2 style='color:$color;'>{$issueStr}</h2>";
return $warning;
}
public function throw(): void
{
throw new Exception(message: (string) $this, file: $this->file, line: $this->line);
}
}