Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add PHP Coding Standards Fixer in CI #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 21, 2023
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
17 changes: 16 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ jobs:
- name: Install dependencies
run: composer install --no-progress
- name: Run PHPStan
run: composer run-script analyse
run: composer run-script analyse

php-cs-fixer:
runs-on: ubuntu-latest
name: PHP CS Fixer
steps:
- uses: actions/checkout@v3
- name: Use PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: curl
- name: Install dependencies
run: composer install --no-progress
- name: Run PHPStan
run: composer run-script cs
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ composer.lock
composer.phar
phpunit.xml
.phpunit.result.cache
php-cs-fixer.phar
.php-cs-fixer.cache
.puli/
11 changes: 11 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in('src')
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
])
->setFinder($finder);
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"geoip2/geoip2": "~2.0",
"nyholm/nsa": "^1.1",
"nyholm/psr7": "^1.0",
"php-cs-fixer/shim": "^3.22",
"php-http/curl-client": "^2.2",
"php-http/message": "^1.0",
"php-http/mock-client": "^1.0",
Expand Down Expand Up @@ -82,6 +83,8 @@
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"cs": "vendor/bin/php-cs-fixer fix -v --dry-run",
"cs:fix": "vendor/bin/php-cs-fixer fix -v",
"test": "vendor/bin/phpunit"
}
}
14 changes: 2 additions & 12 deletions src/Common/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
class Assert
{
/**
* @param float $value
* @param string $message
* @param float $value
*/
public static function latitude($value, string $message = '')
{
Expand All @@ -29,8 +28,7 @@ public static function latitude($value, string $message = '')
}

/**
* @param float $value
* @param string $message
* @param float $value
*/
public static function longitude($value, string $message = '')
{
Expand All @@ -40,10 +38,6 @@ public static function longitude($value, string $message = '')
}
}

