Skip to content

Commit 30ae77f

Browse files
authored
Add PHP Coding Standards Fixer in CI (#1196)
* Update composer.json * Update .gitignore * Update php.yml * Apply PHPCSFixer fixes * Switch to php-cs-fixer/shim * Create .php-cs-fixer.dist.php
1 parent c83b9da commit 30ae77f

File tree

141 files changed

+331
-1898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+331
-1898
lines changed

.github/workflows/php.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,19 @@ jobs:
4949
- name: Install dependencies
5050
run: composer install --no-progress
5151
- name: Run PHPStan
52-
run: composer run-script analyse
52+
run: composer run-script analyse
53+
54+
php-cs-fixer:
55+
runs-on: ubuntu-latest
56+
name: PHP CS Fixer
57+
steps:
58+
- uses: actions/checkout@v3
59+
- name: Use PHP 8.2
60+
uses: shivammathur/setup-php@v2
61+
with:
62+
php-version: 8.2
63+
extensions: curl
64+
- name: Install dependencies
65+
run: composer install --no-progress
66+
- name: Run PHPStan
67+
run: composer run-script cs

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ composer.lock
33
composer.phar
44
phpunit.xml
55
.phpunit.result.cache
6-
php-cs-fixer.phar
6+
.php-cs-fixer.cache
77
.puli/

.php-cs-fixer.dist.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in('src')
5+
;
6+
7+
return (new PhpCsFixer\Config())
8+
->setRules([
9+
'@Symfony' => true,
10+
])
11+
->setFinder($finder);

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"geoip2/geoip2": "~2.0",
3737
"nyholm/nsa": "^1.1",
3838
"nyholm/psr7": "^1.0",
39+
"php-cs-fixer/shim": "^3.22",
3940
"php-http/curl-client": "^2.2",
4041
"php-http/message": "^1.0",
4142
"php-http/mock-client": "^1.0",
@@ -82,6 +83,8 @@
8283
},
8384
"scripts": {
8485
"analyse": "vendor/bin/phpstan analyse",
86+
"cs": "vendor/bin/php-cs-fixer fix -v --dry-run",
87+
"cs:fix": "vendor/bin/php-cs-fixer fix -v",
8588
"test": "vendor/bin/phpunit"
8689
}
8790
}

src/Common/Assert.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
class Assert
1818
{
1919
/**
20-
* @param float $value
21-
* @param string $message
20+
* @param float $value
2221
*/
2322
public static function latitude($value, string $message = '')
2423
{
@@ -29,8 +28,7 @@ public static function latitude($value, string $message = '')
2928
}
3029

3130
/**
32-
* @param float $value
33-
* @param string $message
31+
* @param float $value
3432
*/
3533
public static function longitude($value, string $message = '')
3634
{
@@ -40,10 +38,6 @@ public static function longitude($value, string $message = '')
4038
}
4139
}
4240

43-
/**
44-
* @param mixed $value
45-
* @param string $message
46-
*/
4741
public static function notNull($value, string $message = '')
4842
{
4943
if (null === $value) {
@@ -56,10 +50,6 @@ private static function typeToString($value): string
5650
return is_object($value) ? get_class($value) : gettype($value);
5751
}
5852

59-
/**
60-
* @param $value
61-
* @param $message
62-
*/
6353
private static function float($value, string $message)
6454
{
6555
if (!is_float($value)) {

src/Common/Collection.php

-10
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,20 @@
2626
interface Collection extends \IteratorAggregate, \Countable
2727
{
2828
/**
29-
* @return Location
30-
*
3129
* @throws CollectionIsEmpty
3230
*/
3331
public function first(): Location;
3432

35-
/**
36-
* @return bool
37-
*/
3833
public function isEmpty(): bool;
3934

4035
/**
4136
* @return Location[]
4237
*/
4338
public function slice(int $offset, int $length = null);
4439

45-
/**
46-
* @return bool
47-
*/
4840
public function has(int $index): bool;
4941

5042
/**
51-
* @return Location
52-
*
5343
* @throws OutOfBounds
5444
*/
5545
public function get(int $index): Location;

src/Common/Dumper/AbstractArrayDumper.php

-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
*/
2020
abstract class AbstractArrayDumper
2121
{
22-
/**
23-
* @param Location $location
24-
*
25-
* @return array
26-
*/
2722
protected function getArray(Location $location): array
2823
{
2924
$properties = array_filter($location->toArray(), function ($value) {

src/Common/Dumper/AbstractDumper.php

-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
abstract class AbstractDumper
1818
{
19-
/**
20-
* @param Location $address
21-
*
22-
* @return string
23-
*/
2419
protected function formatName(Location $address): string
2520
{
2621
$name = [];

src/Common/Dumper/Dumper.php

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ interface Dumper
2222
/**
2323
* Dumps an `Location` object as a string representation of
2424
* the implemented format.
25-
*
26-
* @param Location $location
27-
*
28-
* @return mixed
2925
*/
3026
public function dump(Location $location);
3127
}

src/Common/Dumper/GeoArray.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
final class GeoArray extends AbstractArrayDumper implements Dumper
2121
{
22-
/**
23-
* {@inheritdoc}
24-
*/
2522
public function dump(Location $location): array
2623
{
2724
return $this->getArray($location);

src/Common/Dumper/GeoJson.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
final class GeoJson extends AbstractArrayDumper implements Dumper
2121
{
22-
/**
23-
* {@inheritdoc}
24-
*/
2522
public function dump(Location $location): string
2623
{
2724
return json_encode($this->getArray($location));

src/Common/Dumper/Gpx.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
*/
2121
final class Gpx extends AbstractDumper implements Dumper
2222
{
23-
/**
24-
* @param Location $location
25-
*
26-
* @return string
27-
*/
2823
public function dump(Location $location): string
2924
{
3025
$gpx = sprintf(<<<'GPX'
@@ -37,14 +32,14 @@ public function dump(Location $location): string
3732
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
3833

3934
GPX
40-
, Geocoder::VERSION);
35+
, Geocoder::VERSION);
4136

4237
if (null !== $bounds = $location->getBounds()) {
4338
$gpx .= sprintf(<<<'GPX'
4439
<bounds minlat="%f" minlon="%f" maxlat="%f" maxlon="%f"/>
4540

4641
GPX
47-
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
42+
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
4843
}
4944

5045
$lat = null;
@@ -61,7 +56,7 @@ public function dump(Location $location): string
6156
</wpt>
6257

6358
GPX
64-
, $lat, $lon, $this->formatName($location));
59+
, $lat, $lon, $this->formatName($location));
6560

6661
$gpx .= <<<'GPX'
6762
</gpx>

src/Common/Dumper/Kml.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
final class Kml extends AbstractDumper implements Dumper
2121
{
22-
/**
23-
* {@inheritdoc}
24-
*/
2522
public function dump(Location $location): string
2623
{
2724
$name = $this->formatName($location);

src/Common/Dumper/Wkb.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
final class Wkb implements Dumper
2121
{
22-
/**
23-
* {@inheritdoc}
24-
*/
2522
public function dump(Location $location): string
2623
{
2724
$lat = null;

src/Common/Dumper/Wkt.php

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*/
2020
final class Wkt implements Dumper
2121
{
22-
/**
23-
* {@inheritdoc}
24-
*/
2522
public function dump(Location $location): string
2623
{
2724
$lat = null;

src/Common/Exception/FunctionNotFound.php

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
final class FunctionNotFound extends \RuntimeException implements Exception
1919
{
2020
/**
21-
* @param string $functionName
2221
* @param string $description
2322
*/
2423
public function __construct(string $functionName, $description = null)

src/Common/Exception/InvalidServerResponse.php

-11
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,11 @@
1919
*/
2020
final class InvalidServerResponse extends \RuntimeException implements Exception
2121
{
22-
/**
23-
* @param string $query
24-
* @param int $code
25-
*
26-
* @return InvalidServerResponse
27-
*/
2822
public static function create(string $query, int $code = 0): self
2923
{
3024
return new self(sprintf('The geocoder server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query));
3125
}
3226

33-
/**
34-
* @param string $query
35-
*
36-
* @return InvalidServerResponse
37-
*/
3827
public static function emptyResponse(string $query): self
3928
{
4029
return new self(sprintf('The geocoder server returned an empty response for query "%s".', $query));

src/Common/Exception/ProviderNotRegistered.php

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
*/
1818
final class ProviderNotRegistered extends \RuntimeException implements Exception
1919
{
20-
/**
21-
* @param string $providerName
22-
* @param array $registeredProviders
23-
*/
2420
public static function create(string $providerName, array $registeredProviders = [])
2521
{
2622
return new self(sprintf(

src/Common/Formatter/StringFormatter.php

+11-16
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,36 @@
1212

1313
namespace Geocoder\Formatter;
1414

15-
use Geocoder\Model\AdminLevelCollection;
1615
use Geocoder\Location;
16+
use Geocoder\Model\AdminLevelCollection;
1717

1818
/**
1919
* @author William Durand <[email protected]>
2020
*/
2121
final class StringFormatter
2222
{
23-
const STREET_NUMBER = '%n';
23+
public const STREET_NUMBER = '%n';
2424

25-
const STREET_NAME = '%S';
25+
public const STREET_NAME = '%S';
2626

27-
const LOCALITY = '%L';
27+
public const LOCALITY = '%L';
2828

29-
const POSTAL_CODE = '%z';
29+
public const POSTAL_CODE = '%z';
3030

31-
const SUB_LOCALITY = '%D';
31+
public const SUB_LOCALITY = '%D';
3232

33-
const ADMIN_LEVEL = '%A';
33+
public const ADMIN_LEVEL = '%A';
3434

35-
const ADMIN_LEVEL_CODE = '%a';
35+
public const ADMIN_LEVEL_CODE = '%a';
3636

37-
const COUNTRY = '%C';
37+
public const COUNTRY = '%C';
3838

39-
const COUNTRY_CODE = '%c';
39+
public const COUNTRY_CODE = '%c';
4040

41-
const TIMEZONE = '%T';
41+
public const TIMEZONE = '%T';
4242

4343
/**
4444
* Transform an `Address` instance into a string representation.
45-
*
46-
* @param Location $location
47-
* @param string $format
48-
*
49-
* @return string
5045
*/
5146
public function format(Location $location, string $format): string
5247
{

src/Common/Geocoder.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,25 @@ interface Geocoder extends Provider
2222
/**
2323
* Version of this package.
2424
*/
25-
const MAJOR_VERSION = 4;
25+
public const MAJOR_VERSION = 4;
2626

27-
const VERSION = '4.0';
27+
public const VERSION = '4.0';
2828

2929
/**
3030
* The default result limit.
3131
*/
32-
const DEFAULT_RESULT_LIMIT = 5;
32+
public const DEFAULT_RESULT_LIMIT = 5;
3333

3434
/**
3535
* Geocodes a given value.
3636
*
37-
* @param string $value
38-
*
39-
* @return Collection
40-
*
4137
* @throws \Geocoder\Exception\Exception
4238
*/
4339
public function geocode(string $value): Collection;
4440

4541
/**
4642
* Reverses geocode given latitude and longitude values.
4743
*
48-
* @param float $latitude
49-
* @param float $longitude
50-
*
51-
* @return Collection
52-
*
5344
* @throws \Geocoder\Exception\Exception
5445
*/
5546
public function reverse(float $latitude, float $longitude): Collection;

0 commit comments

Comments
 (0)