File tree Expand file tree Collapse file tree 5 files changed +44
-1
lines changed
tests/Rule/data/EnforceNativeReturnTypehintRule Expand file tree Collapse file tree 5 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -117,7 +117,7 @@ private function getTypehintByType(
117117 bool $ topLevel
118118 ): ?string
119119 {
120- if ($ type instanceof MixedType) {
120+ if ($ type instanceof MixedType || $ this -> isUnionTypeWithMixed ( $ type ) ) {
121121 return $ this ->phpVersion ->getVersionId () >= 80_000 ? 'mixed ' : null ;
122122 }
123123
@@ -351,4 +351,19 @@ private function alwaysThrowsException(ReturnStatementsNode $node): bool
351351 return $ exitPoints !== [];
352352 }
353353
354+ private function isUnionTypeWithMixed (Type $ type ): bool
355+ {
356+ if (!$ type instanceof UnionType) {
357+ return false ;
358+ }
359+
360+ foreach ($ type ->getTypes () as $ innerType ) {
361+ if ($ innerType instanceof MixedType) {
362+ return true ;
363+ }
364+ }
365+
366+ return false ;
367+ }
368+
354369}
Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ public function requireMixed3() {}
8080 /** @return mixed|int|null */
8181 public function requireMixed4 () {}
8282
83+ /**
84+ * @template T
85+ * @param callable(): T $function
86+ * @return T|false
87+ */
88+ public function requireMixed5 (callable $ function ) {}
89+
8390 /** @return void */
8491 public function requireVoid () {} // error: Missing native return typehint void
8592
Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ public function requireMixed3() {} // error: Missing native return typehint mixe
8080 /** @return mixed|int|null */
8181 public function requireMixed4 () {} // error: Missing native return typehint mixed
8282
83+ /**
84+ * @template T
85+ * @param callable(): T $function
86+ * @return T|false
87+ */
88+ public function requireMixed5 (callable $ function ) {} // error: Missing native return typehint mixed
89+
8390 /** @return void */
8491 public function requireVoid () {} // error: Missing native return typehint void
8592
Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ public function requireMixed3() {} // error: Missing native return typehint mixe
8080 /** @return mixed|int|null */
8181 public function requireMixed4 () {} // error: Missing native return typehint mixed
8282
83+ /**
84+ * @template T
85+ * @param callable(): T $function
86+ * @return T|false
87+ */
88+ public function requireMixed5 (callable $ function ) {} // error: Missing native return typehint mixed
89+
8390 /** @return void */
8491 public function requireVoid () {} // error: Missing native return typehint void
8592
Original file line number Diff line number Diff line change @@ -80,6 +80,13 @@ public function requireMixed3() {} // error: Missing native return typehint mixe
8080 /** @return mixed|int|null */
8181 public function requireMixed4 () {} // error: Missing native return typehint mixed
8282
83+ /**
84+ * @template T
85+ * @param callable(): T $function
86+ * @return T|false
87+ */
88+ public function requireMixed5 (callable $ function ) {} // error: Missing native return typehint mixed
89+
8390 /** @return void */
8491 public function requireVoid () {} // error: Missing native return typehint void
8592
You can’t perform that action at this time.
0 commit comments