8000 [TypeInfo] Add `IntRangeType` to hold specific type details for `int` builtin types by DerManoMann · Pull Request #59676 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TypeInfo] Add IntRangeType to hold specific type details for int builtin types #59676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split ExplicitStringType off into separate branch
  • Loading branch information
DerManoMann committed Feb 22, 2025
commit e76cbc1a5680dea9b1a8c421d75743d6f54dfbd2
Original file line number Diff line number Diff line change
Expand Up @@ -946,31 +946,33 @@ public function testPseudoTypes(string $property, ?Type $type)
*/
public static function pseudoTypesProvider(): iterable
{
yield ['classString', Type::explicitString('class-string')];
yield ['classString', Type::string()];

// BC layer for type-info < 7.2
if (!interface_exists(WrappingTypeInterface::class)) {
yield ['classStringGeneric', Type::generic(Type::string(), Type::object(\stdClass::class))];
} else {
yield ['classStringGeneric', Type::explicitString('class-string')];
yield ['classStringGeneric', Type::string()];
}

yield ['htmlEscapedString', Type::explicitString('html-escaped-string')];
yield ['lowercaseString', Type::explicitString('lowercase-string')];
yield ['nonEmptyLowercaseString', Type::explicitString('non-empty-lowercase-string')];
yield ['nonEmptyString', Type::explicitString('non-empty-string')];
yield ['numericString', Type::explicitString('numeric-string')];
yield ['traitString', Type::explicitString('trait-string')];
yield ['interfaceString', Type::explicitString('interface-string')];
yield ['positiveInt', Type::intRange(1, \PHP_INT_MAX)];
yield ['negativeInt', Type::intRange(\PHP_INT_MIN, -1)];
yield ['htmlEscapedString', Type::string()];
yield ['lowercaseString', Type::string()];
yield ['nonEmptyLowercaseString', Type::string()];
yield ['nonEmptyString', Type::string()];
yield ['numericString', Type::string()];
yield ['traitString', Type::string()];
yield ['interfaceString', Type::string()];
yield ['literalString', Type::string()];
yield ['nonEmptyArray', Type::array()];
yield ['nonEmptyList', Type::list()];
yield ['scalar', Type::union(Type::int(), Type::float(), Type::string(), Type::bool())];
yield ['number', Type::union(Type::int(), Type::float())];
yield ['numeric', Type::union(Type::int(), Type::float(), Type::string())];
yield ['arrayKey', Type::union(Type::int(), Type::string())];
yield ['double', Type::float()];

yield ['positiveInt', Type::intRange(1)];
yield ['negativeInt', Type::intRange(\PHP_INT_MIN, -1)];
}

public function testDummyNamespace()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/TypeInfo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CHANGELOG
7.3
---

* Add `IntRangeType` and `ExplicitStringType` classes to hold specific type details for `int` and `string` builtin types
* Add `IntRangeType` class to hold specific type details for `int` builtin types
* Add `Type::accepts()` method
* Add `TypeFactoryTrait::fromValue()` method
* Deprecate constructing a `CollectionType` instance as a list that is not an array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ public static function resolveDataProvider(): iterable
yield [Type::float(), 'float'];
yield [Type::float(), 'double'];
yield [Type::string(), 'string'];
yield [Type::string(), 'class-string'];
yield [Type::string(), 'trait-string'];
yield [Type::string(), 'interface-string'];
yield [Type::string(), 'callable-string'];
yield [Type::string(), 'numeric-string'];
yield [Type::string(), 'lowercase-string'];
yield [Type::string(), 'non-empty-lowercase-string'];
yield [Type::string(), 'non-empty-string'];
yield [Type::string(), 'non-falsy-string'];
yield [Type::string(), 'truthy-string'];
yield [Type::string(), 'literal-string'];
yield [Type::string(), 'html-escaped-string'];
yield [Type::resource(), 'resource'];
yield [Type::object(), 'object'];
yield [Type::callable(), 'callable'];
Expand Down Expand Up @@ -138,11 +150,6 @@ public static function resolveDataProvider(): iterable
yield [Type::intRange(0, 100), 'int<0, 100>'];
yield [Type::intRange(), 'int<min, max>'];

// explicit string
yield [Type::explicitString('class-string'), 'class-string'];
yield [Type::explicitString('literal-string'), 'literal-string'];
yield [Type::explicitString('html-escaped-string'), 'html-escaped-string'];

// nullable
yield [Type::nullable(Type::int()), '?int'];

Expand Down
34 changes: 0 additions & 34 deletions src/Symfony/Component/TypeInfo/Type/ExplicitStringType.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Symfony/Component/TypeInfo/TypeFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ public static function string(): BuiltinType
return self::builtin(TypeIdentifier::STRING);
}

public static function explicitString(string $explicitType): ExplicitStringType
{
return new ExplicitStringType($explicitType);
}

/**
* @return BuiltinType<TypeIdentifier::BOOL>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ
'non-negative-int' => Type::intRange(from: 0),
'non-zero-int' => Type::union(Type::intRange(to: -1), Type::intRange(from: 1)),
'float', 'double' => Type::float(),
'string' => Type::string(),
'string',
'class-string',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to handle class-string<Foo>, and interface-string<Bar> in a specific way.
IMHO, we should split the work in 2 PRs, on for the integers stuff, and on other for the strings stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was wondering about that. Seems wrong to leave things half finished.
Happy to create a second PR. Not sure what the pattern is here - wait until this is merged, or base thge second off this branch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant to move all the string related stuff (ie: ExplicitString) in another PR. By doing that, you won't have to base the second PR on the first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Getting late here...

'trait-string',
'interface-string',
Expand All @@ -154,7 +154,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ
'non-falsy-string',
'truthy-string',
'literal-string',
'html-escaped-string' => Type::explicitString($node->name),
'html-escaped-string' => Type::string(),
'resource' => Type::resource(),
'object' => Type::object(),
'callable' => Type::callable(),
Expand Down
Loading
0