1 | <?php |
||
24 | class ProfileSearchQuery implements HttpQuery |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $identityId; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $actorId; |
||
35 | |||
36 | /** |
||
37 | * @param string $identityId |
||
38 | * @param string $actorId |
||
39 | */ |
||
40 | public function __construct($identityId, $actorId) |
||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getIdentityId() |
||
53 | |||
54 | /** |
||
55 | * @param string $actorId |
||
56 | * @return ProfileSearchQuery |
||
57 | */ |
||
58 | public function setActorId($actorId) |
||
66 | |||
67 | /** |
||
68 | * @param string $identityId |
||
69 | * @return ProfileSearchQuery |
||
70 | */ |
||
71 | public function setIdentityId($identityId) |
||
79 | |||
80 | private function assertNonEmptyString($value, $name) |
||
81 | { |
||
82 | $message = sprintf( |
||
83 | '"%s" must be a non-empty string, "%s" given', |
||
84 | $name, |
||
85 | (is_object($value) ? get_class($value) : gettype($value)) |
||
86 | ); |
||
87 | |||
88 | Assert\that($value)->string($message)->notEmpty($message); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | public function toHttpQuery() |
||
102 | } |
||
103 |
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: