These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Thinktomorrow\Locale\Values; |
||
4 | |||
5 | final class Locale |
||
6 | { |
||
7 | /** |
||
8 | * @var string Locale key identifier |
||
9 | */ |
||
10 | private $value; |
||
11 | |||
12 | 82 | private function __construct(string $value) |
|
13 | { |
||
14 | 82 | $this->value = $value; |
|
15 | 82 | } |
|
16 | |||
17 | 82 | public static function from(string $value) |
|
18 | { |
||
19 | 82 | return new static($value); |
|
20 | } |
||
21 | |||
22 | 2 | public function withoutRegion() |
|
23 | { |
||
24 | 2 | if(false !== strpos($this->value, '-')){ |
|
25 | 2 | $value = substr($this->value,0,strpos($this->value, '-')); |
|
26 | 1 | }else if(false !== strpos($this->value, '_')){ |
|
27 | 1 | $value = substr($this->value,0,strpos($this->value, '_')); |
|
28 | } |
||
29 | |||
30 | 2 | return new static($value); |
|
0 ignored issues
–
show
|
|||
31 | } |
||
32 | |||
33 | 69 | public function get(): string |
|
34 | { |
||
35 | 69 | return $this->value; |
|
36 | } |
||
37 | |||
38 | 1 | public function equals(self $other): bool |
|
39 | { |
||
40 | 1 | return get_class($this) === get_class($other) && (string) $this === (string) $other; |
|
41 | } |
||
42 | |||
43 | 69 | public function __toString(): string |
|
44 | { |
||
45 | 69 | return $this->get(); |
|
46 | } |
||
47 | } |
||
48 |
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: