-
Notifications
You must be signed in to change notification settings - Fork 426
/
modulo-operator.php
76 lines (58 loc) · 1.68 KB
/
modulo-operator.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
<?php
namespace ModuloOperator;
use function PHPStan\Testing\assertType;
class Foo
{
/**
* @param positive-int $p
* @param int<5, 10> $range
* @param int<0, max> $zeroOrMore
* @param 1|2|3 $intConst
* @param int<min, 3>|int<4, max> $unionRange
* @param int<min, 3>|7 $hybridUnionRange
*/
function doBar(int $i, int $j, $p, $range, $zeroOrMore, $intConst, $unionRange, $hybridUnionRange, $mixed)
{
assertType('int<-1, 1>', $i % 2);
assertType('int<0, 1>', $p % 2);
assertType('int<-2, 2>', $i % 3);
assertType('int<0, 2>', $p % 3);
assertType('0|1|2', $intConst % 3);
assertType('int<-2, 2>', $i % $intConst);
assertType('int<0, 2>', $p % $intConst);
assertType('int<0, 2>', $range % 3);
assertType('int<-9, 9>', $i % $range);
assertType('int<0, 9>', $p % $range);
assertType('int', $i % $unionRange);
assertType('int<0, max>', $p % $unionRange);
assertType('int<-6, 6>', $i % $hybridUnionRange);
assertType('int<0, 6>', $p % $hybridUnionRange);
assertType('int<0, max>', $zeroOrMore % $mixed);
if ($i === 0) {
return;
}
assertType('int', $j % $i);
}
function moduleOne(int $i, float $f) {
assertType('0', true % '1');
assertType('0', false % '1');
assertType('0', null % '1');
assertType('0', -1 % '1');
assertType('0', 0 % '1');
assertType('0', 1 % '1');
assertType('0', '1' % '1');
assertType('0', 1.24 % '1');
assertType('0', $i % 1.0);
assertType('0', $f % 1.0);
assertType('0', $i % '1.0');
assertType('0', $f % '1.0');
assertType('0', $i % '1');
assertType('0', $f % '1');
assertType('0', $i % true);
assertType('0', $f % true);
$i %= '1';
$f %= '1';
assertType('0', $i);
assertType('0', $f);
}
}