Skip to content

Commit 58506e3

Browse files
committed
Reformatted code (PSR-2)
1 parent 7c4878a commit 58506e3

16 files changed

+99
-88
lines changed

Cmfcmf/OpenWeatherMap.php

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OpenWeatherMap
3535
* @var string $weatherUrl The basic api url to fetch weather data from.
3636
*/
3737
private $weatherUrl = "http://api.openweathermap.org/data/2.5/weather?";
38-
38+
3939
/**
4040
* @var string $url The basic api url to fetch weekly forecast data from.
4141
*/
@@ -101,7 +101,7 @@ public function __construct($fetcher = null, $cacheClass = false, $seconds = 600
101101
if ($seconds == 0) {
102102
$cacheClass = false;
103103
}
104-
104+
105105
$this->cacheClass = $cacheClass;
106106
$this->seconds = $seconds;
107107
$this->fetcher = $fetcher;
@@ -156,7 +156,7 @@ public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '
156156

157157
try {
158158
$xml = new \SimpleXMLElement($answer);
159-
} catch(\Exception $e) {
159+
} catch (\Exception $e) {
160160
// Invalid xml format. This happens in case OpenWeatherMap returns an error.
161161
// OpenWeatherMap always uses json for errors, even if one specifies xml as format.
162162
$error = json_decode($answer, true);
@@ -166,6 +166,7 @@ public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '
166166
throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer);
167167
}
168168
}
169+
169170
return new CurrentWeather($xml, $units);
170171
}
171172

