1 | <?php |
||
28 | class ManagerFactory |
||
29 | { |
||
30 | /** |
||
31 | * @var MetadataCollector |
||
32 | */ |
||
33 | private $metadataCollector; |
||
34 | |||
35 | /** |
||
36 | * @var Converter |
||
37 | */ |
||
38 | private $converter; |
||
39 | |||
40 | /** |
||
41 | * @var LoggerInterface |
||
42 | */ |
||
43 | private $logger; |
||
44 | |||
45 | /** |
||
46 | * @var LoggerInterface |
||
47 | */ |
||
48 | private $tracer; |
||
49 | |||
50 | /** |
||
51 | * @var EventDispatcherInterface |
||
52 | */ |
||
53 | private $eventDispatcher; |
||
54 | |||
55 | /** |
||
56 | * @var Stopwatch |
||
57 | */ |
||
58 | private $stopwatch; |
||
59 | |||
60 | /** |
||
61 | * @param MetadataCollector $metadataCollector Metadata collector service. |
||
62 | * @param Converter $converter Converter service to transform arrays to objects and visa versa. |
||
63 | * @param LoggerInterface $tracer |
||
64 | * @param LoggerInterface $logger |
||
65 | */ |
||
66 | public function __construct($metadataCollector, $converter, $tracer = null, $logger = null) |
||
73 | |||
74 | /** |
||
75 | * @param EventDispatcherInterface $eventDispatcher |
||
76 | */ |
||
77 | public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) |
||
81 | |||
82 | /** |
||
83 | * @param Stopwatch $stopwatch |
||
84 | */ |
||
85 | public function setStopwatch(Stopwatch $stopwatch) |
||
89 | |||
90 | /** |
||
91 | * Factory function to create a manager instance. |
||
92 | * |
||
93 | * @param string $managerName Manager name. |
||
94 | * @param array $connection Connection configuration. |
||
95 | * @param array $analysis Analyzers, filters and tokenizers config. |
||
96 | * @param array $managerConfig Manager configuration. |
||
97 | * |
||
98 | * @return Manager |
||
99 | */ |
||
100 | public function createManager($managerName, $connection, $analysis, $managerConfig) |
||
170 | } |
||
171 |
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: