-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support int and string as template type bound
- Loading branch information
1 parent
756af18
commit 768bfab
Showing
19 changed files
with
307 additions
and
24 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
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,58 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Generic; | ||
|
||
use PHPStan\Type\IntegerType; | ||
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; | ||
use PHPStan\Type\Type; | ||
|
||
final class TemplateIntegerType extends IntegerType implements TemplateType | ||
{ | ||
|
||
use TemplateTypeTrait; | ||
use UndecidedComparisonCompoundTypeTrait; | ||
|
||
public function __construct( | ||
TemplateTypeScope $scope, | ||
TemplateTypeStrategy $templateTypeStrategy, | ||
TemplateTypeVariance $templateTypeVariance, | ||
string $name | ||
) | ||
{ | ||
$this->scope = $scope; | ||
$this->strategy = $templateTypeStrategy; | ||
$this->variance = $templateTypeVariance; | ||
$this->name = $name; | ||
$this->bound = new IntegerType(); | ||
} | ||
|
||
public function toArgument(): TemplateType | ||
{ | ||
return new self( | ||
$this->scope, | ||
new TemplateTypeArgumentStrategy(), | ||
$this->variance, | ||
$this->name | ||
); | ||
} | ||
|
||
protected function shouldGeneralizeInferredType(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return Type | ||
*/ | ||
public static function __set_state(array $properties): Type | ||
{ | ||
return new self( | ||
$properties['scope'], | ||
$properties['strategy'], | ||
$properties['variance'], | ||
$properties['name'] | ||
); | ||
} | ||
|
||
} |
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,58 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Generic; | ||
|
||
use PHPStan\Type\StringType; | ||
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; | ||
use PHPStan\Type\Type; | ||
|
||
final class TemplateStringType extends StringType implements TemplateType | ||
{ | ||
|
||
use TemplateTypeTrait; | ||
use UndecidedComparisonCompoundTypeTrait; | ||
|
||
public function __construct( | ||
TemplateTypeScope $scope, | ||
TemplateTypeStrategy $templateTypeStrategy, | ||
TemplateTypeVariance $templateTypeVariance, | ||
string $name | ||
) | ||
{ | ||
$this->scope = $scope; | ||
$this->strategy = $templateTypeStrategy; | ||
$this->variance = $templateTypeVariance; | ||
$this->name = $name; | ||
$this->bound = new StringType(); | ||
} | ||
|
||
public function toArgument(): TemplateType | ||
{ | ||
return new self( | ||
$this->scope, | ||
new TemplateTypeArgumentStrategy(), | ||
$this->variance, | ||
$this->name | ||
); | ||
} | ||
|
||
protected function shouldGeneralizeInferredType(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @param mixed[] $properties | ||
* @return Type | ||
*/ | ||
public static function __set_state(array $properties): Type | ||
{ | ||
return new self( | ||
$properties['scope'], | ||
$properties['strategy'], | ||
$properties['variance'], | ||
$properties['name'] | ||
); | ||
} | ||
|
||
} |
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
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
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ function bar() | |
} | ||
|
||
/** | ||
* @template T of int | ||
* @template T of float | ||
*/ | ||
function baz() | ||
{ | ||
|
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ interface Bar | |
} | ||
|
||
/** | ||
* @template T of int | ||
* @template T of float | ||
*/ | ||
interface Baz | ||
{ | ||
|
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 |
---|---|---|
|
@@ -45,7 +45,7 @@ class Baz | |
{ | ||
|
||
/** | ||
* @template T of int | ||
* @template T of float | ||
*/ | ||
public function doFoo() | ||
{ | ||
|
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ trait Bar | |
} | ||
|
||
/** | ||
* @template T of int | ||
* @template T of float | ||
*/ | ||
trait Baz | ||
{ | ||
|
Oops, something went wrong.