@@ -51,13 +51,24 @@ class WeatherHistory implements \Iterator
5151 */
5252 private $ position = 0 ;
5353
54- function __construct ($ weatherHistory , $ query )
54+ public function __construct ($ weatherHistory , $ query )
5555 {
56- $ this ->city = new OpenWeatherMap \Util \City ($ weatherHistory ['city_id ' ], (is_string ($ query )) ? $ query : null , (isset ($ query ['lon ' ])) ? $ query ['lon ' ] : null , (isset ($ query ['lat ' ])) ? $ query ['lat ' ] : null , $ weatherHistory ['list ' ][0 ]['city ' ]['country ' ], $ weatherHistory ['list ' ][0 ]['city ' ]['population ' ]);
56+ if (isset ($ weatherHistory ['list ' ][0 ]['city ' ])) {
57+ $ country = $ weatherHistory ['list ' ][0 ]['city ' ]['country ' ];
58+ $ population = $ weatherHistory ['list ' ][0 ]['city ' ]['population ' ];
59+ } else {
60+ $ country = null ;
61+ $ population = null ;
62+ }
63+
64+ $ this ->city = new OpenWeatherMap \Util \City ($ weatherHistory ['city_id ' ], (is_string ($ query )) ? $ query : null , (isset ($ query ['lon ' ])) ? $ query ['lon ' ] : null , (isset ($ query ['lat ' ])) ? $ query ['lat ' ] : null , $ country , $ population );
5765 $ this ->calctime = $ weatherHistory ['calctime ' ];
5866
5967 foreach ($ weatherHistory ['list ' ] as $ history ) {
60- $ units = array_keys ($ history ['rain ' ]);
68+ if (isset ($ history ['rain ' ])) {
69+ $ units = array_keys ($ history ['rain ' ]);
70+ }
71+
6172 $ this ->histories [] = new History (
6273 $ this ->city ,
6374 $ history ['weather ' ][0 ],
@@ -69,7 +80,7 @@ function __construct($weatherHistory, $query)
6980 $ history ['main ' ]['pressure ' ],
7081 $ history ['main ' ]['humidity ' ],
7182 $ history ['clouds ' ]['all ' ],
72- array ('val ' => $ history ['rain ' ][($ units [0 ])], 'unit ' => $ units [0 ]),
83+ isset ( $ history [ ' rain ' ]) ? array ('val ' => $ history ['rain ' ][($ units [0 ])], 'unit ' => $ units [0 ]) : null ,
7384 $ history ['wind ' ],
7485 \DateTime::createFromFormat ('U ' , $ history ['dt ' ])
7586 );
0 commit comments