Skip to content

Commit ae23a92

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Simplify abs return type
1 parent a2548e3 commit ae23a92

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed

resources/functionMap.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@
5757

5858
return [
5959
'_' => ['string', 'message'=>'string'],
60-
'abs' => ['0|positive-int', 'number'=>'int'],
61-
'abs\'1' => ['float', 'number'=>'float'],
62-
'abs\'2' => ['float|0|positive-int', 'number'=>'string'],
60+
'abs' => ['float|0|positive-int', 'num'=>'int|float'],
6361
'accelerator_get_configuration' => ['array'],
6462
'accelerator_get_scripts' => ['array'],
6563
'accelerator_get_status' => ['array', 'fetch_scripts'=>'bool'],

stubs/core.stub

+6
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,9 @@ function headers_sent(?string &$filename = null, ?int &$line = null): bool {}
307307
* @return ($value is callable ? true : false)
308308
*/
309309
function is_callable(mixed $value, bool $syntax_only = false, ?string &$callable_name = null): bool {}
310+
311+
/**
312+
* @param float|int $num
313+
* @return ($num is float ? float : $num is int ? non-negative-int : float|non-negative-int)
314+
*/
315+
function abs($num) {}

tests/PHPStan/Reflection/ParametersAcceptorSelectorTest.php

-29
Original file line numberDiff line numberDiff line change
@@ -144,35 +144,6 @@ public function dataSelectFromTypes(): Generator
144144
),
145145
];
146146

147-
$absVariants = $reflectionProvider->getFunction(new Name('abs'), null)->getVariants();
148-
yield [
149-
[
150-
new FloatType(),
151-
new FloatType(),
152-
],
153-
$absVariants,
154-
false,
155-
ParametersAcceptorSelector::combineAcceptors($absVariants),
156-
];
157-
yield [
158-
[
159-
new FloatType(),
160-
new IntegerType(),
161-
new StringType(),
162-
],
163-
$absVariants,
164-
false,
165-
ParametersAcceptorSelector::combineAcceptors($absVariants),
166-
];
167-
yield [
168-
[
169-
new StringType(),
170-
],
171-
$absVariants,
172-
false,
173-
$absVariants[2],
174-
];
175-
176147
$strtokVariants = $reflectionProvider->getFunction(new Name('strtok'), null)->getVariants();
177148
yield [
178149
[],

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -1777,4 +1777,13 @@ public function testBug11559b(): void
17771777
]);
17781778
}
17791779

1780+
public function testBug9224(): void
1781+
{
1782+
if (PHP_VERSION_ID < 80100) {
1783+
$this->markTestSkipped('Test requires PHP 8.1.');
1784+
}
1785+
1786+
$this->analyse([__DIR__ . '/data/bug-9224.php'], []);
1787+
}
1788+
17801789
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types = 1); // lint >= 8.1
2+
3+
namespace Bug3425;
4+
5+
class HelloWorld
6+
{
7+
/** @param array<int> $arr */
8+
public function sayHello(array $arr): void
9+
{
10+
array_map(abs(...), $arr);
11+
}
12+
}

0 commit comments

Comments
 (0)