ControlledError.php$0 ➔ __construct()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
cc 2
crap 6
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
It seems like $category can also be of type string; however, parameter $category of anonymous//src/Exception...or.php$0::__construct() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
        return new class($message, $code, /** @scrutinizer ignore-type */ $category) extends ControlledError
Loading history...
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
Documentation Bug introduced by
Are you sure the doc-type for parameter $category is correct as it would always require null to be passed?
Loading history...
52
             */
53
            public function __construct($message, $code, $category = null)
54
            {
55
                if ($category) {
0 ignored issues
show
introduced by
$category is of type null, thus it always evaluated to false.
Loading history...
56
                    $this->category = $category;
57
                }
58
                parent:: __construct($message, $code);
0 ignored issues
show
Bug introduced by
$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 ignore-type  annotation

58
                parent:: __construct($message, /** @scrutinizer ignore-type */ $code);
Loading history...
59
            }
60
61
            /**
62
             * @return string
63
             */
64
            public function getCategory(): string
65
            {
66
                return $this->category ?? parent::getCategory();
67
            }
68
        };
69
    }
70
}
71