-
Notifications
You must be signed in to change notification settings - Fork 0
/
docblock.php
58 lines (45 loc) · 985 Bytes
/
docblock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
// See examples of problems in
// Psalm: https://psalm.dev/r/ecc3bf7a6a
// PHPStan: https://phpstan.org/r/d9511997-e344-40a7-9d97-625eae1a1c80
interface Animal {}
class Dog implements Animal
{
public function bark(): void {}
}
class Cat implements Animal {}
/**
* @template T of Animal
*/
interface AnimalGame
{
/** @param T $animal */
public function play(
$animal,
): void;
}
/**
* @implements AnimalGame<Dog>
*/
class DogGame implements AnimalGame
{
public function play($animal): void
{
$animal->bark();
}
}
// Given
$dog = new Dog();
$cat = new Cat();
$dogGame = new DogGame();
// This is correct
$dogGame->play($dog);
// ERROR: This should be picked up as an error by static analysis
$dogGame->play($cat);
interface Car {}
// ERROR: This should also be picked up as an error by static analysis
/** @implements AnimalGame<Car> */
class CarGame implements AnimalGame
{
public function play($animal): void {}
}