1 | <?php |
||
7 | class GoogleBooks |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $baseUri = 'https://www.googleapis.com/books/v1/'; |
||
13 | |||
14 | /** |
||
15 | * @var integer (Number of results to retrieve per batch, between 1 and 40) |
||
16 | */ |
||
17 | protected $batchSize = 40; |
||
18 | |||
19 | /** |
||
20 | * @var Client |
||
21 | */ |
||
22 | protected $http; |
||
23 | |||
24 | /** |
||
25 | * @var key string API key |
||
26 | */ |
||
27 | protected $key; |
||
28 | |||
29 | /** |
||
30 | * @var country string 2 letter ISO 639 country code. |
||
31 | * |
||
32 | * The Books API must honor copyright laws from various countries, and have |
||
33 | * country-specific rights from publishers. It uses the IP address of the |
||
34 | * client to geo-locate the user, but if this fails for some reason, it will |
||
35 | * return 403 Forbidden with reason "unknownLocation". To avoid this, we can |
||
36 | * manually set the country code. |
||
37 | */ |
||
38 | protected $country; |
||
39 | |||
40 | /** |
||
41 | * @var Volumes |
||
42 | */ |
||
43 | public $volumes; |
||
44 | |||
45 | /** |
||
46 | * @var Bookshelves |
||
47 | */ |
||
48 | public $bookshelves; |
||
49 | |||
50 | public function __construct($options = []) |
||
65 | |||
66 | protected function raw($endpoint, $params = [], $method='GET') |
||
104 | |||
105 | public function getItem($path) |
||
109 | |||
110 | public function listItems($endpoint, $params = []) |
||
131 | |||
132 | } |
||
133 |
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: