1 | <?php |
||||
2 | /******************************************************************************* |
||||
3 | * This file is part of the GraphQL Bundle package. |
||||
4 | * |
||||
5 | * (c) YnloUltratech <[email protected]> |
||||
6 | * |
||||
7 | * For the full copyright and license information, please view the LICENSE |
||||
8 | * file that was distributed with this source code. |
||||
9 | ******************************************************************************/ |
||||
10 | |||||
11 | namespace Ynlo\GraphQLBundle\Exception; |
||||
12 | |||||
13 | use GraphQL\Error\UserError; |
||||
14 | |||||
15 | abstract class ControlledError extends UserError implements ControlledErrorInterface |
||||
16 | { |
||||
17 | /** |
||||
18 | * @var string |
||||
19 | */ |
||||
20 | protected $description; |
||||
21 | |||||
22 | /** |
||||
23 | * @return string |
||||
24 | */ |
||||
25 | public function getDescription(): ?string |
||||
26 | { |
||||
27 | return $this->description; |
||||
28 | } |
||||
29 | |||||
30 | /** |
||||
31 | * Throw a controlled error dynamically |
||||
32 | * |
||||
33 | * @param int|string $code |
||||
34 | * @param string $message |
||||
35 | * @param string|null $category |
||||
36 | * |
||||
37 | * @return ControlledError |
||||
38 | */ |
||||
39 | public static function create($code, $message = null, $category = null) |
||||
40 | { |
||||
41 | return new class($message, $code, $category) extends ControlledError |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
42 | { |
||||
43 | /** |
||||
44 | * @var string |
||||
45 | */ |
||||
46 | protected $category; |
||||
47 | |||||
48 | /** |
||||
49 | * @param string $message |
||||
50 | * @param string $code |
||||
51 | * @param null $category |
||||
0 ignored issues
–
show
|
|||||
52 | */ |
||||
53 | public function __construct($message, $code, $category = null) |
||||
54 | { |
||||
55 | if ($category) { |
||||
0 ignored issues
–
show
|
|||||
56 | $this->category = $category; |
||||
57 | } |
||||
58 | parent:: __construct($message, $code); |
||||
0 ignored issues
–
show
$code of type string is incompatible with the type integer expected by parameter $code of Exception::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * @return string |
||||
63 | */ |
||||
64 | public function getCategory(): string |
||||
65 | { |
||||
66 | return $this->category ?? parent::getCategory(); |
||||
67 | } |
||||
68 | }; |
||||
69 | } |
||||
70 | } |
||||
71 |