Skip to content

Commit 0080806

Browse files
Merge pull request #19983 from kamil-tekiela/Remove-Gis-singletons
Remove Gis Singletons
2 parents 895153b + b2a14e0 commit 0080806

16 files changed

Lines changed: 61 additions & 250 deletions

‎psalm-baseline.xml‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4426,9 +4426,6 @@
44264426
<code><![CDATA[$geomCount]]></code>
44274427
<code><![CDATA[$type]]></code>
44284428
</MixedAssignment>
4429-
<RedundantPropertyInitializationCheck>
4430-
<code><![CDATA[isset(self::$instance)]]></code>
4431-
</RedundantPropertyInitializationCheck>
44324429
</file>
44334430
<file src="src/Gis/GisLineString.php">
44344431
<MixedArgument>
@@ -4458,9 +4455,6 @@
44584455
<code><![CDATA[$dataRow[$i]]]></code>
44594456
<code><![CDATA[$dataRow['data_length']]]></code>
44604457
</PossiblyNullArrayAccess>
4461-
<RedundantPropertyInitializationCheck>
4462-
<code><![CDATA[isset(self::$instance)]]></code>
4463-
</RedundantPropertyInitializationCheck>
44644458
</file>
44654459
<file src="src/Gis/GisMultiLineString.php">
44664460
<MixedArgument>
@@ -4506,9 +4500,6 @@
45064500
<code><![CDATA[$dataRow[$i]['data_length']]]></code>
45074501
<code><![CDATA[$dataRow['data_length']]]></code>
45084502
</PossiblyNullArrayAccess>
4509-
<RedundantPropertyInitializationCheck>
4510-
<code><![CDATA[isset(self::$instance)]]></code>
4511-
</RedundantPropertyInitializationCheck>
45124503
</file>
45134504
<file src="src/Gis/GisMultiPoint.php">
45144505
<MixedArgument>
@@ -4538,9 +4529,6 @@
45384529
<code><![CDATA[$dataRow[$i]]]></code>
45394530
<code><![CDATA[$dataRow['data_length']]]></code>
45404531
</PossiblyNullArrayAccess>
4541-
<RedundantPropertyInitializationCheck>
4542-
<code><![CDATA[isset(self::$instance)]]></code>
4543-
</RedundantPropertyInitializationCheck>
45444532
</file>
45454533
<file src="src/Gis/GisMultiPolygon.php">
45464534
<InvalidArgument>
@@ -4642,9 +4630,6 @@
46424630
<code><![CDATA[$dataRow[$k]['data_length']]]></code>
46434631
<code><![CDATA[$dataRow['data_length']]]></code>
46444632
</PossiblyNullArrayAccess>
4645-
<RedundantPropertyInitializationCheck>
4646-
<code><![CDATA[isset(self::$instance)]]></code>
4647-
</RedundantPropertyInitializationCheck>
46484633
</file>
46494634
<file src="src/Gis/GisPoint.php">
46504635
<MixedArgument>
@@ -4658,9 +4643,6 @@
46584643
<code><![CDATA[$black]]></code>
46594644
<code><![CDATA[$pointColor]]></code>
46604645
</PossiblyFalseArgument>
4661-
<RedundantPropertyInitializationCheck>
4662-
<code><![CDATA[isset(self::$instance)]]></code>
4663-
</RedundantPropertyInitializationCheck>
46644646
</file>
46654647
<file src="src/Gis/GisPolygon.php">
46664648
<InvalidArgument>
@@ -4692,9 +4674,6 @@
46924674
<code><![CDATA[$dataRow[$i]['data_length']]]></code>
46934675
<code><![CDATA[$dataRow['data_length']]]></code>
46944676
</PossiblyNullArrayAccess>
4695-
<RedundantPropertyInitializationCheck>
4696-
<code><![CDATA[isset(self::$instance)]]></code>
4697-
</RedundantPropertyInitializationCheck>
46984677
</file>
46994678
<file src="src/Gis/GisVisualization.php">
47004679
<DeprecatedMethod>

‎src/Gis/GisFactory.php‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,22 @@
1616
*/
1717
class GisFactory
1818
{
19-
/**
20-
* Returns the singleton instance of geometric class of the given type.
21-
*
22-
* @param string $type type of the geometric object
23-
*
24-
* @return GisGeometry|null the singleton instance of geometric class of the given type
25-
*/
2619
public static function fromType(string $type): GisGeometry|null
2720
{
2821
return match (strtoupper($type)) {
29-
'MULTIPOLYGON' => GisMultiPolygon::singleton(),
30-
'POLYGON' => GisPolygon::singleton(),
31-
'MULTIPOINT' => GisMultiPoint::singleton(),
32-
'POINT' => GisPoint::singleton(),
33-
'MULTILINESTRING' => GisMultiLineString::singleton(),
34-
'LINESTRING' => GisLineString::singleton(),
35-
'GEOMETRYCOLLECTION' => GisGeometryCollection::singleton(),
22+
'MULTIPOLYGON' => new GisMultiPolygon(),
23+
'POLYGON' => new GisPolygon(),
24+
'MULTIPOINT' => new GisMultiPoint(),
25+
'POINT' => new GisPoint(),
26+
'MULTILINESTRING' => new GisMultiLineString(),
27+
'LINESTRING' => new GisLineString(),
28+
'GEOMETRYCOLLECTION' => new GisGeometryCollection(),
3629
default => null,
3730
};
3831
}
3932

4033
/**
41-
* Returns the singleton instance of geometric class of the given wkt type.
34+
* Returns the instance of geometric class of the given wkt type.
4235
*/
4336
public static function fromWkt(string $wkt): GisGeometry|null
4437
{

‎src/Gis/GisGeometryCollection.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@
2323
*/
2424
class GisGeometryCollection extends GisGeometry
2525
{
26-
private static self $instance;
27-
28-
/**
29-
* A private constructor; prevents direct creation of object.
30-
*/
31-
private function __construct()
32-
{
33-
}
34-
35-
/**
36-
* Returns the singleton.
37-
*
38-
* @return GisGeometryCollection the singleton
39-
*/
40-
public static function singleton(): GisGeometryCollection
41-
{
42-
if (! isset(self::$instance)) {
43-
self::$instance = new GisGeometryCollection();
44-
}
45-
46-
return self::$instance;
47-
}
48-
4926
/**
5027
* Get coordinate extent for this wkt.
5128
*

‎src/Gis/GisLineString.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,6 @@
2424
*/
2525
class GisLineString extends GisGeometry
2626
{
27-
private static self $instance;
28-
29-
/**
30-
* A private constructor; prevents direct creation of object.
31-
*/
32-
private function __construct()
33-
{
34-
}
35-
36-
/**
37-
* Returns the singleton.
38-
*
39-
* @return GisLineString the singleton
40-
*/
41-
public static function singleton(): GisLineString
42-
{
43-
if (! isset(self::$instance)) {
44-
self::$instance = new GisLineString();
45-
}
46-
47-
return self::$instance;
48-
}
49-
5027
/**
5128
* Get coordinate extent for this wkt.
5229
*

‎src/Gis/GisMultiLineString.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,6 @@
2525
*/
2626
class GisMultiLineString extends GisGeometry
2727
{
28-
private static self $instance;
29-
30-
/**
31-
* A private constructor; prevents direct creation of object.
32-
*/
33-
private function __construct()
34-
{
35-
}
36-
37-
/**
38-
* Returns the singleton.
39-
*
40-
* @return GisMultiLineString the singleton
41-
*/
42-
public static function singleton(): GisMultiLineString
43-
{
44-
if (! isset(self::$instance)) {
45-
self::$instance = new GisMultiLineString();
46-
}
47-
48-
return self::$instance;
49-
}
50-
5128
/**
5229
* Get coordinate extent for this wkt.
5330
*

‎src/Gis/GisMultiPoint.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,6 @@
2424
*/
2525
class GisMultiPoint extends GisGeometry
2626
{
27-
private static self $instance;
28-
29-
/**
30-
* A private constructor; prevents direct creation of object.
31-
*/
32-
private function __construct()
33-
{
34-
}
35-
36-
/**
37-
* Returns the singleton.
38-
*
39-
* @return GisMultiPoint the singleton
40-
*/
41-
public static function singleton(): GisMultiPoint
42-
{
43-
if (! isset(self::$instance)) {
44-
self::$instance = new GisMultiPoint();
45-
}
46-
47-
return self::$instance;
48-
}
49-
5027
/**
5128
* Get coordinate extent for this wkt.
5229
*

‎src/Gis/GisMultiPolygon.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,6 @@
2828
*/
2929
class GisMultiPolygon extends GisGeometry
3030
{
31-
private static self $instance;
32-
33-
/**
34-
* A private constructor; prevents direct creation of object.
35-
*/
36-
private function __construct()
37-
{
38-
}
39-
40-
/**
41-
* Returns the singleton.
42-
*
43-
* @return GisMultiPolygon the singleton
44-
*/
45-
public static function singleton(): GisMultiPolygon
46-
{
47-
if (! isset(self::$instance)) {
48-
self::$instance = new GisMultiPolygon();
49-
}
50-
51-
return self::$instance;
52-
}
53-
5431
/**
5532
* Get coordinates extent for this wkt.
5633
*

‎src/Gis/GisPoint.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,6 @@
2121
*/
2222
class GisPoint extends GisGeometry
2323
{
24-
private static self $instance;
25-
26-
/**
27-
* A private constructor; prevents direct creation of object.
28-
*/
29-
private function __construct()
30-
{
31-
}
32-
33-
/**
34-
* Returns the singleton.
35-
*
36-
* @return GisPoint the singleton
37-
*/
38-
public static function singleton(): GisPoint
39-
{
40-
if (! isset(self::$instance)) {
41-
self::$instance = new GisPoint();
42-
}
43-
44-
return self::$instance;
45-
}
46-
4724
/**
4825
* Get coordinate extent for this wkt.
4926
*

‎src/Gis/GisPolygon.php‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,6 @@
2727
*/
2828
class GisPolygon extends GisGeometry
2929
{
30-
private static self $instance;
31-
32-
/**
33-
* A private constructor; prevents direct creation of object.
34-
*/
35-
private function __construct()
36-
{
37-
}
38-
39-
/**
40-
* Returns the singleton.
41-
*
42-
* @return GisPolygon the singleton
43-
*/
44-
public static function singleton(): GisPolygon
45-
{
46-
if (! isset(self::$instance)) {
47-
self::$instance = new GisPolygon();
48-
}
49-
50-
return self::$instance;
51-
}
52-
5330
/**
5431
* Get coordinate extent for this wkt.
5532
*

‎tests/unit/Gis/GisGeometryCollectionTest.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function providerForTestGetExtent(): array
4444
#[DataProvider('providerForTestGetExtent')]
4545
public function testGetExtent(string $spatial, Extent $extent): void
4646
{
47-
$object = GisGeometryCollection::singleton();
47+
$object = new GisGeometryCollection();
4848
self::assertEquals($extent, $object->getExtent($spatial));
4949
}
5050

@@ -59,7 +59,7 @@ public function testGetExtent(string $spatial, Extent $extent): void
5959
#[DataProvider('providerForTestGenerateWkt')]
6060
public function testGenerateWkt(array $gisData, int $index, string $empty, string $output): void
6161
{
62-
$object = GisGeometryCollection::singleton();
62+
$object = new GisGeometryCollection();
6363
self::assertSame($output, $object->generateWkt($gisData, $index, $empty));
6464
}
6565

@@ -157,7 +157,7 @@ public static function providerForTestGenerateWkt(): array
157157
#[DataProvider('providerForTestGenerateParams')]
158158
public function testGenerateParams(string $wkt, array $params): void
159159
{
160-
$object = GisGeometryCollection::singleton();
160+
$object = new GisGeometryCollection();
161161
self::assertSame($params, $object->generateParams($wkt));
162162
}
163163

@@ -280,7 +280,7 @@ public static function providerForTestGenerateParams(): array
280280
#[RequiresPhpExtension('gd')]
281281
public function testPrepareRowAsPng(): void
282282
{
283-
$object = GisGeometryCollection::singleton();
283+
$object = new GisGeometryCollection();
284284
$image = ImageWrapper::create(200, 124, ['red' => 229, 'green' => 229, 'blue' => 229]);
285285
self::assertNotNull($image);
286286
$object->prepareRowAsPng(
@@ -317,7 +317,7 @@ public function testPrepareRowAsPdf(
317317
ScaleData $scaleData,
318318
TCPDF $pdf,
319319
): void {
320-
$object = GisGeometryCollection::singleton();
320+
$object = new GisGeometryCollection();
321321
$object->prepareRowAsPdf($spatial, $label, $color, $scaleData, $pdf);
322322

323323
$fileExpected = $this->testDir . '/geometrycollection-expected.pdf';
@@ -361,7 +361,7 @@ public function testPrepareRowAsSvg(
361361
ScaleData $scaleData,
362362
string $output,
363363
): void {
364-
$object = GisGeometryCollection::singleton();
364+
$object = new GisGeometryCollection();
365365
$svg = $object->prepareRowAsSvg($spatial, $label, $color, $scaleData);
366366
self::assertSame($output, $svg);
367367
}
@@ -403,7 +403,7 @@ public function testPrepareRowAsOl(
403403
array $color,
404404
array $expected,
405405
): void {
406-
$object = GisGeometryCollection::singleton();
406+
$object = new GisGeometryCollection();
407407
self::assertSame($expected, $object->prepareRowAsOl($spatial, $srid, $label, $color));
408408
}
409409

0 commit comments

Comments
 (0)