Skip to content

Commit 1dda339

Browse files
committed
chore: 🤖 Improves code sniffer
Uses PSR-12 instead of the deprecated PSR-2
1 parent fdc3274 commit 1dda339

File tree

10 files changed

+76
-64
lines changed

10 files changed

+76
-64
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ jobs:
3535
if [ "${{ matrix.php-version }}" != "8.5" ]; then rm composer.lock; fi
3636
composer install --no-progress --no-suggest --no-interaction
3737
38-
- name: Run tests
38+
- name: Run phpunit tests (with and without cURL)
3939
run: |
40-
composer validate
41-
./vendor/bin/phpunit
42-
SKIP_CURL=1 ./vendor/bin/phpunit
40+
composer check
4341
4442
- name: Run proxy tests
4543
run: |
4644
docker run -d --name=tinyproxy -p 8888:8888 monokal/tinyproxy:latest ANY
4745
PROXY=http://0.0.0.0:8888 ./vendor/bin/phpunit
46+
PROXY=http://0.0.0.0:8888 SKIP_CURL=1 ./vendor/bin/phpunit
4847
docker rm -f tinyproxy
4948
50-
- name: Run Linter
49+
- name: Run PHPCS (Code Sniffer)
5150
run: ./vendor/bin/phpcs .
5251

53-
- name: Run PHPStan
54-
run: ./vendor/bin/phpstan analyse --level 5 src tests demo
52+
- name: Run PHPStan (Static Analysis)
53+
run: ./vendor/bin/phpstan analyse

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vagrant
22
vendor
3-
.phpunit.*
3+
.phpunit.*
4+
.php-cs-fixer.cache

‎composer.json‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,20 @@
2020
"require-dev": {
2121
"phpunit/phpunit": "^10.5 || ^11.0 || ^12.0",
2222
"squizlabs/php_codesniffer": "^3.7 || ^4.0",
23-
"phpstan/phpstan": "^2.0.0"
23+
"phpstan/phpstan": "^2.0"
24+
},
25+
"scripts": {
26+
"test": "phpunit --display-deprecations",
27+
"test:nocurl": "SKIP_CURL=1 phpunit --display-deprecations",
28+
"phpcs": "phpcs .",
29+
"phpstan": "phpstan analyse",
30+
"check": [
31+
"composer validate --strict",
32+
"@test",
33+
"@test:nocurl",
34+
"@phpcs",
35+
"@phpstan"
36+
]
2437
},
2538
"archive": {
2639
"exclude": ["vendor", ".DS_Store"]

‎composer.lock‎

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎demo/geocode.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3-
include(dirname(__DIR__).'/src/AbstractGeocoder.php');
4-
include(dirname(__DIR__).'/src/Geocoder.php');
3+
include(dirname(__DIR__) . '/src/AbstractGeocoder.php');
4+
include(dirname(__DIR__) . '/src/Geocoder.php');
55

66
// use OpenCage\Geocoder;
77

‎phpcs.xml‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33

44
<description>opencage geocode standard</description>
55

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

1110
<exclude-pattern>./vendor/</exclude-pattern>
1211
<exclude-pattern>./tests/bootstrap.php</exclude-pattern>
1312

1413
<!-- default 120 -->
1514
<rule ref="Generic.Files.LineLength">
1615
<properties>
17-
<property name="lineLimit" value="150"/>
18-
<property name="absoluteLineLimit" value="0"/>
16+
<property name="lineLimit" value="150" />
17+
<property name="absoluteLineLimit" value="0" />
1918
</properties>
2019
</rule>
2120

22-
</ruleset>
21+
</ruleset>

‎phpstan.neon‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
2-
level: max
2+
level: 5
33
paths:
44
- src
55
- tests
6+
- demo
67
reportUnmatchedIgnoredErrors: false

‎src/AbstractGeocoder.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

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

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

1313
protected $key;
1414
protected $timeout;
@@ -132,7 +132,7 @@ protected function getJSONByCurl($query)
132132

133133
$ret = curl_exec($ch);
134134
if ($ret === false) {
135-
return $this->generateErrorJSON(498, 'network issue '.curl_error($ch));
135+
return $this->generateErrorJSON(498, 'network issue ' . curl_error($ch));
136136
}
137137
return $ret;
138138
}

‎src/Geocoder.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public function geocode($query, $optParams = [])
2424

2525
if (is_array($optParams) && !empty($optParams)) {
2626
foreach ($optParams as $param => $paramValue) {
27-
$url .= '&'.$param.'=' . urlencode($paramValue);
27+
$url .= '&' . $param . '=' . urlencode($paramValue);
2828
}
2929
}
30-
30+
3131
if (empty($this->key)) {
3232
throw new \Exception('Missing API key');
3333
}

‎tests/GeocoderTest.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class GeocoderTest extends \PHPUnit\Framework\TestCase
88
{
9-
109
public function testMissingKey()
1110
{
1211
$geocoder = new Geocoder();
@@ -34,7 +33,7 @@ public function testNetworkRequestError()
3433
$geocoder = new Geocoder('6d0e711d72d74daeb2b0bfd2a5cdfdba');
3534
$result = $geocoder->geocode('London', ['host' => 'doesnotexist.opencagedata.com']);
3635
// print_r($result);
37-
36+
3837
$this->assertEquals(498, $result['status']['code']);
3938
$this->assertStringContainsString('network issue', $result['status']['message']);
4039
$this->assertStringContainsString('doesnotexist.opencagedata.com', $result['status']['message']);

0 commit comments

Comments
 (0)