Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc82b67

Browse files
committed
bug#59844 [TypeInfo] FixisSatisfiedBy not traversing type tree (mtarld)
This PR was merged into the 7.2 branch.Discussion----------[TypeInfo] Fix `isSatisfiedBy` not traversing type tree| Q | A| ------------- | ---| Branch? | 7.2| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues || License | MITPreviously, `Type::isSatisfiedBy` was not traversing the type tree, which means that:```php$specification = static fn (Type $type): bool => $type instanceof ObjectType;return Type::collection(Type::object(Foo::class))->isSatisfiedBy($specification);```was unexpectedly returning `false`.This PR fixes it.Commits-------8df764a [TypeInfo] Fix `isSatisfiedBy` not traversing type tree
2 parents4471969 +8df764a commitbc82b67

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

‎src/Symfony/Component/TypeInfo/Tests/TypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
usePHPUnit\Framework\TestCase;
1515
useSymfony\Component\TypeInfo\Type;
16+
useSymfony\Component\TypeInfo\Type\CollectionType;
17+
useSymfony\Component\TypeInfo\Type\UnionType;
1618
useSymfony\Component\TypeInfo\TypeIdentifier;
1719

1820
class TypeTestextends TestCase
@@ -34,4 +36,12 @@ public function testIsNullable()
3436

3537
$this->assertFalse(Type::int()->isNullable());
3638
}
39+
40+
publicfunctiontestIsSatisfiedBy()
41+
{
42+
$this->assertTrue(Type::union(Type::int(), Type::string())->isSatisfiedBy(fn (Type$t):bool =>'int' === (string)$t));
43+
$this->assertTrue(Type::union(Type::int(), Type::string())->isSatisfiedBy(fn (Type$t):bool =>$tinstanceof UnionType));
44+
$this->assertTrue(Type::list(Type::int())->isSatisfiedBy(fn (Type$t):bool =>$tinstanceof CollectionType &&'int' === (string)$t->getCollectionValueType()));
45+
$this->assertFalse(Type::list(Type::int())->isSatisfiedBy(fn (Type$t):bool =>'int' === (string)$t));
46+
}
3747
}

‎src/Symfony/Component/TypeInfo/Type.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ abstract class Type implements \Stringable
2929
*/
3030
publicfunctionisSatisfiedBy(callable$specification):bool
3131
{
32+
if ($thisinstanceof WrappingTypeInterface &&$this->wrappedTypeIsSatisfiedBy($specification)) {
33+
returntrue;
34+
}
35+
36+
if ($thisinstanceof CompositeTypeInterface &&$this->composedTypesAreSatisfiedBy($specification)) {
37+
returntrue;
38+
}
39+
3240
return$specification($this);
3341
}
3442

@@ -37,19 +45,17 @@ public function isSatisfiedBy(callable $specification): bool
3745
*/
3846
publicfunctionisIdentifiedBy(TypeIdentifier|string ...$identifiers):bool
3947
{
40-
$specification =staticfunction (Type$type)use (&$specification,$identifiers):bool {
41-
if ($typeinstanceof WrappingTypeInterface) {
42-
return$type->wrappedTypeIsSatisfiedBy($specification);
43-
}
48+
$specification =staticfn (Type$type):bool =>$type->isIdentifiedBy(...$identifiers);
4449

45-
if ($typeinstanceofCompositeTypeInterface) {
46-
return$type->composedTypesAreSatisfiedBy($specification);
47-
}
50+
if ($thisinstanceofWrappingTypeInterface &&$this->wrappedTypeIsSatisfiedBy($specification)) {
51+
returntrue;
52+
}
4853

49-
return$type->isIdentifiedBy(...$identifiers);
50-
};
54+
if ($thisinstanceof CompositeTypeInterface &&$this->composedTypesAreSatisfiedBy($specification)) {
55+
returntrue;
56+
}
5157

52-
return$this->isSatisfiedBy($specification);
58+
returnfalse;
5359
}
5460

5561
publicfunctionisNullable():bool

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp