File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -233,13 +233,13 @@ public function isClassKeyword(): bool
233233 /**
234234 * Verifies type compatibility. For example, it checks if a value of a certain type could be passed as a parameter.
235235 */
236- public function allows (string $ type ): bool
236+ public function allows (string | self $ type ): bool
237237 {
238238 if ($ this ->types === ['mixed ' ]) {
239239 return true ;
240240 }
241241
242- $ type = self ::fromString ($ type );
242+ $ type = is_string ( $ type ) ? self ::fromString ($ type ) : $ type ;
243243 return $ type ->isUnion ()
244244 ? Arrays::every ($ type ->types , fn ($ t ) => $ this ->allowsAny ($ t instanceof self ? $ t ->types : [$ t ]))
245245 : $ this ->allowsAny ($ type ->types );
Original file line number Diff line number Diff line change @@ -92,3 +92,10 @@ Assert::true($type->allows('Foo&Bar'));
9292Assert::true ($ type ->allows ('FooChild&Bar ' ));
9393Assert::true ($ type ->allows ('Foo&Bar&Baz ' ));
9494Assert::true ($ type ->allows ('(Foo&Bar&Baz)|null ' ));
95+
96+
97+ // allows() with Type object
98+ $ type = Type::fromString ('string|int ' );
99+ Assert::true ($ type ->allows (Type::fromString ('string ' )));
100+ Assert::true ($ type ->allows (Type::fromString ('int ' )));
101+ Assert::false ($ type ->allows (Type::fromString ('bool ' )));
You can’t perform that action at this time.
0 commit comments