-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathLowerCaseConstantUnitTest.1.inc
174 lines (136 loc) · 3.64 KB
/
LowerCaseConstantUnitTest.1.inc
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
// True
function myFunction($arg1, $arg2=true)
{
}
function myFunction($arg1, $arg2=TRUE)
{
}
function myFunction($arg1, $arg2=True)
{
}
if ($variable === true) { }
if ($variable === TRUE) { }
if ($variable === True) { }
// False
function myFunction($arg1, $arg2=false)
{
}
function myFunction($arg1, $arg2=FALSE)
{
}
function myFunction($arg1, $arg2=False)
{
}
if ($variable === false) { }
if ($variable === FALSE) { }
if ($variable === False) { }
// Null
function myFunction($arg1, $arg2=null)
{
}
function myFunction($arg1, $arg2=NULL)
{
}
function myFunction($arg1, $arg2=Null)
{
}
if ($variable === null) { }
if ($variable === NULL) { }
if ($variable === Null) { }
$x = new stdClass();
$x->NULL = 7;
use Zend\Log\Writer\NULL as NullWriter;
new \Zend\Log\Writer\NULL();
namespace False;
class True extends Null implements False {}
use True\Something;
use Something\True;
class MyClass
{
public function myFunction()
{
$var = array('foo' => new True());
}
}
$x = $f?FALSE:true;
$x = $f? FALSE:true;
class MyClass
{
// Spice things up a little.
const TRUE = false;
}
var_dump(MyClass::TRUE);
function tRUE() {}
$input->getFilterChain()->attachByName('Null', ['type' => Null::TYPE_STRING]);
// Issue #3332 - ignore type declarations, but not default values.
class TypedThings {
const MYCONST = FALSE;
public int|FALSE $int = FALSE;
public Type|NULL $int = new MyObj(NULL);
private function typed(int|FALSE $param = NULL, Type|NULL $obj = new MyObj(FALSE)) : string|FALSE|NULL
{
if (TRUE === FALSE) {
return NULL;
}
}
}
$cl = function (int|FALSE $param = NULL, Type|NULL $obj = new MyObj(FALSE)) : string|FALSE|NULL {};
// Adding some extra tests to safeguard that function declarations which don't create scope are handled correctly.
interface InterfaceMethodsWithReturnTypeNoScopeOpener {
private function typed($param = TRUE) : string|FALSE|NULL;
}
abstract class ClassMethodsWithReturnTypeNoScopeOpener {
abstract public function typed($param = FALSE) : TRUE;
}
// Additional tests to safeguard improved property type skip logic.
readonly class Properties {
use SomeTrait {
sayHello as private myPrivateHello;
}
public Type|FALSE|NULL $propertyA = array(
'itemA' => TRUE,
'itemB' => FALSE,
'itemC' => NULL,
), $propertyB = FALSE;
protected \FullyQualified&Partially\Qualified&namespace\Relative $propertyC;
var ?TRUE $propertyD;
static array|callable|FALSE|self|parent $propertyE = TRUE;
private
// phpcs:ignore Stnd.Cat.Sniff -- for reasons.
TRUE /*comment*/
$propertyF = TRUE;
public function __construct(
public FALSE|NULL $promotedPropA,
readonly callable|TRUE $promotedPropB,
) {
static $var;
echo static::class;
static::foo();
$var = $var instanceof static;
$obj = new static();
}
public static function foo(): static|self|FALSE {
$callable = static function() {};
}
}
// PHP 8.3 introduces typed constants.
class TypedConstants {
const MyClass|NULL|TRUE|FALSE MYCONST = FALSE;
}
// Global constants can not be typed.
const MYCONST = TRUE;
class SkipOverPHP82DNFTypes {
protected (\FullyQualified&Partially\Qualified)|TRUE $propertyC;
}
class SkipOverPHP84FinalProperties {
final MyType|FALSE $propA;
private static final NULL|MyClass $propB;
}
// PHP 8.4 asymmetric visibility
class WithAsym {
private(set) NULL|TRUE $asym1 = TRUE;
public private(set) ?bool $asym2 = FALSE;
protected(set) FALSE|string|null $asym3 = NULL;
public protected(set) Type|NULL|bool $asym4 = TRUE;
}