Skip to content

Commit 7755854

Browse files
authored
More precise getimagesize* return type
1 parent e1058cd commit 7755854

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

resources/functionMap.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,8 +3330,8 @@
33303330
'gethostbyname' => ['string', 'hostname'=>'string'],
33313331
'gethostbynamel' => ['list<string>|false', 'hostname'=>'string'],
33323332
'gethostname' => ['string|false'],
3333-
'getimagesize' => ['array|false', 'imagefile'=>'string', '&w_info='=>'array'],
3334-
'getimagesizefromstring' => ['array|false', 'data'=>'string', '&w_info='=>'array'],
3333+
'getimagesize' => ['array{0:int, 1: int, 2: int, 3: string, mime: string, channels?: int, bits?: int}|false', 'imagefile'=>'string', '&w_info='=>'array'],
3334+
'getimagesizefromstring' => ['array{0:int, 1: int, 2: int, 3: string, mime: string, channels?: int, bits?: int}|false', 'data'=>'string', '&w_info='=>'array'],
33353335
'getlastmod' => ['int|false'],
33363336
'getmxrr' => ['bool', 'hostname'=>'string', '&w_mxhosts'=>'array', '&w_weight='=>'array'],
33373337
'getmygid' => ['int|false'],

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,7 @@ public function dataFileAsserts(): iterable
12531253
yield from $this->gatherAssertTypes(__DIR__ . '/data/ini-get.php');
12541254
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9274.php');
12551255
yield from $this->gatherAssertTypes(__DIR__ . '/data/extract.php');
1256+
yield from $this->gatherAssertTypes(__DIR__ . '/data/image-size.php');
12561257
}
12571258

12581259
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace ImageSize;
4+
5+
6+
use function PHPStan\Testing\assertType;
7+
8+
function imageFoo(): void
9+
{
10+
$imagesize = getimagesize("img/flag.jpg");
11+
if ($imagesize === false) {
12+
return;
13+
}
14+
15+
list($width, $height, $type, $attr) = $imagesize;
16+
17+
assertType('int', $width);
18+
assertType('int', $height);
19+
assertType('int', $type);
20+
assertType('string', $attr);
21+
assertType('string', $imagesize['mime']);
22+
assertType('int', $imagesize['channels']);
23+
assertType('int', $imagesize['bits']);
24+
}
25+
26+
function imagesizeFoo(string $s): void
27+
{
28+
$imagesize = getimagesizefromstring($s);
29+
if ($imagesize === false) {
30+
return;
31+
}
32+
list($width, $height, $type, $attr) = $imagesize;
33+
34+
assertType('int', $width);
35+
assertType('int', $height);
36+
assertType('int', $type);
37+
assertType('string', $attr);
38+
assertType('string', $imagesize['mime']);
39+
assertType('int', $imagesize['channels']);
40+
assertType('int', $imagesize['bits']);
41+
}
42+
43+

0 commit comments

Comments
 (0)