forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticTypeFactory.php
More file actions
90 lines (72 loc) · 1.91 KB
/
Copy pathStaticTypeFactory.php
File metadata and controls
90 lines (72 loc) · 1.91 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php declare(strict_types = 1);
namespace PHPStan\Type;
use ArrayAccess;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantFloatType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
final class StaticTypeFactory
{
public static function falsey(): Type
{
static $falsey;
if ($falsey === null) {
$falsey = TypeCombinator::union(
new NullType(),
new ConstantBooleanType(false),
new ConstantIntegerType(0),
new ConstantFloatType(0.0),
new ConstantStringType(''),
new ConstantStringType('0'),
new ConstantArrayType([], []),
);
}
return $falsey;
}
public static function truthy(): Type
{
static $truthy;
if ($truthy === null) {
$truthy = new MixedType(subtractedType: self::falsey());
}
return $truthy;
}
public static function argv(): Type
{
return new IntersectionType([
new ArrayType(IntegerRangeType::createAllGreaterThanOrEqualTo(0), new StringType()),
new NonEmptyArrayType(),
new AccessoryArrayListType(),
]);
}
public static function argc(): Type
{
return IntegerRangeType::fromInterval(1, null);
}
public static function generalOffsetAccessibleType(): Type
{
static $generalOffsetAccessible;
if ($generalOffsetAccessible === null) {
$generalOffsetAccessible = TypeCombinator::union(
new ArrayType(new MixedType(), new MixedType()),
new ObjectType(ArrayAccess::class),
new NullType(),
);
}
return $generalOffsetAccessible;
}
public static function intOffsetAccessibleType(): Type
{
static $intOffsetAccessible;
if ($intOffsetAccessible === null) {
$intOffsetAccessible = TypeCombinator::union(
self::generalOffsetAccessibleType(),
new StringType(),
);
}
return $intOffsetAccessible;
}
}