@@ -225,7 +226,7 @@ public function getWeatherForecast($query, $units = 'imperial', $lang = 'en', $a
225226

226227
try {
227228
$xml = new \SimpleXMLElement($answer);
228-
} catch(\Exception $e) {
229+
} catch (\Exception $e) {
229230
// Invalid xml format. This happens in case OpenWeatherMap returns an error.
230231
// OpenWeatherMap always uses json for errors, even if one specifies xml as format.
231232
$error = json_decode($answer, true);
@@ -295,23 +296,23 @@ public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $ty
295296

296297
return new WeatherHistory($xml, $query);
297298
}
298-
299+
299300
/**
300301
* @deprecated Use {@link self::getRawWeatherData()} instead.
301302
*/
302303
public function getRawData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml')
303304
{
304-
return $this->getRawWeatherData($query, $units, $lang, $appid, $mode );
305+
return $this->getRawWeatherData($query, $units, $lang, $appid, $mode);
305306
}
306-
307+
307308
/**
308309
* Directly returns the xml/json/html string returned by OpenWeatherMap for the current weather.
309310
*
310311
* @param array|int|string $query The place to get weather information for. For possible values see below.
311-
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
312-
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
313-
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
314-
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
312+
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
313+
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
314+
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
315+
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
315316
*
316317
* @return string Returns false on failure and the fetched data in the format you specified on success.
317318
*
@@ -354,10 +355,10 @@ public function getRawWeatherData($query, $units = 'imperial', $lang = 'en', $ap
354355
* Directly returns the xml/json/html string returned by OpenWeatherMap for the hourly forecast.
355356
*
356357
* @param array|int|string $query The place to get weather information for. For possible values see below.
357-
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
358-
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
359-
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
360-
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
358+
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
359+
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
360+
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
361+
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
361362
*
362363
* @return string Returns false on failure and the fetched data in the format you specified on success.
363364
*
@@ -400,10 +401,10 @@ public function getRawHourlyForecastData($query, $units = 'imperial', $lang = 'e
400401
* Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast.
401402
*
402403
* @param array|int|string $query The place to get weather information for. For possible values see below.
403-
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
404-
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
405-
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
406-
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
404+
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
405+
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
406+
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
407+
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
407408
*
408409
* @return string Returns false on failure and the fetched data in the format you specified on success.
409410
*
@@ -438,7 +439,7 @@ public function getRawHourlyForecastData($query, $units = 'imperial', $lang = 'e
438439
public function getRawDailyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml')
439440
{
440441
$url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherDailyForecastUrl);
441-
442+
442443
return $this->cacheOrFetchResult('dailyForecast', $query, $units, $lang, $mode, $url);
443444
}
444445

@@ -449,7 +450,7 @@ public function getRawDailyForecastData($query, $units = 'imperial', $lang = 'en
449450
* @param \DateTime $start The \DateTime object of the date to get the first weather information from.
450451
* @param \DateTime|int $endOrCount Can be either a \DateTime object representing the end of the period to
451452
* receive weather history data for or an integer counting the number of
452-
* reports requested.
453+
* reports requested.
453454
* @param string $type The period of the weather history requested. Can be either be either "tick",
454455
* "hour" or "day".
455456
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
@@ -547,11 +548,11 @@ private function cacheOrFetchResult($type, $query, $units, $lang, $mode, $url)
547548
/**
548549
* Build the url to fetch weather data from.
549550
*
550-
* @param $query
551-
* @param $units
552-
* @param $lang
553-
* @param $appid
554-
* @param $mode
551+
* @param $query
552+
* @param $units
553+
* @param $lang
554+
* @param $appid
555+
* @param $mode
555556
* @param string $url The url to prepend.
556557
*
557558
* @return bool|string The fetched url, false on failure.
@@ -566,7 +567,7 @@ private function buildUrl($query, $units, $lang, $appid, $mode, $url)
566567
if (!empty($appid)) {
567568
$url .= "&APPID=$appid";
568569
}
569-
570+
570571
return $url;
571572
}
572573

@@ -582,7 +583,7 @@ private function buildUrl($query, $units, $lang, $appid, $mode, $url)
582583
*/
583584
private function buildQueryUrlParameter($query)
584585
{
585-
switch($query) {
586+
switch ($query) {
586587
case (is_array($query) && isset($query['lat']) && isset($query['lon']) && is_numeric($query['lat']) && is_numeric($query['lon'])):
587588
return "lat={$query['lat']}&lon={$query['lon']}";
588589
case (is_numeric($query)):

Cmfcmf/OpenWeatherMap/AbstractCache.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ abstract class AbstractCache
2929
/**
3030
* Checks whether a cached weather data is available.
3131
*
32-
* @param string $type The type of the cached data. Can be either 'weather', 'hourlyForecast' or 'dailyForecast'.
32+
* @param string $type The type of the cached data. Can be either 'weather', 'hourlyForecast' or 'dailyForecast'.
3333
* @param array|int|string $query The query parameters used.
34-
* @param string $units The units requested.
35-
* @param string $lang The language requested.
36-
* @param string $mode The mode requested ('xml' or'json').
34+
* @param string $units The units requested.
35+
* @param string $lang The language requested.
36+
* @param string $mode The mode requested ('xml' or'json').
3737
*
3838
* @return \DateTime|bool A \DateTime object containing the time when the weather information was last updated, false if no
3939
* cached information is available.
@@ -46,11 +46,11 @@ public abstract function isCached($type, $query, $units, $lang, $mode);
4646
/**
4747
* Returns cached weather data.
4848
*
49-
* @param string $type The type of the cached data. Can be either 'weather', 'hourlyForecast' or 'dailyForecast'.
49+
* @param string $type The type of the cached data. Can be either 'weather', 'hourlyForecast' or 'dailyForecast'.
5050
* @param array|int|string $query The query parameters used.
51-
* @param string $units The units requested.
52-
* @param string $lang The language requested.
53-
* @param string $mode The mode requested ('xml' or'json').
51+
* @param string $units The units requested.
52+
* @param string $lang The language requested.
53+
* @param string $mode The mode requested ('xml' or'json').
5454
*
5555
* @return string|bool The cached data if it exists, false otherwise.
5656
*/
@@ -59,19 +59,20 @@ public abstract function getCached($type, $query, $units, $lang, $mode);
5959
/**
6060
* Saves cached weather data.
6161
*
62-
* @param string $type The type of the cached data. Can be either 'weather', 'hourlyForecast' or 'dailyForecast'.
63-
* @param string $content The weather data to cache.
62+
* @param string $type The type of the cached data. Can be either 'weather', 'hourlyForecast' or 'dailyForecast'.
63+
* @param string $content The weather data to cache.
6464
* @param array|int|string $query The query parameters used.
65-
* @param string $units The units requested.
66-
* @param string $lang The language requested.
67-
* @param string $mode The mode requested ('xml' or'json').
65+
* @param string $units The units requested.
66+
* @param string $lang The language requested.
67+
* @param string $mode The mode requested ('xml' or'json').
6868
*
6969
* @return bool True on success, false on failure.
7070
*/
7171
public abstract function setCached($type, $content, $query, $units, $lang, $mode);
7272

7373
/**
7474
* Set after how much seconds the cache shall expire.
75+
*
7576
* @param int $seconds
7677
*/
7778
public function setSeconds($seconds)

Cmfcmf/OpenWeatherMap/CurrentWeather.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
namespace Cmfcmf\OpenWeatherMap;
1818

19+
use Cmfcmf\OpenWeatherMap;
1920
use Cmfcmf\OpenWeatherMap\Util\City;
2021
use Cmfcmf\OpenWeatherMap\Util\Sun;
2122
use Cmfcmf\OpenWeatherMap\Util\Temperature;
2223
use Cmfcmf\OpenWeatherMap\Util\Unit;
2324
use Cmfcmf\OpenWeatherMap\Util\Weather as WeatherObj;
2425
use Cmfcmf\OpenWeatherMap\Util\Wind;
25-
use Cmfcmf\OpenWeatherMap;
2626

2727
/**
2828
* Weather class used to hold the current weather data.
@@ -105,7 +105,7 @@ public function __construct($xml, $units)
105105
$windSpeedUnit = 'mph';
106106
}
107107
$this->wind = new Wind(new Unit($xml->wind->speed['value'], $windSpeedUnit, $xml->wind->speed['name']), new Unit($xml->wind->direction['value'], $xml->wind->direction['code'], $xml->wind->direction['name']));
108-
108+
109109
$this->clouds = new Unit($xml->clouds['value'], null, $xml->clouds['name']);
110110
$this->precipitation = new Unit($xml->precipitation['value'], $xml->precipitation['unit'], $xml->precipitation['mode']);
111111
$this->sun = new Sun(new \DateTime($xml->city->sun['rise']), new \DateTime($xml->city->sun['set']));

Cmfcmf/OpenWeatherMap/Fetcher/CurlFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function fetch($url)
3434
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
3535
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
3636
$content = curl_exec($ch);
37-
curl_close( $ch );
37+
curl_close($ch);
3838

3939
return $content;
4040
}

Cmfcmf/OpenWeatherMap/Fetcher/FetcherInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ interface FetcherInterface
3232
*
3333
* @api
3434
*/
35-
public function fetch ($url);
35+
public function fetch($url);
3636
}

Cmfcmf/OpenWeatherMap/Forecast.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
namespace Cmfcmf\OpenWeatherMap;
1818

19+
use Cmfcmf\OpenWeatherMap;
1920
use Cmfcmf\OpenWeatherMap\Util\City;
2021
use Cmfcmf\OpenWeatherMap\Util\Sun;
2122
use Cmfcmf\OpenWeatherMap\Util\Temperature;
2223
use Cmfcmf\OpenWeatherMap\Util\Time;
2324
use Cmfcmf\OpenWeatherMap\Util\Unit;
2425
use Cmfcmf\OpenWeatherMap\Util\Weather as WeatherObj;
2526
use Cmfcmf\OpenWeatherMap\Util\Wind;
26-
use Cmfcmf\OpenWeatherMap;
2727

2828
/**
2929
* Class Forecast.
@@ -37,15 +37,16 @@ class Forecast extends CurrentWeather
3737

3838
/**
3939
* Create a new weather object for forecasts.
40-
* @param \SimpleXMLElement $xml The forecasts xml.
41-
* @param string $units Ths units used.
40+
*
41+
* @param \SimpleXMLElement $xml The forecasts xml.
42+
* @param string $units Ths units used.
4243
*
4344
* @internal
4445
*/
4546
public function __construct($xml, $units)
4647
{
4748
$this->city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country);
48-
49+
4950
if ($units == 'metric') {
5051
$temperatureUnit = "\xB0C";
5152
} else {
@@ -71,7 +72,7 @@ public function __construct($xml, $units)
7172
$this->sun = new Sun(new \DateTime($xml->city->sun['rise']), new \DateTime($xml->city->sun['set']));
7273
$this->weather = new WeatherObj($xml->symbol['number'], $xml->symbol['name'], $xml->symbol['var']);
7374
$this->lastUpdate = new \DateTime($xml->lastupdate['value']);
74-
75+
7576
if (isset($xml['from'])) {
7677
$this->time = new Time($xml['from'], $xml['to']);
7778
} else {

Cmfcmf/OpenWeatherMap/Util/SunTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function testSunSet()
4242
}
4343

4444

45-
4645
private function givenThereIsASunObject($rise, $set)
4746
{
4847
$this->sun = new Sun($rise, $set);

Cmfcmf/OpenWeatherMap/Util/Temperature.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Temperature
3838

3939
/**
4040
* Returns the current temperature as formatted string.
41+
*
4142
* @return string The current temperature as a formatted string.
4243
*/
4344
public function __toString()
@@ -47,6 +48,7 @@ public function __toString()
4748

4849
/**
4950
* Returns the current temperature's unit.
51+
*
5052
* @return string The current temperature's unit.
5153
*/
5254
public function getUnit()
@@ -56,6 +58,7 @@ public function getUnit()
5658

5759
/**
5860
* Returns the current temperature.
61+
*
5962
* @return string The current temperature.
6063
*/
6164
public function getValue()
@@ -65,6 +68,7 @@ public function getValue()
6568

6669
/**
6770
* Returns the current temperature's description.
71+
*
6872
* @return string The current temperature's description.
6973
*/
7074
public function getDescription()
@@ -74,6 +78,7 @@ public function getDescription()
7478

7579
/**
7680
* Returns the current temperature as formatted string.
81+
*
7782
* @return string The current temperature as formatted string.
7883
*/
7984
public function getFormatted()

Cmfcmf/OpenWeatherMap/Util/UnitTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ class UnitTest extends \PHPUnit_Framework_TestCase
2222
private $unit;
2323

2424
const POSITIVE_INT_VALUE = 23;
25+
2526
const POSITIVE_FLOAT_VALUE = 48.23534;
27+
2628
const NEGATIVE_INT_VALUE = -30;
29+
2730
const NEGATIVE_FLOAT_VALUE = -93.45839;
31+
2832
const ZERO_INT_VALUE = 0;
33+
2934
const ZERO_FLOAT_VALUE = 0.0;
3035

3136
public function testGetValueWithPositiveIntValue()

Cmfcmf/OpenWeatherMap/Util/Weather.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Weather
4646
/**
4747
* Create a new weather object.
4848
*
49-
* @param int $id The icon id.
49+
* @param int $id The icon id.
5050
* @param string $description The weather description.
5151
* @param string $icon The icon name.
5252
*

0 commit comments

Comments
 (0)