@@ -71,7 +71,7 @@ class OpenWeatherMap
7171 /**
7272 * @var string The basic api url to fetch uv index data from.
7373 */
74- private $ uviUrl = 'http://api.openweathermap.org/v3/uvi ' ;
74+ private $ uvIndexUrl = 'http://api.openweathermap.org/v3/uvi ' ;
7575
7676 /**
7777 * @var AbstractCache|bool $cache The cache to use.
@@ -310,7 +310,7 @@ public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $ty
310310 }
311311
312312 /**
313- * Returns the uv index at the location you specified.
313+ * Returns the uv index at date, time and location you specified.
314314 *
315315 * @param float $lat The location's latitude.
316316 * @param float $lon The location's longitude.
@@ -324,9 +324,6 @@ public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $ty
324324 *
325325 * @return UVIndex The uvi object.
326326 *
327- * There are three ways to specify the place to get weather information for:
328- * - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
329- *
330327 * @api
331328 */
332329 public function getUVIndex ($ lat , $ lon , $ dateTime , $ timePrecision = 'day ' )
@@ -495,33 +492,7 @@ public function getRawUVIndexData($lat, $lon, $dateTime, $timePrecision = 'day')
495492 if (interface_exists ('DateTimeInterface ' ) && !$ dateTime instanceof \DateTimeInterface || !$ dateTime instanceof \DateTime) {
496493 throw new \InvalidArgumentException ('$dateTime must be an instance of \DateTime or \DateTimeInterface ' );
497494 }
498- $ format = '\Z ' ;
499- switch ($ timePrecision ) {
500- /** @noinspection PhpMissingBreakStatementInspection */
501- case 'second ' :
502- $ format = ':s ' . $ format ;
503- /** @noinspection PhpMissingBreakStatementInspection */
504- case 'minute ' :
505- $ format = ':i ' . $ format ;
506- /** @noinspection PhpMissingBreakStatementInspection */
507- case 'hour ' :
508- $ format = '\TH ' . $ format ;
509- /** @noinspection PhpMissingBreakStatementInspection */
510- case 'day ' :
511- $ format = '-d ' . $ format ;
512- /** @noinspection PhpMissingBreakStatementInspection */
513- case 'month ' :
514- $ format = '-m ' . $ format ;
515- case 'year ' :
516- $ format = 'Y ' . $ format ;
517- break ;
518- default :
519- throw new \InvalidArgumentException ('$timePrecision is invalid. ' );
520- }
521- // OWM only accepts UTC timezones.
522- $ dateTime ->setTimezone (new \DateTimeZone ('UTC ' ));
523-
524- $ url = sprintf ($ this ->uviUrl . '/%s,%s/%s.json?appid=%s ' , $ lat , $ lon , $ dateTime ->format ($ format ), $ this ->apiKey );
495+ $ url = $ this ->buildUVIndexUrl ($ lat , $ lon , $ dateTime , $ timePrecision );
525496
526497 return $ this ->cacheOrFetchResult ($ url );
527498 }
@@ -593,6 +564,46 @@ private function buildUrl($query, $units, $lang, $appid, $mode, $url)
593564 return $ url ;
594565 }
595566
567+ /**
568+ * @param float $lat
569+ * @param float $lon
570+ * @param \DateTime|\DateTimeImmutable $dateTime
571+ * @param string $timePrecision
572+ *
573+ * @return string
574+ */
575+ private function buildUVIndexUrl ($ lat , $ lon , $ dateTime , $ timePrecision )
576+ {
577+ $ format = '\Z ' ;
578+ switch ($ timePrecision ) {
579+ /** @noinspection PhpMissingBreakStatementInspection */
580+ case 'second ' :
581+ $ format = ':s ' . $ format ;
582+ /** @noinspection PhpMissingBreakStatementInspection */
583+ case 'minute ' :
584+ $ format = ':i ' . $ format ;
585+ /** @noinspection PhpMissingBreakStatementInspection */
586+ case 'hour ' :
587+ $ format = '\TH ' . $ format ;
588+ /** @noinspection PhpMissingBreakStatementInspection */
589+ case 'day ' :
590+ $ format = '-d ' . $ format ;
591+ /** @noinspection PhpMissingBreakStatementInspection */
592+ case 'month ' :
593+ $ format = '-m ' . $ format ;
594+ case 'year ' :
595+ $ format = 'Y ' . $ format ;
596+ break ;
597+ default :
598+ throw new \InvalidArgumentException ('$timePrecision is invalid. ' );
599+ }
600+ // OWM only accepts UTC timezones.
601+ $ dateTime ->setTimezone (new \DateTimeZone ('UTC ' ));
602+
603+ $ url = sprintf ($ this ->uvIndexUrl . '/%s,%s/%s.json?appid=%s ' , $ lat , $ lon , $ dateTime ->format ($ format ), $ this ->apiKey );
604+ return $ url ;
605+ }
606+
596607 /**
597608 * Builds the query string for the url.
598609 *
0 commit comments