Skip to content

Commit 1c6fe6d

Browse files
committed
Bump phpmyadmin/coding-standard version to 4.0
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent d747d10 commit 1c6fe6d

8 files changed

+152
-48
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"ext-dbase": "For dbf files parsing"
3737
},
3838
"require-dev": {
39-
"phpmyadmin/coding-standard": "^3.0.0",
40-
"phpstan/phpstan": "^1.4.10",
41-
"phpstan/phpstan-phpunit": "^1.0",
39+
"phpmyadmin/coding-standard": "^4.0",
40+
"phpstan/phpstan": "^1.10",
41+
"phpstan/phpstan-phpunit": "^1.3",
4242
"phpunit/phpunit": "^10.3"
4343
},
4444
"autoload": {

examples/create_shapefile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
50,
7272
0,
7373
],
74-
]
74+
],
7575
);
7676

7777
$shp->records[0]->dbfData['ID'] = '1';

phpcs.xml.dist

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313

1414
<exclude-pattern>*/examples/index.php</exclude-pattern>
1515

16-
<rule ref="PhpMyAdmin">
17-
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
18-
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
19-
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
20-
</rule>
16+
<rule ref="PhpMyAdmin"/>
2117

2218
<rule ref="SlevomatCodingStandard.ControlStructures.RequireSingleLineCondition"/>
2319
<rule ref="SlevomatCodingStandard.Functions.RequireSingleLineCall"/>

phpstan-baseline.neon

+95
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,113 @@ parameters:
1010
count: 1
1111
path: src/ShapeFile.php
1212

13+
-
14+
message: "#^Parameter \\#1 \\$string of function strtoupper expects string, mixed given\\.$#"
15+
count: 1
16+
path: src/ShapeFile.php
17+
1318
-
1419
message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|false given\\.$#"
1520
count: 6
1621
path: src/ShapeFile.php
1722

23+
-
24+
message: "#^Parameter \\#1 \\$value of static method PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:packDouble\\(\\) expects float, mixed given\\.$#"
25+
count: 1
26+
path: src/ShapeFile.php
27+
1828
-
1929
message: "#^Parameter \\#2 \\$shpFile of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:loadFromFile\\(\\) expects resource, resource\\|false given\\.$#"
2030
count: 1
2131
path: src/ShapeFile.php
2232

33+
-
34+
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
35+
count: 4
36+
path: src/ShapeRecord.php
37+
38+
-
39+
message: "#^Cannot access an offset on mixed\\.$#"
40+
count: 2
41+
path: src/ShapeRecord.php
42+
43+
-
44+
message: "#^Cannot access offset 'points' on mixed\\.$#"
45+
count: 12
46+
path: src/ShapeRecord.php
47+
48+
-
49+
message: "#^Cannot access offset int on mixed\\.$#"
50+
count: 14
51+
path: src/ShapeRecord.php
52+
53+
-
54+
message: "#^Cannot access offset int\\<\\-1, max\\> on mixed\\.$#"
55+
count: 2
56+
path: src/ShapeRecord.php
57+
58+
-
59+
message: "#^Cannot access offset int\\<0, max\\> on mixed\\.$#"
60+
count: 3
61+
path: src/ShapeRecord.php
62+
63+
-
64+
message: "#^Cannot access offset string on mixed\\.$#"
65+
count: 1
66+
path: src/ShapeRecord.php
67+
68+
-
69+
message: "#^Cannot call method hasMeasure\\(\\) on PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\|null\\.$#"
70+
count: 2
71+
path: src/ShapeRecord.php
72+
73+
-
74+
message: "#^Cannot call method readSHP\\(\\) on PhpMyAdmin\\\\ShapeFile\\\\ShapeFile\\|null\\.$#"
75+
count: 1
76+
path: src/ShapeRecord.php
77+
2378
-
2479
message: "#^Cannot cast mixed to int\\.$#"
2580
count: 2
2681
path: src/ShapeRecord.php
2782

83+
-
84+
message: "#^Parameter \\#1 \\$data of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:savePoint\\(\\) expects array, mixed given\\.$#"
85+
count: 1
86+
path: src/ShapeRecord.php
87+
88+
-
89+
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
90+
count: 15
91+
path: src/ShapeRecord.php
92+
93+
-
94+
message: "#^Parameter \\#1 \\$value of static method PhpMyAdmin\\\\ShapeFile\\\\Util\\:\\:packDouble\\(\\) expects float, mixed given\\.$#"
95+
count: 10
96+
path: src/ShapeRecord.php
97+
98+
-
99+
message: "#^Cannot access offset 0 on mixed\\.$#"
100+
count: 1
101+
path: tests/ShapeFileTest.php
102+
103+
-
104+
message: "#^Cannot access offset 1 on mixed\\.$#"
105+
count: 1
106+
path: tests/ShapeFileTest.php
107+
108+
-
109+
message: "#^Parameter \\#1 \\$point of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects array, mixed given\\.$#"
110+
count: 1
111+
path: tests/ShapeFileTest.php
112+
113+
-
114+
message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#"
115+
count: 1
116+
path: tests/ShapeFileTest.php
117+
118+
-
119+
message: "#^Parameter \\#2 \\$partIndex of method PhpMyAdmin\\\\ShapeFile\\\\ShapeRecord\\:\\:addPoint\\(\\) expects int, mixed given\\.$#"
120+
count: 1
121+
path: tests/ShapeFileTest.php
122+

src/ShapeFile.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static function supportsDbase(): bool
8585

8686
/**
8787
* @param int $shapeType File shape type, should be same as all records
88-
* @param array $boundingBox File bounding box
88+
* @param mixed[] $boundingBox File bounding box
8989
* @param string|null $fileName File name
9090
*/
9191
public function __construct(
@@ -96,7 +96,7 @@ public function __construct(
9696
'xmax' => 0.0,
9797
'ymax' => 0.0,
9898
],
99-
public ?string $fileName = null
99+
public string|null $fileName = null,
100100
) {
101101
}
102102

@@ -144,7 +144,7 @@ public function loadFromFile(string $fileName): bool
144144
*
145145
* @param string|null $fileName Name of file, otherwise existing is used
146146
*/
147-
public function saveToFile(?string $fileName = null): bool
147+
public function saveToFile(string|null $fileName = null): bool
148148
{
149149
if ($fileName !== null) {
150150
$this->fileName = $fileName;
@@ -176,8 +176,8 @@ private function getFilename(string $extension): string
176176
/**
177177
* Updates bounding box based on shpData.
178178
*
179-
* @param string $type Type of box
180-
* @param array $data ShapeRecord shpData
179+
* @param string $type Type of box
180+
* @param mixed[] $data ShapeRecord shpData
181181
*/
182182
private function updateBBox(string $type, array $data): void
183183
{
@@ -254,21 +254,21 @@ public function deleteRecord(int $index): void
254254
/**
255255
* Returns array defining fields in DBF file.
256256
*
257-
* @return array|null see setDBFHeader for more information
257+
* @return mixed[]|null see setDBFHeader for more information
258258
*/
259-
public function getDBFHeader(): ?array
259+
public function getDBFHeader(): array|null
260260
{
261261
return $this->dbfHeader;
262262
}
263263

264264
/**
265265
* Changes array defining fields in DBF file, used in dbase_create call.
266266
*
267-
* @param array $header An array of arrays, each array describing the
268-
* format of one field of the database. Each
269-
* field consists of a name, a character indicating
270-
* the field type, and optionally, a length,
271-
* a precision and a nullable flag.
267+
* @param mixed[] $header An array of arrays, each array describing the
268+
* format of one field of the database. Each
269+
* field consists of a name, a character indicating
270+
* the field type, and optionally, a length,
271+
* a precision and a nullable flag.
272272
*/
273273
public function setDBFHeader(array $header): void
274274
{
@@ -401,7 +401,7 @@ private function loadHeaders(): bool
401401
private function saveBBoxRecord($file, string $type): void
402402
{
403403
fwrite($file, Util::packDouble(
404-
$this->boundingBox[$type] ?? 0
404+
$this->boundingBox[$type] ?? 0,
405405
));
406406
}
407407

src/ShapeRecord.php

+19-14
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,24 @@ class ShapeRecord
4545
/** @var resource|false */
4646
private $dbfFile = false;
4747

48-
/** @var ShapeFile */
49-
private $shapeFile = null;
48+
private ShapeFile|null $shapeFile = null;
5049

5150
private int $size = 0;
5251

5352
private int $read = 0;
5453

5554
public int $recordNumber = 0;
5655

57-
public int $shapeType;
58-
5956
public string $lastError = '';
6057

58+
/** @var mixed[] */
6159
public array $shpData = [];
6260

61+
/** @var mixed[] */
6362
public array $dbfData = [];
6463

65-
public function __construct(int $shapeType)
64+
public function __construct(public int $shapeType)
6665
{
67-
$this->shapeType = $shapeType;
6866
}
6967

7068
/**
@@ -161,7 +159,7 @@ public function saveToFile($shpFile, $dbfFile, int $recordNumber): void
161159
/**
162160
* Updates DBF data to match header.
163161
*
164-
* @param array $header DBF structure header
162+
* @param mixed[] $header DBF structure header
165163
*/
166164
public function updateDBFInfo(array $header): void
167165
{
@@ -229,6 +227,7 @@ private function saveHeaders(): void
229227
fwrite($this->shpFile, pack('V', $this->shapeType));
230228
}
231229

230+
/** @return mixed[] */
232231
private function loadPoint(): array
233232
{
234233
return [
@@ -237,6 +236,7 @@ private function loadPoint(): array
237236
];
238237
}
239238

239+
/** @return mixed[] */
240240
private function loadPointM(): array
241241
{
242242
$data = $this->loadPoint();
@@ -246,6 +246,7 @@ private function loadPointM(): array
246246
return $data;
247247
}
248248

249+
/** @return mixed[] */
249250
private function loadPointZ(): array
250251
{
251252
$data = $this->loadPoint();
@@ -256,19 +257,22 @@ private function loadPointZ(): array
256257
return $data;
257258
}
258259

260+
/** @param mixed[] $data */
259261
private function savePoint(array $data): void
260262
{
261263
fwrite($this->shpFile, Util::packDouble($data['x']));
262264
fwrite($this->shpFile, Util::packDouble($data['y']));
263265
}
264266

267+
/** @param mixed[] $data */
265268
private function savePointM(array $data): void
266269
{
267270
fwrite($this->shpFile, Util::packDouble($data['x']));
268271
fwrite($this->shpFile, Util::packDouble($data['y']));
269272
fwrite($this->shpFile, Util::packDouble($data['m']));
270273
}
271274

275+
/** @param mixed[] $data */
272276
private function savePointZ(array $data): void
273277
{
274278
fwrite($this->shpFile, Util::packDouble($data['x']));
@@ -369,7 +373,7 @@ private function saveMultiPointRecord(): void
369373
$this->shpData['xmin'],
370374
$this->shpData['ymin'],
371375
$this->shpData['xmax'],
372-
$this->shpData['ymax']
376+
$this->shpData['ymax'],
373377
));
374378

375379
fwrite($this->shpFile, pack('V', $this->shpData['numpoints']));
@@ -480,7 +484,7 @@ private function savePolyLineRecord(): void
480484
$this->shpData['xmin'],
481485
$this->shpData['ymin'],
482486
$this->shpData['xmax'],
483-
$this->shpData['ymax']
487+
$this->shpData['ymax'],
484488
));
485489

486490
fwrite($this->shpFile, pack('VV', $this->shpData['numparts'], $this->shpData['numpoints']));
@@ -554,6 +558,7 @@ private function savePolygonZRecord(): void
554558
$this->savePolyLineZRecord();
555559
}
556560

561+
/** @param mixed[] $point */
557562
private function adjustBBox(array $point): void
558563
{
559564
// Adjusts bounding box based on point
@@ -580,9 +585,9 @@ private function adjustBBox(array $point): void
580585
* Adjust point and bounding box when adding point.
581586
* Sets dimension to 0 if not set.
582587
*
583-
* @param array $point Point data
588+
* @param mixed[] $point Point data
584589
*
585-
* @return array Fixed point data
590+
* @return mixed[] Fixed point data
586591
*/
587592
private function adjustPoint(array $point): array
588593
{
@@ -600,8 +605,8 @@ private function adjustPoint(array $point): array
600605
/**
601606
* Adds point to a record.
602607
*
603-
* @param array $point Point data
604-
* @param int $partIndex Part index
608+
* @param mixed[] $point Point data
609+
* @param int $partIndex Part index
605610
*/
606611
public function addPoint(array $point, int $partIndex = 0): void
607612
{
@@ -721,7 +726,7 @@ public function deletePoint(int $pointIndex = 0, int $partIndex = 0): void
721726
/**
722727
* Returns length of content.
723728
*/
724-
public function getContentLength(): ?int
729+
public function getContentLength(): int|null
725730
{
726731
// The content length for a record is the length of the record contents section measured in 16-bit words.
727732
// one coordinate makes 4 16-bit words (64 bit double)

0 commit comments

Comments
 (0)