29
29
use function count ;
30
30
use function in_array ;
31
31
use function intval ;
32
+ use function is_array ;
32
33
use function is_string ;
33
34
use function preg_match ;
34
35
use function sprintf ;
@@ -69,7 +70,7 @@ public function getTypeFromFunctionCall(
69
70
static fn (Type $ type ): bool => $ type ->toString ()->isLowercaseString ()->yes ()
70
71
);
71
72
72
- $ singlePlaceholderEarlyReturn = null ;
73
+ $ singlePlaceholderEarlyReturn = [] ;
73
74
$ allPatternsNonEmpty = count ($ formatStrings ) !== 0 ;
74
75
$ allPatternsNonFalsy = count ($ formatStrings ) !== 0 ;
75
76
foreach ($ formatStrings as $ constantString ) {
@@ -93,8 +94,11 @@ public function getTypeFromFunctionCall(
93
94
$ allPatternsNonFalsy = false ;
94
95
}
95
96
96
- // The printf format is %[argnum$][flags][width][.precision]specifier.
97
- if (preg_match ('/^%(?P<argnum>[0-9]*\$)?(?P<width>[0-9]*)\.?[0-9]*(?P<specifier>[sbdeEfFgGhHouxX])$/ ' , $ constantString ->getValue (), $ matches ) === 1 ) {
97
+ if (
98
+ is_array ($ singlePlaceholderEarlyReturn )
99
+ // The printf format is %[argnum$][flags][width][.precision]specifier.
100
+ && preg_match ('/^%(?P<argnum>[0-9]*\$)?(?P<width>[0-9]*)\.?[0-9]*(?P<specifier>[sbdeEfFgGhHouxX])$/ ' , $ constantString ->getValue (), $ matches ) === 1
101
+ ) {
98
102
if ($ matches ['argnum ' ] !== '' ) {
99
103
// invalid positional argument
100
104
if ($ matches ['argnum ' ] === '0$ ' ) {
@@ -122,24 +126,22 @@ public function getTypeFromFunctionCall(
122
126
$ constArgTypes = $ checkArgType ->getConstantScalarTypes ();
123
127
}
124
128
if ($ constArgTypes !== []) {
125
- $ result = [];
126
129
$ printfArgs = array_fill (0 , count ($ args ) - 1 , '' );
127
130
foreach ($ constArgTypes as $ constArgType ) {
128
131
$ printfArgs [$ checkArg - 1 ] = $ constArgType ->getValue ();
129
132
try {
130
- $ result [] = new ConstantStringType (@sprintf ($ constantString ->getValue (), ...$ printfArgs ));
133
+ $ singlePlaceholderEarlyReturn [] = new ConstantStringType (@sprintf ($ constantString ->getValue (), ...$ printfArgs ));
131
134
} catch (Throwable ) {
132
135
continue 2 ;
133
136
}
134
137
}
135
- $ singlePlaceholderEarlyReturn = TypeCombinator::union (...$ result );
136
138
137
139
continue ;
138
140
}
139
141
140
- $ singlePlaceholderEarlyReturn = $ checkArgType ->toString ();
142
+ $ singlePlaceholderEarlyReturn[] = $ checkArgType ->toString ();
141
143
} elseif ($ matches ['specifier ' ] !== 's ' ) {
142
- $ singlePlaceholderEarlyReturn = $ this ->getStringReturnType (
144
+ $ singlePlaceholderEarlyReturn[] = $ this ->getStringReturnType (
143
145
new AccessoryNumericStringType (),
144
146
$ isLowercase ,
145
147
);
@@ -149,11 +151,10 @@ public function getTypeFromFunctionCall(
149
151
}
150
152
151
153
$ singlePlaceholderEarlyReturn = null ;
152
- break ;
153
154
}
154
155
155
- if ($ singlePlaceholderEarlyReturn !== null ) {
156
- return $ singlePlaceholderEarlyReturn ;
156
+ if (is_array ( $ singlePlaceholderEarlyReturn) && count ( $ singlePlaceholderEarlyReturn ) > 0 ) {
157
+ return TypeCombinator:: union (... $ singlePlaceholderEarlyReturn) ;
157
158
}
158
159
159
160
if ($ allPatternsNonFalsy ) {
0 commit comments