Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@ jobs:
if [ "${{ matrix.php-version }}" != "8.5" ]; then rm composer.lock; fi
composer install --no-progress --no-suggest --no-interaction

- name: Run tests
- name: Run phpunit tests (with and without cURL)
run: |
composer validate
./vendor/bin/phpunit
SKIP_CURL=1 ./vendor/bin/phpunit
composer check

- name: Run proxy tests
run: |
docker run -d --name=tinyproxy -p 8888:8888 monokal/tinyproxy:latest ANY
PROXY=http://0.0.0.0:8888 ./vendor/bin/phpunit
PROXY=http://0.0.0.0:8888 SKIP_CURL=1 ./vendor/bin/phpunit
docker rm -f tinyproxy

- name: Run Linter
- name: Run PHPCS (Code Sniffer)
run: ./vendor/bin/phpcs .

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --level 5 src tests demo
- name: Run PHPStan (Static Analysis)
run: ./vendor/bin/phpstan analyse
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vagrant
vendor
.phpunit.*
.phpunit.*
.php-cs-fixer.cache
15 changes: 14 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@
"require-dev": {
"phpunit/phpunit": "^10.5 || ^11.0 || ^12.0",
"squizlabs/php_codesniffer": "^3.7 || ^4.0",
"phpstan/phpstan": "^2.0.0"
"phpstan/phpstan": "^2.0"
},
"scripts": {
"test": "phpunit --display-deprecations",
"test:nocurl": "SKIP_CURL=1 phpunit --display-deprecations",
"phpcs": "phpcs .",
"phpstan": "phpstan analyse",
"check": [
"composer validate --strict",
"@test",
"@test:nocurl",
"@phpcs",
"@phpstan"
]
},
"archive": {
"exclude": ["vendor", ".DS_Store"]
Expand Down
72 changes: 36 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions demo/geocode.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

include(dirname(__DIR__).'/src/AbstractGeocoder.php');
include(dirname(__DIR__).'/src/Geocoder.php');
include(dirname(__DIR__) . '/src/AbstractGeocoder.php');
include(dirname(__DIR__) . '/src/Geocoder.php');

// use OpenCage\Geocoder;

Expand Down
13 changes: 6 additions & 7 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@

<description>opencage geocode standard</description>

<!-- based on another standard, you can find it here -->
<!-- /usr/share/php/PHP/CodeSniffer/Standards/PSR2/ruleset.xml -->
<!-- https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml -->
<rule ref="PSR2"/>
<!-- PSR12 is the modern replacement for deprecated PSR2 -->
<!-- https://www.php-fig.org/psr/psr-12/ -->
<rule ref="PSR12" />

<exclude-pattern>./vendor/</exclude-pattern>
<exclude-pattern>./tests/bootstrap.php</exclude-pattern>

<!-- default 120 -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="150"/>
<property name="absoluteLineLimit" value="0"/>
<property name="lineLimit" value="150" />
<property name="absoluteLineLimit" value="0" />
</properties>
</rule>

</ruleset>
</ruleset>
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
level: max
level: 5
paths:
- src
- tests
- demo
reportUnmatchedIgnoredErrors: false
10 changes: 5 additions & 5 deletions src/AbstractGeocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

abstract class AbstractGeocoder
{
const VERSION = '3.3.2'; // if changing this => remember to match everything with the git tag
public const VERSION = '3.3.2'; // if changing this => remember to match everything with the git tag

const TIMEOUT = 10;
const URL = 'https://api.opencagedata.com/geocode/v1/json/?';
const PROXY = null;
public const TIMEOUT = 10;
public const URL = 'https://api.opencagedata.com/geocode/v1/json/?';
public const PROXY = null;

protected $key;
protected $timeout;
Expand Down Expand Up @@ -132,7 +132,7 @@ protected function getJSONByCurl($query)

$ret = curl_exec($ch);
if ($ret === false) {
return $this->generateErrorJSON(498, 'network issue '.curl_error($ch));
return $this->generateErrorJSON(498, 'network issue ' . curl_error($ch));
}
return $ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Geocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public function geocode($query, $optParams = [])

if (is_array($optParams) && !empty($optParams)) {
foreach ($optParams as $param => $paramValue) {
$url .= '&'.$param.'=' . urlencode($paramValue);
$url .= '&' . $param . '=' . urlencode($paramValue);
}
}

if (empty($this->key)) {
throw new \Exception('Missing API key');
}
Expand Down
3 changes: 1 addition & 2 deletions tests/GeocoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class GeocoderTest extends \PHPUnit\Framework\TestCase
{

public function testMissingKey()
{
$geocoder = new Geocoder();
Expand Down Expand Up @@ -34,7 +33,7 @@ public function testNetworkRequestError()
$geocoder = new Geocoder('6d0e711d72d74daeb2b0bfd2a5cdfdba');
$result = $geocoder->geocode('London', ['host' => 'doesnotexist.opencagedata.com']);
// print_r($result);

$this->assertEquals(498, $result['status']['code']);
$this->assertStringContainsString('network issue', $result['status']['message']);
$this->assertStringContainsString('doesnotexist.opencagedata.com', $result['status']['message']);
Expand Down