Skip to content

Commit

Permalink
Add coverage and quality reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
John Pedrie committed Dec 17, 2015
1 parent 5c29f7a commit f66ff57
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendor
composer.lock
.DS_Store
coverage
build
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -65,4 +67,4 @@ echo $lookup->timezone()->getName(); // America/Detroit

## License

Ziptastic PHP is licensed under the MIT license.
Ziptastic PHP is licensed under the MIT license.
2 changes: 1 addition & 1 deletion bin/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

$(dirname $0)/../vendor/bin/phpunit
$(dirname $0)/../vendor/bin/phpunit
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
5 changes: 3 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
</testsuites>

<logging>
<log type="coverage-html" target="./coverage" lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-html" target="build/coverage" lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>

</phpunit>
27 changes: 16 additions & 11 deletions src/LookupModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -125,4 +125,9 @@ public function timezone()
{
return $this->timezone;
}
}

private function getOrNull($key, array $data)
{
return (isset($data[$key])) ? $data[$key] : null;
}
}
37 changes: 21 additions & 16 deletions src/Service/CurlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -38,6 +38,7 @@ public function get($url, $apiKey)

/**
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD)
*/
protected function curl_init()
{
Expand All @@ -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);
}
}
}

0 comments on commit f66ff57

Please sign in to comment.