diff --git a/.gitignore b/.gitignore index ccb5c20..95d08c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ vendor composer.lock .DS_Store -coverage \ No newline at end of file +build diff --git a/.travis.yml b/.travis.yml index e046be0..0628c5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,11 @@ php: - '5.5' - '5.6' - '7.0' +install: + - mkdir -p build/logs before_script: - composer self-update - composer install --prefer-source --no-interaction --dev -script: phpunit +script: ./bin/test +after_success: + - travis_retry ./vendor/bin/test-reporter diff --git a/README.md b/README.md index 5bda851..a03a374 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Ziptastic PHP +[![Build Status](https://travis-ci.org/Ziptastic/ziptastic-php.svg)](https://travis-ci.org/Ziptastic/ziptastic-php) [![Code Climate](https://codeclimate.com/github/Ziptastic/ziptastic-php/badges/gpa.svg)](https://codeclimate.com/github/Ziptastic/ziptastic-php) [![Test Coverage](https://codeclimate.com/github/Ziptastic/ziptastic-php/badges/coverage.svg)](https://codeclimate.com/github/Ziptastic/ziptastic-php/coverage) + This library is a simple interface for the [Ziptastic API](https://www.getziptastic.com/). Using Ziptastic requires an API key. @@ -65,4 +67,4 @@ echo $lookup->timezone()->getName(); // America/Detroit ## License -Ziptastic PHP is licensed under the MIT license. \ No newline at end of file +Ziptastic PHP is licensed under the MIT license. diff --git a/bin/test b/bin/test index a036bbb..3b723e2 100755 --- a/bin/test +++ b/bin/test @@ -1,3 +1,3 @@ #!/bin/bash -$(dirname $0)/../vendor/bin/phpunit \ No newline at end of file +$(dirname $0)/../vendor/bin/phpunit diff --git a/composer.json b/composer.json index 654f34d..d3b9d31 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,8 @@ "php": ">=5.4" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.0", + "codeclimate/php-test-reporter": "dev-master" }, "license": "MIT", "authors": [ diff --git a/phpunit.xml b/phpunit.xml index ccab9b0..cf027a3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,8 +8,9 @@ - + + diff --git a/src/LookupModel.php b/src/LookupModel.php index 1999e61..d7759c4 100644 --- a/src/LookupModel.php +++ b/src/LookupModel.php @@ -49,16 +49,16 @@ class LookupModel */ public function __construct(array $lookup) { - $this->county = (isset($lookup['county'])) ? $lookup['county'] : null; - $this->city = (isset($lookup['city'])) ? $lookup['city'] : null; - $this->state = (isset($lookup['state'])) ? $lookup['state'] : null; - $this->stateShort = (isset($lookup['state_short'])) ? $lookup['state_short'] : null; - $this->postalCode = (isset($lookup['postal_code'])) ? $lookup['postal_code'] : null; - $this->latitude = (isset($lookup['latitude'])) ? $lookup['latitude'] : null; - $this->longitude = (isset($lookup['longitude'])) ? $lookup['longitude'] : null; - $tz = (isset($lookup['timezone'])) ? $lookup['timezone'] : null; - if (!is_null($tz)) { - $this->timezone = new DateTimeZone($tz); + $this->county = $this->getOrNull('county', $lookup); + $this->city = $this->getOrNull('city', $lookup); + $this->state = $this->getOrNull('state', $lookup); + $this->stateShort = $this->getOrNull('state_short', $lookup); + $this->postalCode = $this->getOrNull('postal_code', $lookup); + $this->latitude = $this->getOrNull('latitude', $lookup); + $this->longitude = $this->getOrNull('longitude', $lookup); + $timezone = $this->getOrNull('timezone', $lookup); + if (!is_null($timezone)) { + $this->timezone = new DateTimeZone($timezone); } } @@ -125,4 +125,9 @@ public function timezone() { return $this->timezone; } -} \ No newline at end of file + + private function getOrNull($key, array $data) + { + return (isset($data[$key])) ? $data[$key] : null; + } +} diff --git a/src/Service/CurlService.php b/src/Service/CurlService.php index 19c5d00..91953cd 100644 --- a/src/Service/CurlService.php +++ b/src/Service/CurlService.php @@ -6,18 +6,18 @@ class CurlService implements ServiceInterface { public function get($url, $apiKey) { - $ch = $this->curl_init(); - $this->curl_setopt($ch, CURLOPT_URL, $url); - $this->curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - $this->curl_setopt($ch, CURLOPT_HTTPHEADER, [ + $handle = $this->curl_init(); + $this->curl_setopt($handle, CURLOPT_URL, $url); + $this->curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + $this->curl_setopt($handle, CURLOPT_HTTPHEADER, [ sprintf("x-key: %s", $apiKey) ]); - $response = $this->curl_exec($ch); + $response = $this->curl_exec($handle); $res = json_decode(trim($response), true); - $statusCode = $this->curl_getinfo($ch, CURLINFO_HTTP_CODE); - $this->curl_close($ch); + $statusCode = $this->curl_getinfo($handle, CURLINFO_HTTP_CODE); + $this->curl_close($handle); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('Could not parse response as json'); @@ -38,6 +38,7 @@ public function get($url, $apiKey) /** * @codeCoverageIgnore + * @SuppressWarnings(PHPMD) */ protected function curl_init() { @@ -46,33 +47,37 @@ protected function curl_init() /** * @codeCoverageIgnore + * @SuppressWarnings(PHPMD) */ - protected function curl_setopt($ch, $name, $opt) + protected function curl_setopt($handle, $name, $opt) { - return curl_setopt($ch, $name, $opt); + return curl_setopt($handle, $name, $opt); } /** * @codeCoverageIgnore + * @SuppressWarnings(PHPMD) */ - protected function curl_getinfo($ch, $name) + protected function curl_getinfo($handle, $name) { - return curl_getinfo($ch, $name); + return curl_getinfo($handle, $name); } /** * @codeCoverageIgnore + * @SuppressWarnings(PHPMD) */ - protected function curl_exec($ch) + protected function curl_exec($handle) { - return curl_exec($ch); + return curl_exec($handle); } /** * @codeCoverageIgnore + * @SuppressWarnings(PHPMD) */ - protected function curl_close($ch) + protected function curl_close($handle) { - return curl_close($ch); + return curl_close($handle); } -} \ No newline at end of file +}