1 | <?php declare(strict_types=1); |
||
16 | class Explorer |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * @var \FeedIo\Adapter\ClientInterface; |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * @var \Psr\Log\LoggerInterface |
||
26 | */ |
||
27 | protected $logger; |
||
28 | |||
29 | const VALID_TYPES = [ |
||
30 | 'application/atom+xml', |
||
31 | 'application/rss+xml' |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * @param \FeedIo\Adapter\ClientInterface $client |
||
36 | * @param \Psr\Log\LoggerInterface $logger |
||
37 | */ |
||
38 | 1 | public function __construct(ClientInterface $client, LoggerInterface $logger) |
|
43 | |||
44 | /** |
||
45 | * Discover feeds from the webpage's headers |
||
46 | * @param string $url |
||
47 | * @return array |
||
48 | */ |
||
49 | 1 | public function discover(string $url) : array |
|
68 | |||
69 | /** |
||
70 | * Extract feeds Urls from HTML stream |
||
71 | * @param string $html |
||
72 | * @return array |
||
73 | */ |
||
74 | 1 | protected function extractFeeds(string $html) : array |
|
89 | |||
90 | /** |
||
91 | * Tells if the given Element contains a valid Feed Url |
||
92 | * @param DomElement $element |
||
93 | * @return bool |
||
94 | */ |
||
95 | 1 | protected function isFeedLink(\DomElement $element) : bool |
|
100 | } |
||
101 |
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: