-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
315 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @psalm-immutable | ||
* @implements Type<class-string> | ||
* Absence of a template declaration for the object type is intentional. Consider a trait: parent::class type declared in | ||
* this trait does not represent class of the trait, but an instance of a class that uses this trait. | ||
*/ | ||
final class ParentClassStringLiteralType implements Type | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public readonly string $declaredAtClass; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Type | ||
* @param class-string $declaredAtClass | ||
*/ | ||
public function __construct( | ||
string $declaredAtClass, | ||
) { | ||
$this->declaredAtClass = $declaredAtClass; | ||
} | ||
|
||
public function accept(TypeVisitor $visitor): mixed | ||
{ | ||
return $visitor->visitParentClassStringLiteral($this); | ||
} | ||
} |
This file contains 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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @psalm-immutable | ||
* @implements Type<object> | ||
* Absence of a template declaration for the object type is intentional. Consider a trait: parent type declared in | ||
* this trait does not represent instance of the trait, but an instance of a class that uses this trait. | ||
*/ | ||
final class ParentType implements Type | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public readonly string $declaredAtClass; | ||
|
||
/** | ||
* @var list<Type> | ||
*/ | ||
public readonly array $templateArguments; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Type | ||
* @param class-string $declaredAtClass | ||
* @param list<Type> $templateArguments | ||
*/ | ||
public function __construct( | ||
string $declaredAtClass, | ||
array $templateArguments = [], | ||
) { | ||
$this->declaredAtClass = $declaredAtClass; | ||
$this->templateArguments = $templateArguments; | ||
} | ||
|
||
public function accept(TypeVisitor $visitor): mixed | ||
{ | ||
return $visitor->visitParent($this); | ||
} | ||
} |
This file contains 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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @psalm-immutable | ||
* @implements Type<class-string> | ||
* Absence of a template declaration for the object type is intentional. Consider a trait: self::class type declared in | ||
* this trait does not represent class of the trait, but an instance of a class that uses this trait. | ||
*/ | ||
final class SelfClassStringLiteralType implements Type | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public readonly string $declaredAtClass; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Type | ||
* @param class-string $declaredAtClass | ||
*/ | ||
public function __construct( | ||
string $declaredAtClass, | ||
) { | ||
$this->declaredAtClass = $declaredAtClass; | ||
} | ||
|
||
public function accept(TypeVisitor $visitor): mixed | ||
{ | ||
return $visitor->visitSelfClassStringLiteral($this); | ||
} | ||
} |
This file contains 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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @psalm-immutable | ||
* @implements Type<object> | ||
* Absence of a template declaration for the object type is intentional. Consider a trait: self type declared in | ||
* this trait does not represent instance of the trait, but an instance of a class that uses this trait. | ||
*/ | ||
final class SelfType implements Type | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public readonly string $declaredAtClass; | ||
|
||
/** | ||
* @var list<Type> | ||
*/ | ||
public readonly array $templateArguments; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Type | ||
* @param class-string $declaredAtClass | ||
* @param list<Type> $templateArguments | ||
*/ | ||
public function __construct( | ||
string $declaredAtClass, | ||
array $templateArguments = [], | ||
) { | ||
$this->declaredAtClass = $declaredAtClass; | ||
$this->templateArguments = $templateArguments; | ||
} | ||
|
||
public function accept(TypeVisitor $visitor): mixed | ||
{ | ||
return $visitor->visitSelf($this); | ||
} | ||
} |
This file contains 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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Typhoon\Type; | ||
|
||
/** | ||
* @api | ||
* @psalm-immutable | ||
* @implements Type<class-string> | ||
* Absence of a template declaration for the object type is intentional. Consider a trait: static::class type declared in | ||
* this trait does not represent class of the trait, but an instance of a class that uses this trait. | ||
*/ | ||
final class StaticClassStringLiteralType implements Type | ||
{ | ||
/** | ||
* @var class-string | ||
*/ | ||
public readonly string $declaredAtClass; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Typhoon\Type | ||
* @param class-string $declaredAtClass | ||
*/ | ||
public function __construct( | ||
string $declaredAtClass, | ||
) { | ||
$this->declaredAtClass = $declaredAtClass; | ||
} | ||
|
||
public function accept(TypeVisitor $visitor): mixed | ||
{ | ||
return $visitor->visitStaticClassStringLiteral($this); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,9 @@ | ||
--FILE-- | ||
<?php | ||
|
||
namespace Typhoon\Type; | ||
|
||
$_type = PsalmTest::extractType(new ParentClassStringLiteralType(\stdClass::class)); | ||
/** @psalm-check-type-exact $_type = \class-string */ | ||
|
||
--EXPECT-- |
This file contains 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,9 @@ | ||
--FILE-- | ||
<?php | ||
|
||
namespace Typhoon\Type; | ||
|
||
$_type = PsalmTest::extractType(new ParentType(\stdClass::class)); | ||
/** @psalm-check-type-exact $_type = \object */ | ||
|
||
--EXPECT-- |
This file contains 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,9 @@ | ||
--FILE-- | ||
<?php | ||
|
||
namespace Typhoon\Type; | ||
|
||
$_type = PsalmTest::extractType(new SelfClassStringLiteralType(\stdClass::class)); | ||
/** @psalm-check-type-exact $_type = \class-string */ | ||
|
||
--EXPECT-- |
This file contains 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,9 @@ | ||
--FILE-- | ||
<?php | ||
|
||
namespace Typhoon\Type; | ||
|
||
$_type = PsalmTest::extractType(new SelfType(\stdClass::class)); | ||
/** @psalm-check-type-exact $_type = \object */ | ||
|
||
--EXPECT-- |
This file contains 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,9 @@ | ||
--FILE-- | ||
<?php | ||
|
||
namespace Typhoon\Type; | ||
|
||
$_type = PsalmTest::extractType(new StaticClassStringLiteralType(\stdClass::class)); | ||
/** @psalm-check-type-exact $_type = \class-string */ | ||
|
||
--EXPECT-- |
This file contains 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