-
Notifications
You must be signed in to change notification settings - Fork 433
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
1 parent
adb41f9
commit 6c9b52e
Showing
2 changed files
with
58 additions
and
0 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,52 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace ComplexGenericsExample; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
/** | ||
* @template TVariant of VariantInterface | ||
*/ | ||
interface ExperimentInterface | ||
{ | ||
} | ||
|
||
interface VariantInterface | ||
{ | ||
} | ||
|
||
interface VariantRetrieverInterface | ||
{ | ||
/** | ||
* @template TVariant of VariantInterface | ||
* @param ExperimentInterface<TVariant> $experiment | ||
* @return TVariant | ||
*/ | ||
public function getVariant(ExperimentInterface $experiment): VariantInterface; | ||
} | ||
|
||
/** | ||
* @implements ExperimentInterface<SomeVariant> | ||
*/ | ||
class SomeExperiment implements ExperimentInterface | ||
{ | ||
} | ||
|
||
class SomeVariant implements VariantInterface | ||
{ | ||
} | ||
|
||
class SomeClass | ||
{ | ||
private $variantRetriever; | ||
|
||
public function __construct(VariantRetrieverInterface $variantRetriever) | ||
{ | ||
$this->variantRetriever = $variantRetriever; | ||
} | ||
|
||
public function someFunction(): void | ||
{ | ||
assertType('ComplexGenericsExample\SomeVariant', $this->variantRetriever->getVariant(new SomeExperiment())); | ||
} | ||
} |