| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type; |
| 4: | |
| 5: | use PHPStan\Php\PhpVersion; |
| 6: | use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; |
| 7: | use PHPStan\PhpDocParser\Ast\Type\TypeNode; |
| 8: | use PHPStan\TrinaryLogic; |
| 9: | use PHPStan\Type\Accessory\AccessoryNumericStringType; |
| 10: | use PHPStan\Type\Accessory\AccessoryUppercaseStringType; |
| 11: | use PHPStan\Type\Constant\ConstantArrayType; |
| 12: | use PHPStan\Type\Constant\ConstantIntegerType; |
| 13: | use PHPStan\Type\Traits\NonArrayTypeTrait; |
| 14: | use PHPStan\Type\Traits\NonCallableTypeTrait; |
| 15: | use PHPStan\Type\Traits\NonGeneralizableTypeTrait; |
| 16: | use PHPStan\Type\Traits\NonGenericTypeTrait; |
| 17: | use PHPStan\Type\Traits\NonIterableTypeTrait; |
| 18: | use PHPStan\Type\Traits\NonObjectTypeTrait; |
| 19: | use PHPStan\Type\Traits\NonOffsetAccessibleTypeTrait; |
| 20: | use PHPStan\Type\Traits\NonRemoveableTypeTrait; |
| 21: | use PHPStan\Type\Traits\UndecidedBooleanTypeTrait; |
| 22: | use PHPStan\Type\Traits\UndecidedComparisonTypeTrait; |
| 23: | use function get_class; |
| 24: | |
| 25: | |
| 26: | class FloatType implements Type |
| 27: | { |
| 28: | |
| 29: | use NonArrayTypeTrait; |
| 30: | use NonCallableTypeTrait; |
| 31: | use NonIterableTypeTrait; |
| 32: | use NonObjectTypeTrait; |
| 33: | use UndecidedBooleanTypeTrait; |
| 34: | use UndecidedComparisonTypeTrait; |
| 35: | use NonGenericTypeTrait; |
| 36: | use NonOffsetAccessibleTypeTrait; |
| 37: | use NonRemoveableTypeTrait; |
| 38: | use NonGeneralizableTypeTrait; |
| 39: | |
| 40: | |
| 41: | public function __construct() |
| 42: | { |
| 43: | } |
| 44: | |
| 45: | public function getReferencedClasses(): array |
| 46: | { |
| 47: | return []; |
| 48: | } |
| 49: | |
| 50: | public function getObjectClassNames(): array |
| 51: | { |
| 52: | return []; |
| 53: | } |
| 54: | |
| 55: | public function getObjectClassReflections(): array |
| 56: | { |
| 57: | return []; |
| 58: | } |
| 59: | |
| 60: | public function getConstantStrings(): array |
| 61: | { |
| 62: | return []; |
| 63: | } |
| 64: | |
| 65: | public function accepts(Type $type, bool $strictTypes): AcceptsResult |
| 66: | { |
| 67: | if ($type instanceof self || $type->isInteger()->yes()) { |
| 68: | return AcceptsResult::createYes(); |
| 69: | } |
| 70: | |
| 71: | if ($type instanceof CompoundType) { |
| 72: | return $type->isAcceptedBy($this, $strictTypes); |
| 73: | } |
| 74: | |
| 75: | return AcceptsResult::createNo(); |
| 76: | } |
| 77: | |
| 78: | public function isSuperTypeOf(Type $type): IsSuperTypeOfResult |
| 79: | { |
| 80: | if ($type instanceof self) { |
| 81: | return IsSuperTypeOfResult::createYes(); |
| 82: | } |
| 83: | |
| 84: | if ($type instanceof CompoundType) { |
| 85: | return $type->isSubTypeOf($this); |
| 86: | } |
| 87: | |
| 88: | return IsSuperTypeOfResult::createNo(); |
| 89: | } |
| 90: | |
| 91: | public function equals(Type $type): bool |
| 92: | { |
| 93: | return get_class($type) === static::class; |
| 94: | } |
| 95: | |
| 96: | public function describe(VerbosityLevel $level): string |
| 97: | { |
| 98: | return 'float'; |
| 99: | } |
| 100: | |
| 101: | public function toNumber(): Type |
| 102: | { |
| 103: | return $this; |
| 104: | } |
| 105: | |
| 106: | public function toAbsoluteNumber(): Type |
| 107: | { |
| 108: | return $this; |
| 109: | } |
| 110: | |
| 111: | public function toFloat(): Type |
| 112: | { |
| 113: | return $this; |
| 114: | } |
| 115: | |
| 116: | public function toInteger(): Type |
| 117: | { |
| 118: | return new IntegerType(); |
| 119: | } |
| 120: | |
| 121: | public function toString(): Type |
| 122: | { |
| 123: | return new IntersectionType([ |
| 124: | new StringType(), |
| 125: | new AccessoryUppercaseStringType(), |
| 126: | new AccessoryNumericStringType(), |
| 127: | ]); |
| 128: | } |
| 129: | |
| 130: | public function toArray(): Type |
| 131: | { |
| 132: | return new ConstantArrayType( |
| 133: | [new ConstantIntegerType(0)], |
| 134: | [$this], |
| 135: | [1], |
| 136: | [], |
| 137: | TrinaryLogic::createYes(), |
| 138: | ); |
| 139: | } |
| 140: | |
| 141: | public function toArrayKey(): Type |
| 142: | { |
| 143: | return new IntegerType(); |
| 144: | } |
| 145: | |
| 146: | public function isOffsetAccessLegal(): TrinaryLogic |
| 147: | { |
| 148: | return TrinaryLogic::createYes(); |
| 149: | } |
| 150: | |
| 151: | public function isNull(): TrinaryLogic |
| 152: | { |
| 153: | return TrinaryLogic::createNo(); |
| 154: | } |
| 155: | |
| 156: | public function isConstantValue(): TrinaryLogic |
| 157: | { |
| 158: | return TrinaryLogic::createNo(); |
| 159: | } |
| 160: | |
| 161: | public function isConstantScalarValue(): TrinaryLogic |
| 162: | { |
| 163: | return TrinaryLogic::createNo(); |
| 164: | } |
| 165: | |
| 166: | public function getConstantScalarTypes(): array |
| 167: | { |
| 168: | return []; |
| 169: | } |
| 170: | |
| 171: | public function getConstantScalarValues(): array |
| 172: | { |
| 173: | return []; |
| 174: | } |
| 175: | |
| 176: | public function isTrue(): TrinaryLogic |
| 177: | { |
| 178: | return TrinaryLogic::createNo(); |
| 179: | } |
| 180: | |
| 181: | public function isFalse(): TrinaryLogic |
| 182: | { |
| 183: | return TrinaryLogic::createNo(); |
| 184: | } |
| 185: | |
| 186: | public function isBoolean(): TrinaryLogic |
| 187: | { |
| 188: | return TrinaryLogic::createNo(); |
| 189: | } |
| 190: | |
| 191: | public function isFloat(): TrinaryLogic |
| 192: | { |
| 193: | return TrinaryLogic::createYes(); |
| 194: | } |
| 195: | |
| 196: | public function isInteger(): TrinaryLogic |
| 197: | { |
| 198: | return TrinaryLogic::createNo(); |
| 199: | } |
| 200: | |
| 201: | public function isString(): TrinaryLogic |
| 202: | { |
| 203: | return TrinaryLogic::createNo(); |
| 204: | } |
| 205: | |
| 206: | public function isNumericString(): TrinaryLogic |
| 207: | { |
| 208: | return TrinaryLogic::createNo(); |
| 209: | } |
| 210: | |
| 211: | public function isNonEmptyString(): TrinaryLogic |
| 212: | { |
| 213: | return TrinaryLogic::createNo(); |
| 214: | } |
| 215: | |
| 216: | public function isNonFalsyString(): TrinaryLogic |
| 217: | { |
| 218: | return TrinaryLogic::createNo(); |
| 219: | } |
| 220: | |
| 221: | public function isLiteralString(): TrinaryLogic |
| 222: | { |
| 223: | return TrinaryLogic::createNo(); |
| 224: | } |
| 225: | |
| 226: | public function isLowercaseString(): TrinaryLogic |
| 227: | { |
| 228: | return TrinaryLogic::createNo(); |
| 229: | } |
| 230: | |
| 231: | public function isClassString(): TrinaryLogic |
| 232: | { |
| 233: | return TrinaryLogic::createNo(); |
| 234: | } |
| 235: | |
| 236: | public function isUppercaseString(): TrinaryLogic |
| 237: | { |
| 238: | return TrinaryLogic::createNo(); |
| 239: | } |
| 240: | |
| 241: | public function getClassStringObjectType(): Type |
| 242: | { |
| 243: | return new ErrorType(); |
| 244: | } |
| 245: | |
| 246: | public function getObjectTypeOrClassStringObjectType(): Type |
| 247: | { |
| 248: | return new ErrorType(); |
| 249: | } |
| 250: | |
| 251: | public function isVoid(): TrinaryLogic |
| 252: | { |
| 253: | return TrinaryLogic::createNo(); |
| 254: | } |
| 255: | |
| 256: | public function isScalar(): TrinaryLogic |
| 257: | { |
| 258: | return TrinaryLogic::createYes(); |
| 259: | } |
| 260: | |
| 261: | public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType |
| 262: | { |
| 263: | return new BooleanType(); |
| 264: | } |
| 265: | |
| 266: | public function traverse(callable $cb): Type |
| 267: | { |
| 268: | return $this; |
| 269: | } |
| 270: | |
| 271: | public function traverseSimultaneously(Type $right, callable $cb): Type |
| 272: | { |
| 273: | return $this; |
| 274: | } |
| 275: | |
| 276: | public function exponentiate(Type $exponent): Type |
| 277: | { |
| 278: | return ExponentiateHelper::exponentiate($this, $exponent); |
| 279: | } |
| 280: | |
| 281: | public function toPhpDocNode(): TypeNode |
| 282: | { |
| 283: | return new IdentifierTypeNode('float'); |
| 284: | } |
| 285: | |
| 286: | public function getFiniteTypes(): array |
| 287: | { |
| 288: | return []; |
| 289: | } |
| 290: | |
| 291: | } |
| 292: | |