Skip to content

Commit 09635a1

Browse files
clxmstaabondrejmirtes
authored andcommitted
replace VarExportFunctionDynamicReturnTypeExtension with conditional-type stub
1 parent 25d6a95 commit 09635a1

7 files changed

Lines changed: 71 additions & 150 deletions

File tree

conf/config.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,6 @@ services:
13431343
tags:
13441344
- phpstan.broker.dynamicFunctionReturnTypeExtension
13451345

1346-
-
1347-
class: PHPStan\Type\Php\VarExportFunctionDynamicReturnTypeExtension
1348-
tags:
1349-
- phpstan.broker.dynamicFunctionReturnTypeExtension
1350-
13511346
-
13521347
class: PHPStan\Type\Php\MbFunctionsReturnTypeExtension
13531348
tags:

conf/config.stubFiles.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ parameters:
2020
- ../stubs/SplObjectStorage.stub
2121
- ../stubs/Exception.stub
2222
- ../stubs/arrayFunctions.stub
23+
- ../stubs/core.stub

src/Type/Php/VarExportFunctionDynamicReturnTypeExtension.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

stubs/core.stub

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* @param mixed $var
5+
* @param bool $return
6+
* @return ($return is true ? string : null)
7+
*/
8+
function var_export($var, bool $return = false) {}
9+
10+
/**
11+
* @param mixed $var
12+
* @return ($return is true ? string : bool)
13+
*/
14+
function highlight_file($var, bool $return = false) {}
15+
16+
/**
17+
* @param mixed $var
18+
* @return ($return is true ? string : bool)
19+
*/
20+
function show_source($var, bool $return = false) {}
21+
22+
/**
23+
* @param mixed $var
24+
* @return ($return is true ? string : bool)
25+
*/
26+
function highlight_string($var, bool $return = false) {}
27+
28+
/**
29+
* @param mixed $var
30+
* @param bool $return
31+
* @return ($return is true ? string : true)
32+
*/
33+
function print_r($var, bool $return = false) {}

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,86 +2615,6 @@ public function dataBinaryOperations(): array
26152615
'array{int, int, int}',
26162616
'$anotherArray = $arrayOfIntegers',
26172617
],
2618-
[
2619-
'string|null',
2620-
'var_export()',
2621-
],
2622-
[
2623-
'null',
2624-
'var_export($string)',
2625-
],
2626-
[
2627-
'null',
2628-
'var_export($string, false)',
2629-
],
2630-
[
2631-
'string',
2632-
'var_export($string, true)',
2633-
],
2634-
[
2635-
'bool|string',
2636-
'highlight_string()',
2637-
],
2638-
[
2639-
'bool',
2640-
'highlight_string($string)',
2641-
],
2642-
[
2643-
'bool',
2644-
'highlight_string($string, false)',
2645-
],
2646-
[
2647-
'string',
2648-
'highlight_string($string, true)',
2649-
],
2650-
[
2651-
'bool|string',
2652-
'highlight_file()',
2653-
],
2654-
[
2655-
'bool',
2656-
'highlight_file($string)',
2657-
],
2658-
[
2659-
'bool',
2660-
'highlight_file($string, false)',
2661-
],
2662-
[
2663-
'string',
2664-
'highlight_file($string, true)',
2665-
],
2666-
[
2667-
'bool|string',
2668-
'show_source()',
2669-
],
2670-
[
2671-
'bool',
2672-
'show_source($string)',
2673-
],
2674-
[
2675-
'bool',
2676-
'show_source($string, false)',
2677-
],
2678-
[
2679-
'string',
2680-
'show_source($string, true)',
2681-
],
2682-
[
2683-
'string|true',
2684-
'print_r()',
2685-
],
2686-
[
2687-
'true',
2688-
'print_r($string)',
2689-
],
2690-
[
2691-
'true',
2692-
'print_r($string, false)',
2693-
],
2694-
[
2695-
'string',
2696-
'print_r($string, true)',
2697-
],
26982618
[
26992619
'1',
27002620
'$one++',

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,8 @@ public function dataFileAsserts(): iterable
879879
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7106.php');
880880
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4950.php');
881881
yield from $this->gatherAssertTypes(__DIR__ . '/data/native-reflection-default-values.php');
882+
883+
yield from $this->gatherAssertTypes(__DIR__ . '/data/pr-1244.php');
882884
}
883885

884886
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Pr1244;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function foo() {
8+
/** @var string $string */
9+
$string = doFoo();
10+
11+
assertType('null', var_export());
12+
assertType('null', var_export($string));
13+
assertType('null', var_export($string, false));
14+
assertType('string', var_export($string, true));
15+
16+
assertType('bool', highlight_string());
17+
assertType('bool', highlight_string($string));
18+
assertType('bool', highlight_string($string, false));
19+
assertType('string', highlight_string($string, true));
20+
21+
assertType('bool', highlight_file());
22+
assertType('bool', highlight_file($string));
23+
assertType('bool', highlight_file($string, false));
24+
assertType('string', highlight_file($string, true));
25+
26+
assertType('bool', show_source());
27+
assertType('bool', show_source($string));
28+
assertType('bool', show_source($string, false));
29+
assertType('string', show_source($string, true));
30+
31+
assertType('true', print_r());
32+
assertType('true', print_r($string));
33+
assertType('true', print_r($string, false));
34+
assertType('string', print_r($string, true));
35+
}

0 commit comments

Comments
 (0)