forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14464.php
More file actions
72 lines (64 loc) · 1.93 KB
/
bug-14464.php
File metadata and controls
72 lines (64 loc) · 1.93 KB
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
<?php declare(strict_types = 1);
namespace Bug14464;
use function PHPStan\Testing\assertType;
class HelloWorld
{
/** Variable count with == (loose comparison from the issue) */
protected function columnOrAlias(string $columnName): void
{
$colParts = preg_split('/\s+/', $columnName, -1, \PREG_SPLIT_NO_EMPTY);
if ($colParts === false) {
throw new \RuntimeException('preg error');
}
assertType('list<non-empty-string>', $colParts);
$numParts = count($colParts);
if ($numParts == 3) {
assertType('array{non-empty-string, non-empty-string, non-empty-string}', $colParts);
$this->columnName($colParts[0]);
$this->columnName($colParts[1]);
$this->columnName($colParts[2]);
} elseif ($numParts == 2) {
assertType('array{non-empty-string, non-empty-string}', $colParts);
$this->columnName($colParts[0]);
$this->columnName($colParts[1]);
} elseif ($numParts == 1) {
assertType('array{non-empty-string}', $colParts);
$this->columnName($colParts[0]);
} else {
throw new \LogicException('invalid');
}
}
/** Variable count with === (strict comparison) */
protected function strictComparison(string $input): void
{
$parts = preg_split('/,/', $input, -1, \PREG_SPLIT_NO_EMPTY);
if ($parts === false) {
throw new \RuntimeException('preg error');
}
$count = count($parts);
if ($count === 3) {
assertType('array{non-empty-string, non-empty-string, non-empty-string}', $parts);
} elseif ($count === 1) {
assertType('array{non-empty-string}', $parts);
}
}
/**
* Variable count on a PHPDoc list type
* @param list<int> $items
*/
protected function phpdocList(array $items): void
{
$count = count($items);
if ($count === 3) {
assertType('array{int, int, int}', $items);
} elseif ($count === 5) {
assertType('array{int, int, int, int, int}', $items);
} else {
assertType('list<int>', $items);
}
}
public function columnName(string $columnName): string
{
return 'abc';
}
}