-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathInlineControlStructureUnitTest.1.inc
299 lines (226 loc) · 4.71 KB
/
InlineControlStructureUnitTest.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?php
if ($something) echo 'hello';
if ($something) {
echo 'hello';
} else echo 'hi';
if ($something) {
echo 'hello';
} else if ($else) echo 'hi';
foreach ($something as $thing) echo 'hello';
for ($i; $i > 0; $i--) echo 'hello';
while ($something) echo 'hello';
do {
$i--;
} while ($something);
if(true)
$someObject->{$name};
if (true) :
$foo = true;
endif;
while (true) :
$foo = true;
endwhile;
for ($i; $i > 0; $i--) :
echo 'hello';
endfor;
foreach ($array as $element) :
echo 'hello';
endforeach;
while (!$this->readLine($tokens, $tag));
while (!$this->readLine($tokens, $tag)); //skip to end of file
foreach ($cookies as $cookie)
if ($cookie->match($uri, $matchSessionCookies, $now))
$ret[] = $cookie;
foreach ($stringParade as $hit)
$hitParade[] = $hit + 0; //cast to integer
if ($foo) :
echo 'true';
elseif ($something) :
echo 'foo';
else:
echo 'false';
endif;
function test()
{
if ($a)
$a.=' '.($b ? 'b' : ($c ? ($d ? 'd' : 'c') : ''));
}
if ($a)
foreach ($b as $c) {
if ($d) {
$e=$f;
$g=$h;
} elseif ($i==0) {
$j=$k;
}
}
?>
<div style="text-align: right;">
<?php if ($model->scenario == 'simple') $widget->renderPager() ?>
</div>
<?php
if ($error === ERROR_ONE): ?>
Error one!
<?php elseif ($error === ERROR_TWO): ?>
Error two!
<?php endif;
if ($value):
if ($anotherValue):
foreach ($array as $element):
echo (function($element): string { return $element; } )($element);
endforeach;
endif;
else:
echo 'foo';
endif;
// ELSE IF split over multiple lines (not inline)
if ($test) {
} else
if ($test) {
} else {
}
if ((function () {
return 'bar';
})())
echo 'one';
$stuff = [1,2,3];
foreach($stuff as $num)
if ($num %2 ) {
echo "even";
} else {
echo "odd";
}
$i = 0;
foreach($stuff as $num)
do {
echo $i;
$i++;
} while ($i < 5);
foreach($stuff as $num)
if (true) {
echo "true1\n";
}
if (true) {
echo "true2\n";
}
if ($foo) echo 'foo';
elseif ($bar) echo 'bar';
else echo 'baz';
switch ($type) {
case 1:
if ($foo) {
return true;
} elseif ($baz)
return true;
else {
echo 'else';
}
break;
}
foreach ($sql as $s)
if (!$this->execute) echo "<pre>",$s.";\n</pre>";
else {
$ok = $this->connDest->Execute($s);
if (!$ok)
if ($this->neverAbort) $ret = false;
else return false;
}
if ($bar)
if ($foo) echo 'hi'; // lol
if ($level == 'district')
\DB::update(<<<EOD
some
text
here
EOD
);
if ($level == 'district')
$var = <<<EOD
some
text
here
EOD;
if ($a && $a === Foo::VARIABLE && ($a === Foo::METHOD || $a === Foo::FUNCTION))
echo 'hi';
$out = array_map(function ($test) { if ($test) return 1; else return 2; }, $input); // comment
for ($x=0;$x<5;$x++):
if ($x) continue;
endfor;
for ($x=0;$x<5;$x++):
if ($x) continue ?> <?php
endfor;
if (true)
try {
}
catch(Exception $e) {
}
for ($i = 0; $i <= 4; $i++)
if ($i % 2)
return bar(
baz(
"foobarbaz"
)
);
do {
$i++;
}
// Comment
while ($i < 10);
if ($this) {
if ($that)
foo(${$a[$b]});
}
while (!$this->readLine($tokens, $tag)); //phpcs:ignore Standard.Category.Sniff
while (!$this->readLine($tokens, $tag)); // comment
while (!$this->readLine($tokens, $tag)); /* comment */
foreach ($stringParade as $hit)
$hitParade[] = $hit + 0; // phpcs:ignore Standard.Category.Sniff
if ($bar)
if ($foo) echo 'hi'; /* @phpcs:ignore Standard.Category.Sniff */
if (true) $callable = function () {
return true;
};
foreach ([] as $a)
echo 'bar';
{
echo 'baz';
}
// Issue 2822.
$i = 10;
while ($i > 0 && --$i);
for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
if ($this->valid(fn(): bool => 2 > 1)) {
}
// Issue 3345.
function testMultiCatch()
{
if (true)
try {
} catch (\LogicException $e) {
} catch (\Exception $e) {
}
}
function testFinally()
{
if (true)
try {
} catch (\LogicException $e) {
} finally {
}
}
if ($something) {
echo 'hello';
} else /* comment */ if ($somethingElse) echo 'hi';
if ($sniffShouldBailEarly);
if (false) {
} elseif ($sniffShouldBailEarly);
if (false) {
} else if ($sniffShouldBailEarly);
if (false) {
} else ($sniffShouldGenerateError);
if (false) {
} else; // Sniff should bail early.
foreach ($array as $sniffShouldBailEarly);
foreach ($array as $sniffShouldBailEarly)
/* some comment */;
do ; while ($sniffShouldBailEarly > 5);