1 | <?php |
||
23 | class CsvDeserializationVisitor extends AbstractDeserializationVisitor |
||
24 | { |
||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $delimiter; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $enclosure; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $escapeChar; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $keySeparator; |
||
44 | |||
45 | /** |
||
46 | * @param InstantiatorInterface $instantiator |
||
47 | * @param MutatorInterface $mutator |
||
48 | * @param string $delimiter |
||
49 | * @param string $enclosure |
||
50 | * @param string $escapeChar |
||
51 | * @param string $keySeparator |
||
52 | */ |
||
53 | 984 | public function __construct( |
|
54 | InstantiatorInterface $instantiator, |
||
55 | MutatorInterface $mutator, |
||
56 | $delimiter = ',', |
||
57 | $enclosure = '"', |
||
58 | $escapeChar = '\\', |
||
59 | $keySeparator = '.' |
||
60 | ) { |
||
61 | 984 | parent::__construct($instantiator, $mutator); |
|
62 | |||
63 | 984 | $this->delimiter = $delimiter; |
|
64 | 984 | $this->enclosure = $enclosure; |
|
65 | 984 | $this->escapeChar = $escapeChar; |
|
66 | 984 | $this->keySeparator = $keySeparator; |
|
67 | 984 | } |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 18 | public function visitArray($data, TypeMetadataInterface $type, ContextInterface $context) |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 99 | protected function decode($data) |
|
136 | |||
137 | /** |
||
138 | * @param string[] $paths |
||
139 | * @param mixed $data |
||
140 | * @param mixed[] $result |
||
141 | */ |
||
142 | 75 | private function expand(array $paths, $data, array &$result) |
|
156 | } |
||
157 |
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: