Skip to content

Commit f66ff57

Browse files
author
John Pedrie
committed
Add coverage and quality reporting
1 parent 5c29f7a commit f66ff57

8 files changed

Lines changed: 52 additions & 34 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
vendor
22
composer.lock
33
.DS_Store
4-
coverage
4+
build

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ php:
44
- '5.5'
55
- '5.6'
66
- '7.0'
7+
install:
8+
- mkdir -p build/logs
79
before_script:
810
- composer self-update
911
- composer install --prefer-source --no-interaction --dev
10-
script: phpunit
12+
script: ./bin/test
13+
after_success:
14+
- travis_retry ./vendor/bin/test-reporter

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Ziptastic PHP
22

3+
[![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)
4+
35
This library is a simple interface for the [Ziptastic API](https://www.getziptastic.com/).
46

57
Using Ziptastic requires an API key.
@@ -65,4 +67,4 @@ echo $lookup->timezone()->getName(); // America/Detroit
6567

6668
## License
6769

68-
Ziptastic PHP is licensed under the MIT license.
70+
Ziptastic PHP is licensed under the MIT license.

bin/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
$(dirname $0)/../vendor/bin/phpunit
3+
$(dirname $0)/../vendor/bin/phpunit

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"php": ">=5.4"
66
},
77
"require-dev": {
8-
"phpunit/phpunit": "~4.0"
8+
"phpunit/phpunit": "~4.0",
9+
"codeclimate/php-test-reporter": "dev-master"
910
},
1011
"license": "MIT",
1112
"authors": [

phpunit.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
</testsuites>
99

1010
<logging>
11-
<log type="coverage-html" target="./coverage" lowUpperBound="35"
12-
highLowerBound="70"/>
11+
<log type="coverage-html" target="build/coverage" lowUpperBound="35"
12+
highLowerBound="70"/>
13+
<log type="coverage-clover" target="build/logs/clover.xml"/>
1314
</logging>
1415

1516
</phpunit>

src/LookupModel.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ class LookupModel
4949
*/
5050
public function __construct(array $lookup)
5151
{
52-
$this->county = (isset($lookup['county'])) ? $lookup['county'] : null;
53-
$this->city = (isset($lookup['city'])) ? $lookup['city'] : null;
54-
$this->state = (isset($lookup['state'])) ? $lookup['state'] : null;
55-
$this->stateShort = (isset($lookup['state_short'])) ? $lookup['state_short'] : null;
56-
$this->postalCode = (isset($lookup['postal_code'])) ? $lookup['postal_code'] : null;
57-
$this->latitude = (isset($lookup['latitude'])) ? $lookup['latitude'] : null;
58-
$this->longitude = (isset($lookup['longitude'])) ? $lookup['longitude'] : null;
59-
$tz = (isset($lookup['timezone'])) ? $lookup['timezone'] : null;
60-
if (!is_null($tz)) {
61-
$this->timezone = new DateTimeZone($tz);
52+
$this->county = $this->getOrNull('county', $lookup);
53+
$this->city = $this->getOrNull('city', $lookup);
54+
$this->state = $this->getOrNull('state', $lookup);
55+
$this->stateShort = $this->getOrNull('state_short', $lookup);
56+
$this->postalCode = $this->getOrNull('postal_code', $lookup);
57+
$this->latitude = $this->getOrNull('latitude', $lookup);
58+
$this->longitude = $this->getOrNull('longitude', $lookup);
59+
$timezone = $this->getOrNull('timezone', $lookup);
60+
if (!is_null($timezone)) {
61+
$this->timezone = new DateTimeZone($timezone);
6262
}
6363
}
6464

@@ -125,4 +125,9 @@ public function timezone()
125125
{
126126
return $this->timezone;
127127
}
128-
}
128+
129+
private function getOrNull($key, array $data)
130+
{
131+
return (isset($data[$key])) ? $data[$key] : null;
132+
}
133+
}

src/Service/CurlService.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ class CurlService implements ServiceInterface
66
{
77
public function get($url, $apiKey)
88
{
9-
$ch = $this->curl_init();
10-
$this->curl_setopt($ch, CURLOPT_URL, $url);
11-
$this->curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
12-
$this->curl_setopt($ch, CURLOPT_HTTPHEADER, [
9+
$handle = $this->curl_init();
10+
$this->curl_setopt($handle, CURLOPT_URL, $url);
11+
$this->curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
12+
$this->curl_setopt($handle, CURLOPT_HTTPHEADER, [
1313
sprintf("x-key: %s", $apiKey)
1414
]);
1515

16-
$response = $this->curl_exec($ch);
16+
$response = $this->curl_exec($handle);
1717

1818
$res = json_decode(trim($response), true);
19-
$statusCode = $this->curl_getinfo($ch, CURLINFO_HTTP_CODE);
20-
$this->curl_close($ch);
19+
$statusCode = $this->curl_getinfo($handle, CURLINFO_HTTP_CODE);
20+
$this->curl_close($handle);
2121

2222
if (json_last_error() !== JSON_ERROR_NONE) {
2323
throw new Exception('Could not parse response as json');
@@ -38,6 +38,7 @@ public function get($url, $apiKey)
3838

3939
/**
4040
* @codeCoverageIgnore
41+
* @SuppressWarnings(PHPMD)
4142
*/
4243
protected function curl_init()
4344
{
@@ -46,33 +47,37 @@ protected function curl_init()
4647

4748
/**
4849
* @codeCoverageIgnore
50+
* @SuppressWarnings(PHPMD)
4951
*/
50-
protected function curl_setopt($ch, $name, $opt)
52+
protected function curl_setopt($handle, $name, $opt)
5153
{
52-
return curl_setopt($ch, $name, $opt);
54+
return curl_setopt($handle, $name, $opt);
5355
}
5456

5557
/**
5658
* @codeCoverageIgnore
59+
* @SuppressWarnings(PHPMD)
5760
*/
58-
protected function curl_getinfo($ch, $name)
61+
protected function curl_getinfo($handle, $name)
5962
{
60-
return curl_getinfo($ch, $name);
63+
return curl_getinfo($handle, $name);
6164
}
6265

6366
/**
6467
* @codeCoverageIgnore
68+
* @SuppressWarnings(PHPMD)
6569
*/
66-
protected function curl_exec($ch)
70+
protected function curl_exec($handle)
6771
{
68-
return curl_exec($ch);
72+
return curl_exec($handle);
6973
}
7074

7175
/**
7276
* @codeCoverageIgnore
77+
* @SuppressWarnings(PHPMD)
7378
*/
74-
protected function curl_close($ch)
79+
protected function curl_close($handle)
7580
{
76-
return curl_close($ch);
81+
return curl_close($handle);
7782
}
78-
}
83+
}

0 commit comments

Comments
 (0)