-
Notifications
You must be signed in to change notification settings - Fork 0
/
attributes.php
61 lines (42 loc) · 1.04 KB
/
attributes.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
59
60
<?php
require_once __DIR__ . "/../vendor/autoload.php";
use StaticAnalysis\Generics\v1\Implement;
use StaticAnalysis\Generics\v1\Template;
use StaticAnalysis\Generics\v1\Type;
interface Animal {}
class Dog implements Animal {
public function bark(): void {}
}
class Cat implements Animal {}
#[Template('T', Animal::class)]
interface AnimalGame {
public function play(
#[Type('T')] $animal,
): void;
}
#[Implement("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);
$cat = new Cat();
$dogGame = new DogGame();
// This is correct
$dogGame->play($dog);
// This should be picked up as an error by static analysis
$dogGame->play($cat);
interface Car {}
// This should also be picked up as an error by static analysis
#[Implement("AnimalGame<Car>")]
class CarGame implements AnimalGame
{
public function play($animal): void {}
}