1 | <?php |
||
7 | class ComposerVersionNormalizer { |
||
8 | |||
9 | /** |
||
10 | * Ensures there is a dash in between the version and the stability suffix. |
||
11 | * |
||
12 | * Examples: |
||
13 | * - 1.23RC => 1.23-RC |
||
14 | * - 1.23alpha => 1.23-alpha |
||
15 | * - 1.23alpha3 => 1.23-alpha3 |
||
16 | * - 1.23-beta => 1.23-beta |
||
17 | * |
||
18 | * @param string $version |
||
19 | * |
||
20 | * @return string |
||
21 | * @throws InvalidArgumentException |
||
22 | */ |
||
23 | public function normalizeSuffix( $version ) { |
||
30 | |||
31 | /** |
||
32 | * Ensures the version has four levels. |
||
33 | * Version suffixes are supported, as long as they start with a dash. |
||
34 | * |
||
35 | * Examples: |
||
36 | * - 1.19 => 1.19.0.0 |
||
37 | * - 1.19.2.3 => 1.19.2.3 |
||
38 | * - 1.19-alpha => 1.19.0.0-alpha |
||
39 | * - 1337 => 1337.0.0.0 |
||
40 | * |
||
41 | * @param string $version |
||
42 | * |
||
43 | * @return string |
||
44 | * @throws InvalidArgumentException |
||
45 | */ |
||
46 | public function normalizeLevelCount( $version ) { |
||
66 | } |
||
67 |
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: