Skip to content

Commit a645445

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents 72c2a8d + 7644bd0 commit a645445

File tree

6 files changed

+80
-1
lines changed

6 files changed

+80
-1
lines changed

resources/functionMap_php80delta.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
'imagejpeg' => ['bool', 'im'=>'GdImage', 'filename='=>'string|resource|null', 'quality='=>'int'],
8383
'imagerotate' => ['false|object', 'src_im'=>'resource', 'angle'=>'float', 'bgdcolor'=>'int', 'ignoretransparent='=>'int'],
8484
'imagescale' => ['false|object', 'im'=>'resource', 'new_width'=>'int', 'new_height='=>'int', 'method='=>'int'],
85+
'getenv' => ['string|false', 'varname'=>'string', 'local_only='=>'bool'],
86+
'getenv\'1' => ['array<string, string>', 'varname='=>'null', 'local_only='=>'bool'],
8587
'ldap_set_rebind_proc' => ['bool', 'ldap'=>'resource', 'callback'=>'?callable'],
8688
'mb_decode_numericentity' => ['string|false', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string'],
8789
'mb_detect_order' => ['bool|list<non-falsy-string>', 'encoding_list='=>'non-empty-list<non-falsy-string>|non-falsy-string|null'],

src/Command/InceptionResult.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,15 @@ public function getEditorModeInsteadOfFile(): ?string
103103
public function handleReturn(int $exitCode, ?int $peakMemoryUsageBytes, float $analysisStartTime): int
104104
{
105105
if ($this->getErrorOutput()->isVerbose()) {
106+
$elapsedTime = round(microtime(true) - $analysisStartTime, 2);
107+
if ($elapsedTime < 10) {
108+
$elapsedTimeString = sprintf('%.2f seconds', $elapsedTime);
109+
} else {
110+
$elapsedTimeString = $this->formatDuration((int) $elapsedTime);
111+
}
106112
$this->getErrorOutput()->writeLineFormatted(sprintf(
107113
'Elapsed time: %s',
108-
$this->formatDuration((int) round(microtime(true) - $analysisStartTime)),
114+
$elapsedTimeString,
109115
));
110116
}
111117

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php // lint < 8.0
2+
3+
namespace GetenvPHP74;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
/**
10+
* @param string|null $stringOrNull
11+
* @param mixed $mixed
12+
*/
13+
public function test($stringOrNull, $mixed)
14+
{
15+
assertType('string|false', getenv(null));
16+
assertType('array<string, string>', getenv());
17+
assertType('string|false', getenv('foo'));
18+
19+
assertType('string|false', getenv($stringOrNull));
20+
assertType('string|false', getenv($mixed));
21+
}
22+
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php // lint >= 8.0
2+
3+
namespace GetenvPHP80;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
10+
public function test(string|null $stringOrNull, mixed $mixed)
11+
{
12+
assertType('array<string, string>', getenv(null));
13+
assertType('array<string, string>', getenv());
14+
assertType('string|false', getenv('foo'));
15+
16+
assertType('array<string, string>|string|false', getenv($stringOrNull));
17+
assertType('array<string, string>|string|false', getenv($mixed));
18+
}
19+
20+
}

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,4 +2248,17 @@ public function testBug12954(): void
22482248
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12954.php'], []);
22492249
}
22502250

2251+
public function testBug13065(): void
2252+
{
2253+
$errors = [];
2254+
if (PHP_VERSION_ID < 80000) {
2255+
$errors[] = [
2256+
'Parameter #1 $varname of function getenv expects string, null given.',
2257+
10,
2258+
];
2259+
}
2260+
2261+
$this->analyse([__DIR__ . '/data/bug-13065.php'], $errors);
2262+
}
2263+
22512264
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug13065;
4+
5+
class Foo
6+
{
7+
8+
public function test()
9+
{
10+
getenv(null);
11+
getenv();
12+
getenv('foo');
13+
}
14+
15+
}

0 commit comments

Comments
 (0)