-
-
Notifications
You must be signed in to change notification settings - Fork 51
Add support for conditional types, offset access types and key-of, value-of, int-mask, int-mask-of
#225
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
Merged
Merged
Add support for conditional types, offset access types and key-of, value-of, int-mask, int-mask-of
#225
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ad3753
Add the `TypeNode` property to `Mixed_`
mspirkov 42b2378
Conditional, ConditionalForParameter, IntMask, IntMaskOf, KeyOf, Offs…
mspirkov 567b14f
fixes
mspirkov 8951a29
fix
mspirkov 0d91e7f
fix
mspirkov 75a02d7
fix cs
mspirkov 7bc7dd3
fix cs
mspirkov 2adbaf4
cr fix
mspirkov 4abe9a0
cr fix
mspirkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link http://phpdoc.org | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
|
||
| use phpDocumentor\Reflection\PseudoType; | ||
| use phpDocumentor\Reflection\Type; | ||
| use phpDocumentor\Reflection\Types\Mixed_; | ||
|
|
||
| use function sprintf; | ||
|
|
||
| /** | ||
| * Value Object representing the conditional type. | ||
| * | ||
| * @psalm-immutable | ||
| */ | ||
| final class Conditional extends Mixed_ implements PseudoType | ||
| { | ||
| /** @var bool */ | ||
| private $negated; | ||
| /** @var Type */ | ||
| private $subjectType; | ||
| /** @var Type */ | ||
| private $targetType; | ||
| /** @var Type */ | ||
| private $if; | ||
| /** @var Type */ | ||
| private $else; | ||
|
|
||
| public function __construct(bool $negated, Type $subjectType, Type $targetType, Type $if, Type $else) | ||
| { | ||
| $this->negated = $negated; | ||
| $this->subjectType = $subjectType; | ||
| $this->targetType = $targetType; | ||
| $this->if = $if; | ||
| $this->else = $else; | ||
| } | ||
|
|
||
| public function isNegated(): bool | ||
| { | ||
| return $this->negated; | ||
| } | ||
|
|
||
| public function getSubjectType(): Type | ||
| { | ||
| return $this->subjectType; | ||
| } | ||
|
|
||
| public function getTargetType(): Type | ||
| { | ||
| return $this->targetType; | ||
| } | ||
|
|
||
| public function getIf(): Type | ||
| { | ||
| return $this->if; | ||
| } | ||
|
|
||
| public function getElse(): Type | ||
| { | ||
| return $this->else; | ||
| } | ||
|
|
||
| public function underlyingType(): Type | ||
| { | ||
| return new Mixed_(); | ||
| } | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return sprintf( | ||
| '(%s %s %s ? %s : %s)', | ||
| (string) $this->subjectType, | ||
| $this->negated ? 'is not' : 'is', | ||
| (string) $this->targetType, | ||
| (string) $this->if, | ||
| (string) $this->else | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link http://phpdoc.org | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
|
||
| use phpDocumentor\Reflection\PseudoType; | ||
| use phpDocumentor\Reflection\Type; | ||
| use phpDocumentor\Reflection\Types\Mixed_; | ||
|
|
||
| use function sprintf; | ||
|
|
||
| /** | ||
| * Value Object representing the conditional type for parameter. | ||
| * | ||
| * @psalm-immutable | ||
| */ | ||
| final class ConditionalForParameter extends Mixed_ implements PseudoType | ||
| { | ||
| /** @var bool */ | ||
| private $negated; | ||
| /** @var string */ | ||
| private $parameterName; | ||
| /** @var Type */ | ||
| private $targetType; | ||
| /** @var Type */ | ||
| private $if; | ||
| /** @var Type */ | ||
| private $else; | ||
|
|
||
| public function __construct(bool $negated, string $parameterName, Type $targetType, Type $if, Type $else) | ||
| { | ||
| $this->negated = $negated; | ||
| $this->parameterName = $parameterName; | ||
| $this->targetType = $targetType; | ||
| $this->if = $if; | ||
| $this->else = $else; | ||
| } | ||
|
|
||
| public function isNegated(): bool | ||
| { | ||
| return $this->negated; | ||
| } | ||
|
|
||
| public function getParameterName(): string | ||
| { | ||
| return $this->parameterName; | ||
| } | ||
|
|
||
| public function getTargetType(): Type | ||
| { | ||
| return $this->targetType; | ||
| } | ||
|
|
||
| public function getIf(): Type | ||
| { | ||
| return $this->if; | ||
| } | ||
|
|
||
| public function getElse(): Type | ||
| { | ||
| return $this->else; | ||
| } | ||
|
|
||
| public function underlyingType(): Type | ||
| { | ||
| return new Mixed_(); | ||
| } | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return sprintf( | ||
| '(%s %s %s ? %s : %s)', | ||
| '$' . $this->parameterName, | ||
| $this->negated ? 'is not' : 'is', | ||
| (string) $this->targetType, | ||
| (string) $this->if, | ||
| (string) $this->else | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link http://phpdoc.org | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
|
||
| use phpDocumentor\Reflection\PseudoType; | ||
| use phpDocumentor\Reflection\Type; | ||
| use phpDocumentor\Reflection\Types\Integer; | ||
|
|
||
| use function implode; | ||
|
|
||
| /** | ||
| * Value Object representing the `int-mask` type. | ||
| * | ||
| * @psalm-immutable | ||
| */ | ||
| final class IntMask implements PseudoType | ||
| { | ||
| /** @var Type[] */ | ||
| private $types; | ||
|
|
||
| public function __construct(Type ...$types) | ||
| { | ||
| $this->types = $types; | ||
| } | ||
|
|
||
| /** | ||
| * @return Type[] | ||
| */ | ||
| public function getTypes(): array | ||
| { | ||
| return $this->types; | ||
| } | ||
|
|
||
| public function underlyingType(): Type | ||
| { | ||
| return new Integer(); | ||
| } | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return 'int-mask<' . implode(', ', $this->types) . '>'; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link http://phpdoc.org | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
|
||
| use phpDocumentor\Reflection\PseudoType; | ||
| use phpDocumentor\Reflection\Type; | ||
| use phpDocumentor\Reflection\Types\Integer; | ||
|
|
||
| /** | ||
| * Value Object representing the `int-mask-of` type. | ||
| * | ||
| * @psalm-immutable | ||
| */ | ||
| final class IntMaskOf implements PseudoType | ||
mspirkov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /** @var Type */ | ||
| private $type; | ||
|
|
||
| public function __construct(Type $type) | ||
| { | ||
| $this->type = $type; | ||
| } | ||
|
|
||
| public function getType(): Type | ||
| { | ||
| return $this->type; | ||
| } | ||
|
|
||
| public function underlyingType(): Type | ||
| { | ||
| return new Integer(); | ||
| } | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return 'int-mask-of<' . $this->type . '>'; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
| /* | ||
| * This file is part of phpDocumentor. | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| * | ||
| * @link http://phpdoc.org | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace phpDocumentor\Reflection\PseudoTypes; | ||
|
|
||
| use phpDocumentor\Reflection\PseudoType; | ||
| use phpDocumentor\Reflection\Type; | ||
| use phpDocumentor\Reflection\Types\ArrayKey; | ||
|
|
||
| /** | ||
| * Value Object representing the `key-of` type. | ||
| * | ||
| * @psalm-immutable | ||
| */ | ||
| final class KeyOf implements PseudoType | ||
mspirkov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /** @var Type */ | ||
| private $type; | ||
|
|
||
| public function __construct(Type $type) | ||
| { | ||
| $this->type = $type; | ||
| } | ||
|
|
||
| public function getType(): Type | ||
| { | ||
| return $this->type; | ||
| } | ||
|
|
||
| public function underlyingType(): Type | ||
| { | ||
| return new ArrayKey(); | ||
| } | ||
|
|
||
| public function __toString(): string | ||
| { | ||
| return 'key-of<' . $this->type . '>'; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.