Skip to content

Commit

Permalink
Merge pull request #6 from longitude-one/dev
Browse files Browse the repository at this point in the history
Dev merged in main for 3.0.0.RC
  • Loading branch information
Alexandre-T authored Apr 10, 2024
2 parents 4886874 + 8b244ac commit 389acde
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 132 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "^10.5.16",
"symfony/deprecation-contracts": "^3.0"
"phpunit/phpunit": "^10.5.16"
},
"autoload": {
"psr-0": {
Expand Down
34 changes: 3 additions & 31 deletions lib/LongitudeOne/Geo/WKB/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,55 +70,27 @@ class Parser
private int $type;

/**
* @param string $input
*
* @throws UnexpectedValueException
*/
public function __construct($input = null)
public function __construct(?string $input = null)
{
$this->reader = new Reader();

if (null !== $input) {
if (!is_string($input)) {
trigger_deprecation(
'longitudeone/geo-wkb-parser',
'2.1',
sprintf('Argument 1 passed to __construct() must be of the type string, %s given, called in %s on line %d',
gettype($input),
__FILE__,
__LINE__
)
);
}

$this->reader->load((string) $input);
$this->reader->load($input);
}
}

/**
* Parse input data.
*
* @param string $input
*
* @return array{type:string, srid: ?int, value: (float|int)[]|(float|int)[][]|(float|int)[][][]|(float|int)[][][][]|(float|int)[][][][][]|array{type: string, value:(float|int)[][]}[]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]|array{type: string, value:(float|int)[][][]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]}[]|array{type: string, value:(float|int)[][][]}[]|array{type:string, value:(float|int)[]|(float|int)[][]|(float|int)[][][]|(float|int)[][][][]|(float|int)[][][][][]|array{type: string, value:(float|int)[][]}[]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]|array{type: string, value:(float|int)[][][]|array{type: string, value:(float|int)[][]|array{type: string, value:(float|int)[][]}[]}[]}[]|array{type: string, value:(float|int)[][][]}[]}[], dimension: ?string}
*
* @throws ExceptionInterface
*/
public function parse($input = null): array
public function parse(?string $input = null): array
{
if (null !== $input) {
if (!is_string($input)) {
trigger_deprecation(
'longitudeone/geo-wkb-parser',
'2.1',
sprintf('Argument 1 passed to parse() must be of the type string, %s given, called in %s on line %d',
gettype($input),
__FILE__,
__LINE__
)
);
}

$this->reader->load((string) $input);
}

Expand Down
52 changes: 2 additions & 50 deletions lib/LongitudeOne/Geo/WKB/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,12 @@ class Reader
private int $previous = 0;

/**
* @param string $input
*
* @throws UnexpectedValueException
*/
public function __construct($input = null)
public function __construct(?string $input = null)
{
if (null !== $input) {
if (!is_string($input)) {
trigger_deprecation(
'longitudeone/geo-wkb-parser',
'2.1',
'Argument 1 passed to __construct() must be of the type string, %s given, called in %s on line %d',
gettype($input),
__FILE__,
__LINE__
);
}
$this->load((string) $input);
$this->load($input);
}
}

Expand Down Expand Up @@ -114,42 +102,6 @@ public function readByteOrder(): int
return $this->byteOrder = $byteOrder;
}

/**
* @throws UnexpectedValueException
* @throws RangeException
*
* @deprecated use readFloat()
*/
public function readDouble(): float
{
trigger_deprecation(
'longitudeone/geo-wkb-parser',
'1.0',
'Method readDouble is deprecated, use readFloat instead.'
);

return $this->readFloat();
}

/**
* @return float[]
*
* @throws RangeException
* @throws UnexpectedValueException
*
* @deprecated use readFloats()
*/
public function readDoubles(int $count): array
{
trigger_deprecation(
'longitudeone/geo-wkb-parser',
'1.0',
'Method readDoubles is deprecated, use readFloats instead.'
);

return $this->readFloats($count);
}

/**
* @throws RangeException
* @throws UnexpectedValueException
Expand Down
4 changes: 2 additions & 2 deletions quality/php-mess-detector/codeclimate-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<properties>
<!-- Set the maximum class complexity to 71 because of Parser, but Parser needs to be simplified -->
<property name="maximum" value="71"/>
<!-- Set the maximum class complexity to 69 because of Parser, but Parser needs to be simplified -->
<property name="maximum" value="69"/>
</properties>
</rule>
<!-- Import the entire naming rule set -->
Expand Down
4 changes: 2 additions & 2 deletions quality/php-mess-detector/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<properties>
<!-- Set the maximum class complexity to 71 because of Parser, but Parser need to be simplified -->
<property name="maximum" value="71"/>
<!-- Set the maximum class complexity to 69 because of Parser, but Parser need to be simplified -->
<property name="maximum" value="69"/>
</properties>
</rule>
<!-- Import the entire naming rule set -->
Expand Down
10 changes: 0 additions & 10 deletions quality/php-stan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,3 @@ parameters:
message: "#^Parameter \\#1 \\$type of method LongitudeOne\\\\Geo\\\\WKB\\\\Parser\\:\\:getTypeName\\(\\) expects int, int\\|null given\\.$#"
count: 1
path: ../../lib/LongitudeOne/Geo/WKB/Parser.php

-
message: "#^Parameter \\#1 \\$input of class LongitudeOne\\\\Geo\\\\WKB\\\\Parser constructor expects string\\|null, float\\|string given\\.$#"
count: 1
path: ../../tests/LongitudeOne/Geo/WKB/Tests/ParserTest.php

-
message: "#^Parameter \\#1 \\$input of method LongitudeOne\\\\Geo\\\\WKB\\\\Parser\\:\\:parse\\(\\) expects string\\|null, float\\|string given\\.$#"
count: 1
path: ../../tests/LongitudeOne/Geo/WKB/Tests/ParserTest.php
13 changes: 5 additions & 8 deletions tests/LongitudeOne/Geo/WKB/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function tearDown(): void
}

/**
* @return \Generator<string, array{value:string|float, exception:class-string<ExceptionInterface>, message:string}, null, void>
* @return \Generator<string, array{value:string, exception:class-string<ExceptionInterface>, message:string}, null, void>
*/
public static function badBinaryData(): \Generator
{
Expand All @@ -55,11 +55,6 @@ public static function badBinaryData(): \Generator
'exception' => UnexpectedValueException::class,
'message' => 'Unsupported WKB type "21" (0x15) at byte 1',
];
yield 'badPacketType' => [
'value' => 0x0101000000000000000000F03F0000000000000040, // POINT(1 2)
'exception' => UnexpectedValueException::class,
'message' => 'Invalid byte order "16" at byte 0',
];

// Short NDR POINT
$message = 'Type d: not enough input values, need 8 values but only 4 were provided';
Expand Down Expand Up @@ -4190,8 +4185,10 @@ public static function wkbGeometryType(): \Generator
* @param class-string<ExceptionInterface> $exception
*
* @dataProvider badBinaryData
*
* @throws ExceptionInterface
*/
public function testBadBinaryData(string|float $value, string $exception, string $message): void
public function testBadBinaryData(string $value, string $exception, string $message): void
{
self::expectException($exception);
self::expectMessage($message);
Expand All @@ -4206,7 +4203,7 @@ public function testBadBinaryData(string|float $value, string $exception, string
*
* @dataProvider badBinaryData
*/
public function testBadBinaryDataWithPreparedParser(string|float $value, string $exception, string $message): void
public function testBadBinaryDataWithPreparedParser(string $value, string $exception, string $message): void
{
self::expectException($exception);
self::expectMessage($message);
Expand Down
27 changes: 0 additions & 27 deletions tests/LongitudeOne/Geo/WKB/Tests/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,6 @@ public function testBad(?string $value, array $methods, string $exception, strin
}
}

public function testDeprecation(): void
{
$reader = new Reader();

$value = '0040411D70A3D70A3D';
$value = pack('H*', $value);

$reader->load($value);

$reader->readByteOrder();

$result = $reader->readDouble();

self::assertEquals(34.23, $result);

$value = '0040411D70A3D70A3D40411D70A3D70A3D';
$value = pack('H*', $value);

$reader->load($value);

$reader->readByteOrder();

$result = $reader->readDoubles(2);

$this->assertEquals([34.23, 34.23], $result);
}

/**
* @param array{0:string, 1:float|int|null, 2:array<int|float>|int|float|null}[] $methods
*
Expand Down

0 comments on commit 389acde

Please sign in to comment.