/**
* @param mixed $value
* @param string $message
*/
public static function notNull($value, string $message = '')
{
if (null === $value) {
Expand All @@ -56,10 +50,6 @@ private static function typeToString($value): string
return is_object($value) ? get_class($value) : gettype($value);
}

/**
* @param $value
* @param $message
*/
private static function float($value, string $message)
{
if (!is_float($value)) {
Expand Down
10 changes: 0 additions & 10 deletions src/Common/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,20 @@
interface Collection extends \IteratorAggregate, \Countable
{
/**
* @return Location
*
* @throws CollectionIsEmpty
*/
public function first(): Location;

/**
* @return bool
*/
public function isEmpty(): bool;

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

/**
* @return bool
*/
public function has(int $index): bool;

/**
* @return Location
*
* @throws OutOfBounds
*/
public function get(int $index): Location;
Expand Down
5 changes: 0 additions & 5 deletions src/Common/Dumper/AbstractArrayDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
*/
abstract class AbstractArrayDumper
{
/**
* @param Location $location
*
* @return array
*/
protected function getArray(Location $location): array
{
$properties = array_filter($location->toArray(), function ($value) {
Expand Down
5 changes: 0 additions & 5 deletions src/Common/Dumper/AbstractDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

abstract class AbstractDumper
{
/**
* @param Location $address
*
* @return string
*/
protected function formatName(Location $address): string
{
$name = [];
Expand Down
4 changes: 0 additions & 4 deletions src/Common/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ interface Dumper
/**
* Dumps an `Location` object as a string representation of
* the implemented format.
*
* @param Location $location
*
* @return mixed
*/
public function dump(Location $location);
}
3 changes: 0 additions & 3 deletions src/Common/Dumper/GeoArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
final class GeoArray extends AbstractArrayDumper implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location): array
{
return $this->getArray($location);
Expand Down
3 changes: 0 additions & 3 deletions src/Common/Dumper/GeoJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
final class GeoJson extends AbstractArrayDumper implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location): string
{
return json_encode($this->getArray($location));
Expand Down
11 changes: 3 additions & 8 deletions src/Common/Dumper/Gpx.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
*/
final class Gpx extends AbstractDumper implements Dumper
{
/**
* @param Location $location
*
* @return string
*/
public function dump(Location $location): string
{
$gpx = sprintf(<<<'GPX'
Expand All @@ -37,14 +32,14 @@ public function dump(Location $location): string
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">

GPX
, Geocoder::VERSION);
, Geocoder::VERSION);

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

GPX
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
, $bounds->getWest(), $bounds->getSouth(), $bounds->getEast(), $bounds->getNorth());
}

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

GPX
, $lat, $lon, $this->formatName($location));
, $lat, $lon, $this->formatName($location));

$gpx .= <<<'GPX'
</gpx>
Expand Down
3 changes: 0 additions & 3 deletions src/Common/Dumper/Kml.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
final class Kml extends AbstractDumper implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location): string
{
$name = $this->formatName($location);
Expand Down
3 changes: 0 additions & 3 deletions src/Common/Dumper/Wkb.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
final class Wkb implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location): string
{
$lat = null;
Expand Down
3 changes: 0 additions & 3 deletions src/Common/Dumper/Wkt.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
final class Wkt implements Dumper
{
/**
* {@inheritdoc}
*/
public function dump(Location $location): string
{
$lat = null;
Expand Down
1 change: 0 additions & 1 deletion src/Common/Exception/FunctionNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
final class FunctionNotFound extends \RuntimeException implements Exception
{
/**
* @param string $functionName
* @param string $description
*/
public function __construct(string $functionName, $description = null)
Expand Down
11 changes: 0 additions & 11 deletions src/Common/Exception/InvalidServerResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,11 @@
*/
final class InvalidServerResponse extends \RuntimeException implements Exception
{
/**
* @param string $query
* @param int $code
*
* @return InvalidServerResponse
*/
public static function create(string $query, int $code = 0): self
{
return new self(sprintf('The geocoder server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query));
}

/**
* @param string $query
*
* @return InvalidServerResponse
*/
public static function emptyResponse(string $query): self
{
return new self(sprintf('The geocoder server returned an empty response for query "%s".', $query));
Expand Down
4 changes: 0 additions & 4 deletions src/Common/Exception/ProviderNotRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
*/
final class ProviderNotRegistered extends \RuntimeException implements Exception
{
/**
* @param string $providerName
* @param array $registeredProviders
*/
public static function create(string $providerName, array $registeredProviders = [])
{
return new self(sprintf(
Expand Down
27 changes: 11 additions & 16 deletions src/Common/Formatter/StringFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,36 @@

namespace Geocoder\Formatter;

use Geocoder\Model\AdminLevelCollection;
use Geocoder\Location;
use Geocoder\Model\AdminLevelCollection;

/**
* @author William Durand <[email protected]>
*/
final class StringFormatter
{
const STREET_NUMBER = '%n';
public const STREET_NUMBER = '%n';

const STREET_NAME = '%S';
public const STREET_NAME = '%S';

const LOCALITY = '%L';
public const LOCALITY = '%L';

const POSTAL_CODE = '%z';
public const POSTAL_CODE = '%z';

const SUB_LOCALITY = '%D';
public const SUB_LOCALITY = '%D';

const ADMIN_LEVEL = '%A';
public const ADMIN_LEVEL = '%A';

const ADMIN_LEVEL_CODE = '%a';
public const ADMIN_LEVEL_CODE = '%a';

const COUNTRY = '%C';
public const COUNTRY = '%C';

const COUNTRY_CODE = '%c';
public const COUNTRY_CODE = '%c';

const TIMEZONE = '%T';
public const TIMEZONE = '%T';

/**
* Transform an `Address` instance into a string representation.
*
* @param Location $location
* @param string $format
*
* @return string
*/
public function format(Location $location, string $format): string
{
Expand Down
15 changes: 3 additions & 12 deletions src/Common/Geocoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,25 @@ interface Geocoder extends Provider
/**
* Version of this package.
*/
const MAJOR_VERSION = 4;
public const MAJOR_VERSION = 4;

const VERSION = '4.0';
public const VERSION = '4.0';

/**
* The default result limit.
*/
const DEFAULT_RESULT_LIMIT = 5;
public const DEFAULT_RESULT_LIMIT = 5;

/**
* Geocodes a given value.
*
* @param string $value
*
* @return Collection
*
* @throws \Geocoder\Exception\Exception
*/
public function geocode(string $value): Collection;

/**
* Reverses geocode given latitude and longitude values.
*
* @param float $latitude
* @param float $longitude
*
* @return Collection
*
* @throws \Geocoder\Exception\Exception
*/
public function reverse(float $latitude, float $longitude): Collection;
Expand Down
Loading