1
1
<?php
2
2
3
+ //phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
4
+
3
5
/**
4
6
* Set return type of get_taxonomies().
5
7
*/
11
13
use PhpParser \Node \Expr \FuncCall ;
12
14
use PHPStan \Analyser \Scope ;
13
15
use PHPStan \Reflection \FunctionReflection ;
14
- use PHPStan \Reflection \ParametersAcceptorSelector ;
15
16
use PHPStan \Type \Type ;
16
17
use PHPStan \Type \ArrayType ;
17
- use PHPStan \Type \IntegerType ;
18
18
use PHPStan \Type \ObjectType ;
19
19
use PHPStan \Type \StringType ;
20
20
use PHPStan \Type \Constant \ConstantStringType ;
21
+ use PHPStan \Type \TypeCombinator ;
21
22
22
23
class GetTaxonomiesDynamicFunctionReturnTypeExtension implements \PHPStan \Type \DynamicFunctionReturnTypeExtension
23
24
{
@@ -31,29 +32,32 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
31
32
*/
32
33
public function getTypeFromFunctionCall (FunctionReflection $ functionReflection , FuncCall $ functionCall , Scope $ scope ): Type
33
34
{
35
+ $ objectsReturnType = new ArrayType (new StringType (), new ObjectType ('WP_Taxonomy ' ));
36
+ $ namesReturnType = new ArrayType (new StringType (), new StringType ());
37
+ $ indeterminateReturnType = TypeCombinator::union (
38
+ $ objectsReturnType ,
39
+ $ namesReturnType
40
+ );
41
+
34
42
// Called without second $output arguments
35
43
if (count ($ functionCall ->args ) <= 1 ) {
36
- return new ArrayType ( new IntegerType (), new StringType ()) ;
44
+ return $ namesReturnType ;
37
45
}
38
46
39
47
$ argumentType = $ scope ->getType ($ functionCall ->args [1 ]->value );
40
48
41
49
// When called with a non-string $output, return default return type
42
50
if (! $ argumentType instanceof ConstantStringType) {
43
- return ParametersAcceptorSelector::selectFromArgs (
44
- $ scope ,
45
- $ functionCall ->args ,
46
- $ functionReflection ->getVariants ()
47
- )->getReturnType ();
51
+ return $ indeterminateReturnType ;
48
52
}
49
53
50
54
// Called with a string $output
51
55
switch ($ argumentType ->getValue ()) {
52
56
case 'objects ' :
53
- return new ArrayType ( new IntegerType (), new ObjectType ( ' WP_Taxonomy ' )) ;
57
+ return $ objectsReturnType ;
54
58
case 'names ' :
55
59
default :
56
- return new ArrayType ( new IntegerType (), new StringType ()) ;
60
+ return $ namesReturnType ;
57
61
}
58
62
}
59
63
}
0 commit comments