1 | <?php declare (strict_types=1); |
||
20 | class Builder |
||
21 | { |
||
22 | /** |
||
23 | * The default domain to use for further link documentation. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $docDomain = 'http://docs.php-opencloud.com/en/latest/'; |
||
28 | |||
29 | /** |
||
30 | * The HTTP client required to validate the further links. |
||
31 | * |
||
32 | * @var ClientInterface |
||
33 | */ |
||
34 | private $client; |
||
35 | |||
36 | /** |
||
37 | * @param ClientInterface $client |
||
38 | */ |
||
39 | 2 | public function __construct(ClientInterface $client = null) |
|
43 | |||
44 | /** |
||
45 | * Internal method used when outputting headers in the error description. |
||
46 | * |
||
47 | * @param $name |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 4 | private function header(string $name): string |
|
55 | |||
56 | /** |
||
57 | * Before outputting custom links, it is validated to ensure that the user is not |
||
58 | * directed off to a broken link. If a 404 is detected, it is hidden. |
||
59 | * |
||
60 | * @param $link The proposed link |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | 2 | private function linkIsValid(string $link): bool |
|
74 | |||
75 | /** |
||
76 | 2 | * @param MessageInterface $message |
|
77 | * |
||
78 | 2 | * @codeCoverageIgnore |
|
79 | 2 | * @return string |
|
80 | 2 | */ |
|
81 | 2 | public function str(MessageInterface $message): string |
|
106 | |||
107 | /** |
||
108 | * Helper method responsible for constructing and returning {@see BadResponseError} exceptions. |
||
109 | * |
||
110 | 2 | * @param RequestInterface $request The faulty request |
|
111 | * @param ResponseInterface $response The error-filled response |
||
112 | 2 | * |
|
113 | * @return BadResponseError |
||
114 | 2 | */ |
|
115 | 2 | public function httpError(RequestInterface $request, ResponseInterface $response): BadResponseError |
|
140 | 2 | ||
141 | 2 | private function getStatusCodeMessage(int $statusCode): string |
|
152 | |||
153 | /** |
||
154 | * Helper method responsible for constructing and returning {@see UserInputError} exceptions. |
||
155 | * |
||
156 | * @param string $expectedType The type that was expected from the user |
||
157 | 2 | * @param mixed $userValue The incorrect value the user actually provided |
|
158 | * @param string|null $furtherLink A link to further information if necessary (optional). |
||
159 | 2 | * |
|
160 | * @return UserInputError |
||
161 | 2 | */ |
|
162 | 2 | public function userInputError(string $expectedType, $userValue, string $furtherLink = null): UserInputError |
|
179 | } |
||
180 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: