-
Notifications
You must be signed in to change notification settings - Fork 428
/
class-constant-types.php
111 lines (79 loc) · 1.87 KB
/
class-constant-types.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
namespace ClassConstantTypes;
use function PHPStan\Testing\assertType;
class Foo
{
const NO_TYPE = 1;
/** @var string */
const TYPE = 'foo';
/** @var string */
private const PRIVATE_TYPE = 'foo';
public function doFoo()
{
assertType('1', self::NO_TYPE);
assertType('mixed', static::NO_TYPE);
assertType('mixed', $this::NO_TYPE);
assertType('\'foo\'', self::TYPE);
assertType('string', static::TYPE);
assertType('string', $this::TYPE);
assertType('\'foo\'', self::PRIVATE_TYPE);
assertType('string', static::PRIVATE_TYPE);
assertType('string', $this::PRIVATE_TYPE);
}
}
class Bar extends Foo
{
const TYPE = 'bar';
private const PRIVATE_TYPE = 'bar';
public function doFoo()
{
assertType('\'bar\'', self::TYPE);
assertType('string', static::TYPE);
assertType('string', $this::TYPE);
assertType('\'bar\'', self::PRIVATE_TYPE);
assertType('mixed', static::PRIVATE_TYPE);
assertType('mixed', $this::PRIVATE_TYPE);
}
}
class Baz extends Foo
{
/** @var int */
const TYPE = 1;
public function doFoo()
{
assertType('1', self::TYPE);
assertType('int', static::TYPE);
assertType('int', $this::TYPE);
}
}
class Lorem extends Foo
{
/** description */
const TYPE = 1;
public function doFoo()
{
assertType('1', self::TYPE);
assertType('string', static::TYPE);
assertType('string', $this::TYPE);
}
}
final class FinalFoo
{
const NO_TYPE = 1;
/** @var string */
const TYPE = 'foo';
/** @var string */
private const PRIVATE_TYPE = 'foo';
public function doFoo()
{
assertType('1', self::NO_TYPE);
assertType('1', static::NO_TYPE);
assertType('1', $this::NO_TYPE);
assertType('\'foo\'', self::TYPE);
assertType('\'foo\'', static::TYPE);
assertType('\'foo\'', $this::TYPE);
assertType('\'foo\'', self::PRIVATE_TYPE);
assertType('\'foo\'', static::PRIVATE_TYPE);
assertType('\'foo\'', $this::PRIVATE_TYPE);
}
}