Skip to content

Commit

Permalink
Update to latest PHP-CS-Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 26, 2024
1 parent 031d896 commit c93e6d4
Show file tree
Hide file tree
Showing 3,648 changed files with 3,933 additions and 273 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require-dev": {
"ext-json": "*",
"ext-sqlite3": "*",
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.48",
"nikic/php-parser": "^4.10",
"php-coord/datapack-africa": "^1.0",
"php-coord/datapack-antarctic": "^1.0",
Expand Down
24 changes: 13 additions & 11 deletions src/BritishNationalGridPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,50 @@
namespace PHPCoord;

use DateTimeInterface;
use function floor;
use function implode;
use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\Exception\InvalidCoordinateException;
use PHPCoord\UnitOfMeasure\Length\Length;
use PHPCoord\UnitOfMeasure\Length\Metre;

use function floor;
use function implode;
use function str_pad;
use const STR_PAD_LEFT;
use function str_replace;
use function strlen;
use function strpos;
use function substr;

use const STR_PAD_LEFT;

class BritishNationalGridPoint extends ProjectedPoint
{
private const GRID_LETTERS = 'VWXYZQRSTULMNOPFGHJKABCDE';

public function __construct(Length $easting, Length $northing, ?DateTimeInterface $epoch = null)
public function __construct(Length $easting, Length $northing, DateTimeInterface $epoch = null)
{
parent::__construct($easting, $northing, null, null, Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID), $epoch);
}

/**
* @param string $reference OS grid reference (e.g. "TG514131")
*/
public static function fromGridReference(string $reference, ?DateTimeInterface $epoch = null): self
public static function fromGridReference(string $reference, DateTimeInterface $epoch = null): self
{
$reference = str_replace(' ', '', $reference);

if (strlen($reference) % 2 !== 0) {
throw new InvalidCoordinateException('Grid ref must be an even number of characters');
}

//first (major) letter is the 500km grid sq, origin at -1000000, -500000
// first (major) letter is the 500km grid sq, origin at -1000000, -500000
$majorEasting = strpos(static::GRID_LETTERS, $reference[0]) % 5 * 500000 - 1000000;
$majorNorthing = (floor(strpos(static::GRID_LETTERS, $reference[0]) / 5)) * 500000 - 500000;
$majorNorthing = floor(strpos(static::GRID_LETTERS, $reference[0]) / 5) * 500000 - 500000;

//second (minor) letter is 100km grid sq, origin at 0,0 of this square
// second (minor) letter is 100km grid sq, origin at 0,0 of this square
$minorEasting = strpos(static::GRID_LETTERS, $reference[1]) % 5 * 100000;
$minorNorthing = (floor(strpos(static::GRID_LETTERS, $reference[1]) / 5)) * 100000;
$minorNorthing = floor(strpos(static::GRID_LETTERS, $reference[1]) / 5) * 100000;

//numbers are a division of that square into smaller and smaller pieces
// numbers are a division of that square into smaller and smaller pieces
$numericPortion = substr($reference, 2);
$numericPortionSize = strlen($numericPortion) / 2;
$gridSizeInMetres = 1 * (10 ** (5 - $numericPortionSize));
Expand Down Expand Up @@ -104,7 +106,7 @@ protected function gridReference(int $length): array
$majorLetterIndex = (int) (5 * $majorSquaresNorth + $majorSquaresEast);
$majorLetter = substr(self::GRID_LETTERS, $majorLetterIndex, 1);

//second (minor) letter is 100km grid sq, origin at 0,0 of this square
// second (minor) letter is 100km grid sq, origin at 0,0 of this square
$minorSquaresEast = $easting[0] % 5;
$minorSquaresNorth = $northing[0] % 5;
$minorLetterIndex = (5 * $minorSquaresNorth + $minorSquaresEast);
Expand Down
6 changes: 3 additions & 3 deletions src/CompoundPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CompoundPoint extends Point implements ConvertiblePoint
* Constructor.
* @param GeographicPoint|ProjectedPoint $horizontalPoint
*/
protected function __construct(Point $horizontalPoint, VerticalPoint $verticalPoint, Compound $crs, ?DateTimeInterface $epoch = null)
protected function __construct(Point $horizontalPoint, VerticalPoint $verticalPoint, Compound $crs, DateTimeInterface $epoch = null)
{
$this->horizontalPoint = $horizontalPoint;
$this->verticalPoint = $verticalPoint;
Expand All @@ -79,7 +79,7 @@ protected function __construct(Point $horizontalPoint, VerticalPoint $verticalPo
/**
* @param GeographicPoint|ProjectedPoint $horizontalPoint
*/
public static function create(Point $horizontalPoint, VerticalPoint $verticalPoint, Compound $crs, ?DateTimeInterface $epoch = null)
public static function create(Point $horizontalPoint, VerticalPoint $verticalPoint, Compound $crs, DateTimeInterface $epoch = null)
{
return new static($horizontalPoint, $verticalPoint, $crs, $epoch);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public function convert(CoordinateReferenceSystem $to, bool $ignoreBoundaryRestr
} catch (UnknownConversionException $e) {
if ($this->getHorizontalPoint() instanceof ConvertiblePoint) {
// if 2D target, try again with just the horizontal component
if (($to instanceof Geographic2D || $to instanceof Projected)) {
if ($to instanceof Geographic2D || $to instanceof Projected) {
return $this->getHorizontalPoint()->convert($to, $ignoreBoundaryRestrictions);
}

Expand Down
35 changes: 18 additions & 17 deletions src/CoordinateOperation/AutoConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@

namespace PHPCoord\CoordinateOperation;

use function abs;
use function array_column;
use function array_merge;
use function array_shift;
use function array_sum;
use function assert;
use function class_exists;
use function count;
use DateTimeImmutable;
use function end;
use Generator;
use function in_array;
use PHPCoord\CompoundPoint;
use PHPCoord\CoordinateReferenceSystem\CoordinateReferenceSystem;
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
Expand All @@ -30,7 +20,18 @@
use PHPCoord\Point;
use PHPCoord\ProjectedPoint;
use PHPCoord\UnitOfMeasure\Time\Year;
use function strpos;

use function abs;
use function array_column;
use function array_merge;
use function array_shift;
use function array_sum;
use function assert;
use function class_exists;
use function count;
use function end;
use function in_array;
use function str_starts_with;
use function usort;

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ public function convert(CoordinateReferenceSystem $to, bool $ignoreBoundaryRestr
return $this;
}

if (strpos($this->getCRS()->getSRID(), CoordinateReferenceSystem::CRS_SRID_PREFIX_EPSG) !== 0 || strpos($to->getSRID(), CoordinateReferenceSystem::CRS_SRID_PREFIX_EPSG) !== 0) {
if (!str_starts_with($this->getCRS()->getSRID(), CoordinateReferenceSystem::CRS_SRID_PREFIX_EPSG) || !str_starts_with($to->getSRID(), CoordinateReferenceSystem::CRS_SRID_PREFIX_EPSG)) {
throw new UnknownConversionException('Automatic conversions are only supported for EPSG CRSs');
}

Expand Down Expand Up @@ -112,7 +113,7 @@ protected function validatePath(array $candidatePath, ?GeographicValue $boundary
foreach ($candidatePath as $pathStep) {
$operation = CoordinateOperations::getOperationData($pathStep['operation']);
if ($boundaryCheckPoint) {
//filter out operations that only operate outside this point
// filter out operations that only operate outside this point
$polygon = BoundingArea::createFromExtentCodes($operation['extent_code']);
if (!$polygon->containsPoint($boundaryCheckPoint)) {
return false;
Expand All @@ -121,23 +122,23 @@ protected function validatePath(array $candidatePath, ?GeographicValue $boundary

$operation = CoordinateOperations::getOperationData($pathStep['operation']);

//filter out operations that require an epoch if we don't have one
// filter out operations that require an epoch if we don't have one
if (isset(self::$methodsThatRequireCoordinateEpoch[$operation['method']]) && !$this->getCoordinateEpoch()) {
return false;
}

$params = CoordinateOperations::getParamData($pathStep['operation']);

//filter out operations that require a specific epoch
// filter out operations that require a specific epoch
if (isset(self::$methodsThatRequireASpecificEpoch[$operation['method']]) && $this->getCoordinateEpoch()) {
$pointEpoch = Year::fromDateTime($this->getCoordinateEpoch());
if (!(abs($pointEpoch->getValue() - $params['transformationReferenceEpoch']['value']) <= 0.001)) {
return false;
}
}

//filter out operations that require a grid file that we don't have, or where boundaries are not being
//checked (a formula-based conversion will always return *a* result, outside a grid boundary does not...
// filter out operations that require a grid file that we don't have, or where boundaries are not being
// checked (a formula-based conversion will always return *a* result, outside a grid boundary does not...
foreach ($params as $param) {
if (isset($param['fileProvider']) && (!$boundaryCheckPoint || !class_exists($param['fileProvider']))) {
return false;
Expand Down
13 changes: 7 additions & 6 deletions src/CoordinateOperation/GeocentricValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

namespace PHPCoord\CoordinateOperation;

use function abs;
use function atan2;
use function cos;
use function hypot;
use PHPCoord\Datum\Datum;
use PHPCoord\UnitOfMeasure\Angle\Radian;
use PHPCoord\UnitOfMeasure\Length\Length;
use PHPCoord\UnitOfMeasure\Length\Metre;

use function abs;
use function atan2;
use function cos;
use function hypot;
use function sin;
use function sqrt;

Expand All @@ -27,7 +28,7 @@ class GeocentricValue
{
protected const ITERATION_CONVERGENCE = 1e-10;

private Metre$x;
private Metre $x;

private Metre $y;

Expand Down Expand Up @@ -71,7 +72,7 @@ public function asGeographicValue(): GeographicValue
$longitude += $this->datum->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue();
$p = hypot($x, $y);

$latitude = atan2($z, ($p * (1 - $e2)));
$latitude = atan2($z, $p * (1 - $e2));

do {
$phi1 = $latitude;
Expand Down
3 changes: 2 additions & 1 deletion src/CoordinateOperation/GeographicValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

namespace PHPCoord\CoordinateOperation;

use function cos;
use PHPCoord\Datum\Datum;
use PHPCoord\UnitOfMeasure\Angle\Angle;
use PHPCoord\UnitOfMeasure\Angle\Degree;
use PHPCoord\UnitOfMeasure\Angle\Radian;
use PHPCoord\UnitOfMeasure\Length\Length;
use PHPCoord\UnitOfMeasure\Length\Metre;

use function cos;
use function sin;
use function sqrt;

Expand Down
11 changes: 6 additions & 5 deletions src/CoordinateOperation/NADCON5Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPCoord\GeographicPoint;
use SplFileObject;
use UnexpectedValueException;

use function unpack;

class NADCON5Grid extends SplFileObject
Expand Down Expand Up @@ -68,11 +69,11 @@ private function getAdjustment(float $latitude, float $longitude): float
// a 3x3 window around $latitude.
$difla = ($latitude - $this->startLatitude);
$ratla = $difla / ($this->latitudeGridSize / 2);
$ila = (int) ($ratla) + 1;
$ila = (int) $ratla + 1;
if ($ila % 2 != 0) {
$jla = ($ila + 1) / 2 - 1;
} else {
$jla = ($ila) / 2;
$jla = $ila / 2;
}

// Fix any edge overlaps
Expand All @@ -87,11 +88,11 @@ private function getAdjustment(float $latitude, float $longitude): float
// a 3x3 window around $longitude.
$diflo = ($longitude - $this->startLongitude);
$ratlo = $diflo / ($this->longitudeGridSize / 2);
$ilo = (int) ($ratlo) + 1;
$ilo = (int) $ratlo + 1;
if ($ilo % 2 != 0) {
$jlo = ($ilo + 1) / 2 - 1;
} else {
$jlo = ($ilo) / 2;
$jlo = $ilo / 2;
}

// Fix any edge overlaps
Expand Down Expand Up @@ -141,7 +142,7 @@ public function getRecord(int $latitudeIndex, int $longitudeIndex): float
$rawRow = $this->fread($recordLength);
$row = unpack("Gstartbuffer/{$this->gridDataType}{$this->numberLongitudes}lon/Gendbuffer", $rawRow);

return $row['lon' . ($longitudeIndex)];
return $row['lon' . $longitudeIndex];
}

private function getHeader(): array
Expand Down
9 changes: 5 additions & 4 deletions src/CoordinateOperation/NTv2Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

namespace PHPCoord\CoordinateOperation;

use function abs;
use function assert;
use InvalidArgumentException;
use PHPCoord\CoordinateReferenceSystem\Geographic;
use PHPCoord\GeographicPoint;
use PHPCoord\UnitOfMeasure\Angle\Angle;
use PHPCoord\UnitOfMeasure\Angle\ArcSecond;
use function round;
use SplFileObject;

use function abs;
use function assert;
use function round;
use function unpack;
use function usort;

Expand Down Expand Up @@ -179,7 +180,7 @@ private function readHeader(): void
$subFileData = unpack("A8/A8SUB_NAME/A8/A8PARENT/A8/A8CREATED/A8/A8UPDATED/A8/{$this->doubleFormatChar}S_LAT/A8/{$this->doubleFormatChar}N_LAT/A8/{$this->doubleFormatChar}E_LONG/A8/{$this->doubleFormatChar}W_LONG/A8/{$this->doubleFormatChar}LAT_INC/A8/{$this->doubleFormatChar}LONG_INC/A8/{$this->integerFormatChar}GS_COUNT/x4", $subFileRawData);
$subFileData['offsetStart'] = $subFileStart;

//apply rounding to eliminate fp issues when being deserialized
// apply rounding to eliminate fp issues when being deserialized
$subFileData['S_LAT'] = round($subFileData['S_LAT'], 5);
$subFileData['N_LAT'] = round($subFileData['N_LAT'], 5);
$subFileData['E_LONG'] = round($subFileData['E_LONG'], 5);
Expand Down
12 changes: 7 additions & 5 deletions src/CoordinateOperation/OSTNOSGM15Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

namespace PHPCoord\CoordinateOperation;

use function abs;
use const PHP_MAJOR_VERSION;
use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\CoordinateSystem\Cartesian;
use PHPCoord\Datum\Datum;
use PHPCoord\ProjectedPoint;
use PHPCoord\UnitOfMeasure\Length\Metre;
use SplFileObject;

use function abs;

use const PHP_MAJOR_VERSION;

class OSTNOSGM15Grid extends SplFileObject
{
private const GRID_SIZE = 1000;
Expand Down Expand Up @@ -80,9 +82,9 @@ private function getAdjustment(Metre $easting, Metre $northing): array
$t = $dx / self::GRID_SIZE;
$u = $dy / self::GRID_SIZE;

$se = (1 - $t) * (1 - $u) * $corner0[3] + ($t) * (1 - $u) * $corner1[3] + ($t) * ($u) * $corner2[3] + (1 - $t) * ($u) * $corner3[3];
$sn = (1 - $t) * (1 - $u) * $corner0[4] + ($t) * (1 - $u) * $corner1[4] + ($t) * ($u) * $corner2[4] + (1 - $t) * ($u) * $corner3[4];
$sh = (1 - $t) * (1 - $u) * $corner0[5] + ($t) * (1 - $u) * $corner1[5] + ($t) * ($u) * $corner2[5] + (1 - $t) * ($u) * $corner3[5];
$se = (1 - $t) * (1 - $u) * $corner0[3] + $t * (1 - $u) * $corner1[3] + $t * $u * $corner2[3] + (1 - $t) * $u * $corner3[3];
$sn = (1 - $t) * (1 - $u) * $corner0[4] + $t * (1 - $u) * $corner1[4] + $t * $u * $corner2[4] + (1 - $t) * $u * $corner3[4];
$sh = (1 - $t) * (1 - $u) * $corner0[5] + $t * (1 - $u) * $corner1[5] + $t * $u * $corner2[5] + (1 - $t) * $u * $corner3[5];

return [$se, $sn, $sh];
}
Expand Down
1 change: 1 addition & 0 deletions src/CoordinateOperation/Params/EPSG10087.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Doug Wright
*/
declare(strict_types=1);

/** @internal */ return [
'A0' => [
'value' => 82357.457,
Expand Down
1 change: 1 addition & 0 deletions src/CoordinateOperation/Params/EPSG10098.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Doug Wright
*/
declare(strict_types=1);

/** @internal */ return [
'xAxisTranslation' => [
'value' => -96.062,
Expand Down
1 change: 1 addition & 0 deletions src/CoordinateOperation/Params/EPSG10100.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Doug Wright
*/
declare(strict_types=1);

/** @internal */ return [
'xAxisTranslation' => [
'value' => -26.5,
Expand Down
1 change: 1 addition & 0 deletions src/CoordinateOperation/Params/EPSG10101.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Doug Wright
*/
declare(strict_types=1);

/** @internal */ return [
'latitudeOfNaturalOrigin' => [
'value' => 30.3,
Expand Down
1 change: 1 addition & 0 deletions src/CoordinateOperation/Params/EPSG10102.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Doug Wright
*/
declare(strict_types=1);

/** @internal */ return [
'latitudeOfNaturalOrigin' => [
'value' => 30.0,
Expand Down
1 change: 1 addition & 0 deletions src/CoordinateOperation/Params/EPSG10103.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Doug Wright
*/
declare(strict_types=1);

/** @internal */ return [
'xAxisTranslation' => [
'value' => -24.5,
Expand Down
Loading

0 comments on commit c93e6d4

Please sign in to comment.