diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index b364935..2352d68 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -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
diff --git a/.gitignore b/.gitignore
index faf5c87..45bd9e5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.vagrant
vendor
-.phpunit.*
\ No newline at end of file
+.phpunit.*
+.php-cs-fixer.cache
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 8bce4c4..e32ac4b 100644
--- a/composer.json
+++ b/composer.json
@@ -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"]
diff --git a/composer.lock b/composer.lock
index 2f1fca6..44197ea 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "42b8f9a4fd79e1b55dca625da7d23890",
+ "content-hash": "99491f00b69c5ed52b1deb238357bc38",
"packages": [],
"packages-dev": [
{
@@ -69,16 +69,16 @@
},
{
"name": "nikic/php-parser",
- "version": "v5.6.2",
+ "version": "v5.7.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "3a454ca033b9e06b63282ce19562e892747449bb"
+ "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3a454ca033b9e06b63282ce19562e892747449bb",
- "reference": "3a454ca033b9e06b63282ce19562e892747449bb",
+ "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82",
+ "reference": "dca41cd15c2ac9d055ad70dbfd011130757d1f82",
"shasum": ""
},
"require": {
@@ -121,9 +121,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
- "source": "https://github.com/nikic/PHP-Parser/tree/v5.6.2"
+ "source": "https://github.com/nikic/PHP-Parser/tree/v5.7.0"
},
- "time": "2025-10-21T19:32:17+00:00"
+ "time": "2025-12-06T11:56:16+00:00"
},
{
"name": "phar-io/manifest",
@@ -245,11 +245,11 @@
},
{
"name": "phpstan/phpstan",
- "version": "2.1.32",
+ "version": "2.1.33",
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e126cad1e30a99b137b8ed75a85a676450ebb227",
- "reference": "e126cad1e30a99b137b8ed75a85a676450ebb227",
+ "url": "https://api.github.com/repos/phpstan/phpstan/zipball/9e800e6bee7d5bd02784d4c6069b48032d16224f",
+ "reference": "9e800e6bee7d5bd02784d4c6069b48032d16224f",
"shasum": ""
},
"require": {
@@ -294,27 +294,27 @@
"type": "github"
}
],
- "time": "2025-11-11T15:18:17+00:00"
+ "time": "2025-12-05T10:24:31+00:00"
},
{
"name": "phpunit/php-code-coverage",
- "version": "12.4.0",
+ "version": "12.5.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "67e8aed88f93d0e6e1cb7effe1a2dfc2fee6022c"
+ "reference": "c467c59a4f6e04b942be422844e7a6352fa01b57"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/67e8aed88f93d0e6e1cb7effe1a2dfc2fee6022c",
- "reference": "67e8aed88f93d0e6e1cb7effe1a2dfc2fee6022c",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c467c59a4f6e04b942be422844e7a6352fa01b57",
+ "reference": "c467c59a4f6e04b942be422844e7a6352fa01b57",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-libxml": "*",
"ext-xmlwriter": "*",
- "nikic/php-parser": "^5.6.1",
+ "nikic/php-parser": "^5.7.0",
"php": ">=8.3",
"phpunit/php-file-iterator": "^6.0",
"phpunit/php-text-template": "^5.0",
@@ -322,10 +322,10 @@
"sebastian/environment": "^8.0.3",
"sebastian/lines-of-code": "^4.0",
"sebastian/version": "^6.0",
- "theseer/tokenizer": "^1.2.3"
+ "theseer/tokenizer": "^2.0"
},
"require-dev": {
- "phpunit/phpunit": "^12.3.7"
+ "phpunit/phpunit": "^12.5.1"
},
"suggest": {
"ext-pcov": "PHP extension that provides line coverage",
@@ -334,7 +334,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "12.4.x-dev"
+ "dev-main": "12.5.x-dev"
}
},
"autoload": {
@@ -363,7 +363,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
- "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/12.4.0"
+ "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/12.5.1"
},
"funding": [
{
@@ -383,7 +383,7 @@
"type": "tidelift"
}
],
- "time": "2025-09-24T13:44:41+00:00"
+ "time": "2025-12-08T07:17:58+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -632,16 +632,16 @@
},
{
"name": "phpunit/phpunit",
- "version": "12.4.4",
+ "version": "12.5.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "9253ec75a672e39fcc9d85bdb61448215b8162c7"
+ "reference": "06713c2633d6d832f2fe98a70511ecaa7cb92c1a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9253ec75a672e39fcc9d85bdb61448215b8162c7",
- "reference": "9253ec75a672e39fcc9d85bdb61448215b8162c7",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/06713c2633d6d832f2fe98a70511ecaa7cb92c1a",
+ "reference": "06713c2633d6d832f2fe98a70511ecaa7cb92c1a",
"shasum": ""
},
"require": {
@@ -655,7 +655,7 @@
"phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.2.1",
"php": ">=8.3",
- "phpunit/php-code-coverage": "^12.4.0",
+ "phpunit/php-code-coverage": "^12.5.1",
"phpunit/php-file-iterator": "^6.0.0",
"phpunit/php-invoker": "^6.0.0",
"phpunit/php-text-template": "^5.0.0",
@@ -677,7 +677,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-main": "12.4-dev"
+ "dev-main": "12.5-dev"
}
},
"autoload": {
@@ -709,7 +709,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
- "source": "https://github.com/sebastianbergmann/phpunit/tree/12.4.4"
+ "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.2"
},
"funding": [
{
@@ -733,7 +733,7 @@
"type": "tidelift"
}
],
- "time": "2025-11-21T07:39:11+00:00"
+ "time": "2025-12-08T07:22:32+00:00"
},
{
"name": "sebastian/cli-parser",
@@ -1765,23 +1765,23 @@
},
{
"name": "theseer/tokenizer",
- "version": "1.3.1",
+ "version": "2.0.1",
"source": {
"type": "git",
"url": "https://github.com/theseer/tokenizer.git",
- "reference": "b7489ce515e168639d17feec34b8847c326b0b3c"
+ "reference": "7989e43bf381af0eac72e4f0ca5bcbfa81658be4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c",
- "reference": "b7489ce515e168639d17feec34b8847c326b0b3c",
+ "url": "https://api.github.com/repos/theseer/tokenizer/zipball/7989e43bf381af0eac72e4f0ca5bcbfa81658be4",
+ "reference": "7989e43bf381af0eac72e4f0ca5bcbfa81658be4",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
- "php": "^7.2 || ^8.0"
+ "php": "^8.1"
},
"type": "library",
"autoload": {
@@ -1803,7 +1803,7 @@
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
"support": {
"issues": "https://github.com/theseer/tokenizer/issues",
- "source": "https://github.com/theseer/tokenizer/tree/1.3.1"
+ "source": "https://github.com/theseer/tokenizer/tree/2.0.1"
},
"funding": [
{
@@ -1811,7 +1811,7 @@
"type": "github"
}
],
- "time": "2025-11-17T20:03:58+00:00"
+ "time": "2025-12-08T11:19:18+00:00"
}
],
"aliases": [],
diff --git a/demo/geocode.php b/demo/geocode.php
index dab725e..76df02c 100644
--- a/demo/geocode.php
+++ b/demo/geocode.php
@@ -1,7 +1,7 @@
opencage geocode standard
-
-
-
-
+
+
+
./vendor/
./tests/bootstrap.php
@@ -14,9 +13,9 @@
-
-
+
+
-
+
\ No newline at end of file
diff --git a/phpstan.neon b/phpstan.neon
index 6d33d5b..eff12c2 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,6 +1,7 @@
parameters:
- level: max
+ level: 5
paths:
- src
- tests
+ - demo
reportUnmatchedIgnoredErrors: false
diff --git a/src/AbstractGeocoder.php b/src/AbstractGeocoder.php
index b2bd021..aee1684 100644
--- a/src/AbstractGeocoder.php
+++ b/src/AbstractGeocoder.php
@@ -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;
@@ -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;
}
diff --git a/src/Geocoder.php b/src/Geocoder.php
index f8a94c2..606dddc 100644
--- a/src/Geocoder.php
+++ b/src/Geocoder.php
@@ -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');
}
diff --git a/tests/GeocoderTest.php b/tests/GeocoderTest.php
index 03e0f59..40fb972 100644
--- a/tests/GeocoderTest.php
+++ b/tests/GeocoderTest.php
@@ -6,7 +6,6 @@
class GeocoderTest extends \PHPUnit\Framework\TestCase
{
-
public function testMissingKey()
{
$geocoder = new Geocoder();
@@ -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']);