1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Type;
4:
5: use PHPStan\TrinaryLogic;
6: use PHPStan\Type\Accessory\AccessoryNumericStringType;
7: use PHPStan\Type\Constant\ConstantArrayType;
8: use PHPStan\Type\Constant\ConstantIntegerType;
9: use PHPStan\Type\Traits\NonCallableTypeTrait;
10: use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
11: use PHPStan\Type\Traits\NonGenericTypeTrait;
12: use PHPStan\Type\Traits\NonIterableTypeTrait;
13: use PHPStan\Type\Traits\NonObjectTypeTrait;
14: use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait;
15: use PHPStan\Type\Traits\NonRemoveableTypeTrait;
16: use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
17: use PHPStan\Type\Traits\UndecidedComparisonTypeTrait;
18: use function get_class;
19:
20: /** @api */
21: class FloatType implements Type
22: {
23:
24: use NonCallableTypeTrait;
25: use NonIterableTypeTrait;
26: use NonObjectTypeTrait;
27: use UndecidedBooleanTypeTrait;
28: use UndecidedComparisonTypeTrait;
29: use NonGenericTypeTrait;
30: use NonOffsetAccessibleTypeTrait;
31: use NonRemoveableTypeTrait;
32: use NonGeneralizableTypeTrait;
33:
34: /** @api */
35: public function __construct()
36: {
37: }
38:
39: /**
40: * @return string[]
41: */
42: public function getReferencedClasses(): array
43: {
44: return [];
45: }
46:
47: public function accepts(Type $type, bool $strictTypes): TrinaryLogic
48: {
49: if ($type instanceof self || $type instanceof IntegerType) {
50: return TrinaryLogic::createYes();
51: }
52:
53: if ($type instanceof CompoundType) {
54: return $type->isAcceptedBy($this, $strictTypes);
55: }
56:
57: return TrinaryLogic::createNo();
58: }
59:
60: public function isSuperTypeOf(Type $type): TrinaryLogic
61: {
62: if ($type instanceof self) {
63: return TrinaryLogic::createYes();
64: }
65:
66: if ($type instanceof CompoundType) {
67: return $type->isSubTypeOf($this);
68: }
69:
70: return TrinaryLogic::createNo();
71: }
72:
73: public function equals(Type $type): bool
74: {
75: return get_class($type) === static::class;
76: }
77:
78: public function describe(VerbosityLevel $level): string
79: {
80: return 'float';
81: }
82:
83: public function toNumber(): Type
84: {
85: return $this;
86: }
87:
88: public function toFloat(): Type
89: {
90: return $this;
91: }
92:
93: public function toInteger(): Type
94: {
95: return new IntegerType();
96: }
97:
98: public function toString(): Type
99: {
100: return new IntersectionType([
101: new StringType(),
102: new AccessoryNumericStringType(),
103: ]);
104: }
105:
106: public function toArray(): Type
107: {
108: return new ConstantArrayType(
109: [new ConstantIntegerType(0)],
110: [$this],
111: [1],
112: );
113: }
114:
115: public function isArray(): TrinaryLogic
116: {
117: return TrinaryLogic::createNo();
118: }
119:
120: public function isOversizedArray(): TrinaryLogic
121: {
122: return TrinaryLogic::createNo();
123: }
124:
125: public function isString(): TrinaryLogic
126: {
127: return TrinaryLogic::createNo();
128: }
129:
130: public function isNumericString(): TrinaryLogic
131: {
132: return TrinaryLogic::createNo();
133: }
134:
135: public function isNonEmptyString(): TrinaryLogic
136: {
137: return TrinaryLogic::createNo();
138: }
139:
140: public function isNonFalsyString(): TrinaryLogic
141: {
142: return TrinaryLogic::createNo();
143: }
144:
145: public function isLiteralString(): TrinaryLogic
146: {
147: return TrinaryLogic::createNo();
148: }
149:
150: public function traverse(callable $cb): Type
151: {
152: return $this;
153: }
154:
155: /**
156: * @param mixed[] $properties
157: */
158: public static function __set_state(array $properties): Type
159: {
160: return new self();
161: }
162:
163: }
164: