Skip to content
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

Fix PHP 8.1 issue: Passing null to parameter #1 ($string) of type string is deprecated #218

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6dff52a
Use existing local var
djlambert Feb 25, 2016
f36081c
Merge pull request #136 from djlambert/develop
sadortun Feb 25, 2016
0a5b64e
Use strict compare. Compare to null is cheaper.
djlambert Mar 22, 2016
7dcdbda
Correct namespace
djlambert Mar 22, 2016
9d453d9
Set result cache in tests
djlambert Mar 22, 2016
23a1c35
CS/WS
djlambert Mar 22, 2016
f3a83b2
Replace switch with if
djlambert Mar 23, 2016
9682cea
LineString Geometry test
djlambert Mar 23, 2016
919f0dc
Doctrine test case not longer needed. Add test namespace to composer.…
djlambert Mar 23, 2016
3a30cb5
Name is a required attribute of testsuite
djlambert Mar 23, 2016
01a1857
Travis config needs changes too
djlambert Mar 23, 2016
2639aad
Merge pull request #139 from djlambert/develop
sadortun Mar 23, 2016
fc32501
Do not parse numeric values in Point coordinate setters
Mar 23, 2016
dad1285
Merge pull request #141 from JanJakes/coordinate-parsing-fix
sadortun Apr 6, 2016
0ab1363
Add test for #141
djlambert Apr 6, 2016
a23d299
Use type safe comparisons. Replace is_null will null comparison. Remo…
djlambert Apr 6, 2016
40bc131
Merge pull request #145 from djlambert/develop
sadortun Apr 7, 2016
cd2d588
Merge pull request #150 from creof/master
sadortun Apr 7, 2016
3b73bcf
Merge coverage changes from master into develop
djlambert Apr 29, 2016
501df61
Merge pull request #154 from djlambert/develop
djlambert Apr 29, 2016
063e030
Fix mysql 8 compatibility issues
prostodima Jan 3, 2019
e751602
Merge pull request #1 from prostodima/develop
prostodima Dec 30, 2021
ad7537e
Update composer.json to fetch prostodima/wkb-parser
Jan 4, 2022
940bf96
Merge pull request #2 from prostodima/develop
prostodima Jan 4, 2022
90e6bf2
Fix wkb-parser version
prostodima Jan 5, 2022
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
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"doctrine/orm": ">=2.3",
"creof/geo-parser": "~2.0",
"creof/wkt-parser": "~2.0",
"creof/wkb-parser": "~2.0"
"creof/wkb-parser": "2.4.0"
},
"require-dev": {
"phpunit/phpunit": "<5.0",
Expand All @@ -25,5 +25,16 @@
"psr-0": {
"CrEOF\\Spatial": "lib/"
}
}
},
"autoload-dev": {
"psr-0": {
"CrEOF\\Spatial\\Tests": "tests/"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/prostodima/wkb-parser.git"
}
]
}
4 changes: 2 additions & 2 deletions lib/CrEOF/Spatial/DBAL/Platform/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getSQLDeclaration(array $fieldDeclaration)
*/
public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
{
return sprintf('AsBinary(%s)', $sqlExpr);
return sprintf('ST_AsBinary(%s)', $sqlExpr);
}

/**
Expand All @@ -69,6 +69,6 @@ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
*/
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
{
return sprintf('GeomFromText(%s)', $sqlExpr);
return sprintf('ST_GeomFromText(%s)', $sqlExpr);
}
}
13 changes: 4 additions & 9 deletions lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function validatePointValue($point)
case ($point instanceof AbstractPoint):
return $point->toArray();
break;
case (is_array($point) && count($point) == 2 && is_numeric($point[0]) && is_numeric($point[1])):
case (is_array($point) && count($point) === 2 && is_numeric($point[0]) && is_numeric($point[1])):
return array_values($point);
break;
default:
Expand All @@ -115,14 +115,8 @@ protected function validatePointValue($point)
*/
protected function validateRingValue($ring)
{
switch (true) {
case ($ring instanceof AbstractLineString):
$ring = $ring->toArray();
break;
case (is_array($ring)):
break;
default:
throw new InvalidValueException(sprintf('Invalid %s LineString value of type "%s"', $this->getType(), (is_object($ring) ? get_class($ring) : gettype($ring))));
if (! (is_array($ring) || $ring instanceof AbstractLineString)) {
throw new InvalidValueException(sprintf('Invalid %s LineString value of type "%s"', $this->getType(), (is_object($ring) ? get_class($ring) : gettype($ring))));
}

$ring = $this->validateLineStringValue($ring);
Expand Down Expand Up @@ -187,6 +181,7 @@ protected function validateMultiPolygonValue(array $polygons)
if ($polygon instanceof GeometryInterface) {
$polygon = $polygon->toArray();
}

$polygon = $this->validatePolygonValue($polygon);
}

Expand Down
52 changes: 29 additions & 23 deletions lib/CrEOF/Spatial/PHP/Types/AbstractPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ public function __construct()
*/
public function setX($x)
{
$parser = new Parser($x);

try {
$this->x = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
if (! is_numeric($x)) {
$parser = new Parser($x);

try {
$x = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$this->x = (float) $x;

return $this;
}

Expand All @@ -93,16 +97,20 @@ public function getX()
*/
public function setY($y)
{
$parser = new Parser($y);

try {
$this->y = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
if (! is_numeric($y)) {
$parser = new Parser($y);

try {
$y = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$this->y = (float) $y;

return $this;
}

Expand Down Expand Up @@ -177,12 +185,12 @@ protected function validateArguments(array $argv = null)
{
$argc = count($argv);

if (1 == $argc && is_array($argv[0])) {
if (1 === $argc && is_array($argv[0])) {
return $argv[0];
}

if (2 == $argc) {
if (is_array($argv[0]) && (is_numeric($argv[1]) || is_null($argv[1]) || is_string($argv[1]))) {
if (2 === $argc) {
if (is_array($argv[0]) && (is_numeric($argv[1]) || null === $argv[1] || is_string($argv[1]))) {
$argv[0][] = $argv[1];

return $argv[0];
Expand All @@ -193,10 +201,8 @@ protected function validateArguments(array $argv = null)
}
}

if (3 == $argc) {
if ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || is_null($argv[2]) || is_string($argv[2]))) {
return $argv;
}
if (3 === $argc && ((is_numeric($argv[0]) || is_string($argv[0])) && (is_numeric($argv[1]) || is_string($argv[1])) && (is_numeric($argv[2]) || null === $argv[2] || is_string($argv[2])))) {
return $argv;
}

array_walk($argv, function (&$value) {
Expand Down
2 changes: 1 addition & 1 deletion lib/CrEOF/Spatial/PHP/Types/AbstractPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getRings()
*/
public function getRing($index)
{
if (-1 == $index) {
if (-1 === $index) {
$index = count($this->rings) - 1;
}

Expand Down
34 changes: 20 additions & 14 deletions lib/CrEOF/Spatial/PHP/Types/Geography/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ class Point extends AbstractPoint implements GeographyInterface
*/
public function setX($x)
{
$parser = new Parser($x);
if (!is_numeric($x)) {
$parser = new Parser($x);

try {
$x = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
try {
$x = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$x = (float) $x;
if ($x < -180 || $x > 180) {
throw new InvalidValueException(sprintf('Invalid longitude value "%s", must be in range -180 to 180.', $x));
}
Expand All @@ -72,16 +75,19 @@ public function setX($x)
*/
public function setY($y)
{
$parser = new Parser($y);
if (!is_numeric($y)) {
$parser = new Parser($y);

try {
$y = (float) $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
try {
$y = $parser->parse();
} catch (RangeException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
} catch (UnexpectedValueException $e) {
throw new InvalidValueException($e->getMessage(), $e->getCode(), $e->getPrevious());
}
}

$y = (float) $y;
if ($y < -90 || $y > 90) {
throw new InvalidValueException(sprintf('Invalid latitude value "%s", must be in range -90 to 90.', $y));
}
Expand Down
19 changes: 11 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit backupGlobals="false"
colors="true"
bootstrap="./tests/CrEOF/Spatial/Tests/TestInit.php"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="./vendor/autoload.php"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
>

<testsuites>
<testsuite>
<testsuite name="Tests">
<directory>./tests/CrEOF/Spatial/Tests</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion tests/CrEOF/Spatial/Tests/DBAL/Types/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testDoctrineTypeMapping()
$databaseTypes = $type->getMappedDatabaseTypes($platform);

foreach ($databaseTypes as $databaseType) {
$typeMapping = $this->getPlatform()->getDoctrineTypeMapping($databaseType);
$typeMapping = $platform->getDoctrineTypeMapping($databaseType);

$this->assertEquals($doctrineType, $typeMapping);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/CrEOF/Spatial/Tests/OrmTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected function setUp()
*/
protected function getEntityManager()
{
if (isset($this->entityManager)) {
if (null !== $this->entityManager) {
return $this->entityManager;
}

Expand All @@ -209,7 +209,8 @@ protected function getEntityManager()

$config = new Configuration();

$config->setMetadataCacheImpl(new ArrayCache);
$config->setMetadataCacheImpl(new ArrayCache());
$config->setResultCacheImpl(new ArrayCache());
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('CrEOF\Spatial\Tests\Proxies');
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures')), true));
Expand Down
89 changes: 89 additions & 0 deletions tests/CrEOF/Spatial/Tests/PHP/Types/Geography/LineStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright (C) 2015 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\Tests\PHP\Types\Geography;

use CrEOF\Spatial\Exception\InvalidValueException;
use CrEOF\Spatial\PHP\Types\Geography\LineString;
use CrEOF\Spatial\PHP\Types\Geography\Point;

/**
* LineString object tests
*
* @author Derek J. Lambert <[email protected]>
* @license http://dlambert.mit-license.org MIT
*
* @group php
*/
class LineStringTest extends \PHPUnit_Framework_TestCase
{

/**
* @expectedException \CrEOF\Spatial\Exception\InvalidValueException
* @expectedExceptionMessage Invalid longitude value "550", must be in range -180 to 180.
*/
public function testLineStringFromObjectsToArray()
{
$expected = array(
array(550, 550),
array(551, 551),
array(552, 552),
array(553, 553)
);
$lineString = new LineString(array(
new Point(550, 550),
new Point(551, 551),
new Point(552, 552),
new Point(553, 553)
));

$this->assertCount(4, $lineString->getPoints());
$this->assertEquals($expected, $lineString->toArray());
}

/**
* @expectedException \CrEOF\Spatial\Exception\InvalidValueException
* @expectedExceptionMessage Invalid longitude value "550", must be in range -180 to 180.
*/
public function testLineStringFromArraysGetPoints()
{
$expected = array(
array(550, 550),
array(551, 551),
array(552, 552),
array(553, 553)
);
$lineString = new LineString(
array(
array(550, 550),
array(551, 551),
array(552, 552),
array(553, 553)
)
);
$actual = $lineString->getPoints();

$this->assertCount(4, $actual);
$this->assertEquals($expected, $actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* SOFTWARE.
*/

namespace CrEOF\Spatial\Tests\PHP\Types\Spatial\Geometry;
namespace CrEOF\Spatial\Tests\PHP\Types\Geometry;

use CrEOF\Spatial\PHP\Types\Geometry\LineString;
use CrEOF\Spatial\PHP\Types\Geometry\Point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ public function testSolidMultiLineStringFromArraysGetRings()
$this->assertEquals($expected, $multiLineString->getLineStrings());
}



public function testSolidMultiLineStringAddRings()
{
$expected = array(
Expand Down
Loading