Skip to content

Commit 5e51e4a

Browse files
committed
Adjust changes by Peter Lee.
1 parent f59cb94 commit 5e51e4a

20 files changed

+1572
-432
lines changed

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@ php:
88
- 5.5
99
- 5.6
1010
- 7.0
11+
- 7.1
1112
- nightly
13+
- hhvm
1214

1315
matrix:
1416
fast_finish: true
1517
allow_failures:
1618
- php: nightly
1719

1820
before_install:
19-
- phpenv config-rm xdebug.ini
21+
- if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then phpenv config-rm xdebug.ini || echo "xdebug not available"; fi
2022

2123
install:
22-
- mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d && echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
23-
- mkdir -p build/logs
24-
- composer global require satooshi/php-coveralls:@stable --no-update
25-
- composer global update --prefer-dist --no-interaction
26-
- composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
27-
28-
before_script:
29-
- echo "zend_extension=xdebug.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
24+
- if [[ ! $TRAVIS_PHP_VERSION = hhvm* ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi
25+
- echo date.timezone = Europe/Berlin >> $INI_FILE
26+
- echo memory_limit = -1 >> $INI_FILE
27+
- composer update
3028

3129
script:
32-
- vendor/bin/phpunit
30+
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
3331

3432
after_success:
33+
# Scrutinizer
34+
- wget https://scrutinizer-ci.com/ocular.phar
35+
- php ocular.phar code-coverage:upload --format=php-clover coverage.xml
36+
# CodeCov
3537
- bash <(curl -s https://codecov.io/bash)

Cmfcmf/OpenWeatherMap.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ public function __construct($apiKey = '', $fetcher = null, $cache = false, $seco
119119
}
120120

121121
if ($cache !== false && !($cache instanceof AbstractCache)) {
122-
throw new \Exception('The cache class must implement the FetcherInterface!');
122+
throw new \InvalidArgumentException('The cache class must implement the FetcherInterface!');
123123
}
124124
if (!is_numeric($seconds)) {
125-
throw new \Exception('$seconds must be numeric.');
125+
throw new \InvalidArgumentException('$seconds must be numeric.');
126126
}
127127
if (!isset($fetcher)) {
128128
$fetcher = (function_exists('curl_version')) ? new CurlFetcher() : new FileGetContentsFetcher();
@@ -545,8 +545,8 @@ private function parseXML($answer)
545545
// Invalid xml format. This happens in case OpenWeatherMap returns an error.
546546
// OpenWeatherMap always uses json for errors, even if one specifies xml as format.
547547
$error = json_decode($answer, true);
548-
if (json_last_error() !== JSON_ERROR_NONE) {
549-
throw new OWMException('OpenWeatherMap returned an invalid json object: ' . json_last_error());
548+
if (isset($error['message'])) {
549+
throw new OWMException($error['message'], isset($error['cod']) ? $error['cod'] : 0);
550550
} else {
551551
throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer);
552552
}
@@ -563,9 +563,28 @@ private function parseJson($answer)
563563
{
564564
$json = json_decode($answer);
565565
if (json_last_error() !== JSON_ERROR_NONE) {
566-
throw new OWMException('OpenWeatherMap returned an invalid json object: ' . json_last_error());
566+
throw new OWMException('OpenWeatherMap returned an invalid json object. JSON error was: ' . $this->json_last_error_msg());
567567
}
568568

569569
return $json;
570570
}
571+
572+
private function json_last_error_msg()
573+
{
574+
if (function_exists('json_last_error_msg')) {
575+
return json_last_error_msg();
576+
}
577+
578+
static $ERRORS = array(
579+
JSON_ERROR_NONE => 'No error',
580+
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
581+
JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
582+
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
583+
JSON_ERROR_SYNTAX => 'Syntax error',
584+
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
585+
);
586+
587+
$error = json_last_error();
588+
return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error';
589+
}
571590
}

Cmfcmf/OpenWeatherMap/AbstractCache.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ abstract public function getCached($url);
5757
*/
5858
abstract public function setCached($url, $content);
5959

60-
/**
61-
* Specify the cached weather data file path.
62-
*
63-
* @param string $path The cached file path.
64-
*
65-
* @return void.
66-
*/
67-
abstract public function setTempPath($path);
68-
6960
/**
7061
* Set after how much seconds the cache shall expire.
7162
*

Cmfcmf/OpenWeatherMap/WeatherHistory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public function __construct($weatherHistory, $query)
7575

7676
$utctz = new \DateTimeZone('UTC');
7777
foreach ($weatherHistory['list'] as $history) {
78-
if (isset($history['city'])) {
79-
continue;
80-
}
8178
if (isset($history['rain'])) {
8279
$units = array_keys($history['rain']);
8380
} else {

Examples/Cache.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ class ExampleCache extends AbstractCache
2929
{
3030
protected $tmp;
3131

32+
public function __construct()
33+
{
34+
$this->tmp = sys_get_temp_dir();
35+
}
36+
3237
private function urlToPath($url)
3338
{
34-
$tmp = $this->tmp;
35-
$dir = $tmp . DIRECTORY_SEPARATOR . "OpenWeatherMapPHPAPI";
39+
$dir = $this->tmp . DIRECTORY_SEPARATOR . "OpenWeatherMapPHPAPI";
3640
if (!is_dir($dir)) {
3741
mkdir($dir);
3842
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This library is neither maintained by OpenWeatherMap nor their official PHP API.
77

88
[![Build Status](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api.png?branch=master)](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api)
99
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/quality-score.png?s=f31ca08aa8896416cf162403d34362f0a5da0966)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/)
10+
[![codecov](https://codecov.io/gh/cmfcmf/OpenWeatherMap-PHP-Api/branch/master/graph/badge.svg)](https://codecov.io/gh/cmfcmf/OpenWeatherMap-PHP-Api)
1011
[![Code Coverage](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/?branch=master)
1112
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104/big.png)](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104)
1213

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"source": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git"
1818
},
1919
"require": {
20-
"php": ">=5.3.0",
21-
"ext-curl": "*"
20+
"php": ">=5.3.0"
2221
},
2322
"require-dev": {
2423
"phpunit/phpunit": "^4.8 || ^5.0.5"

0 commit comments

Comments
 (0)