-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce oversized-array type to enfore max number of HasOffsetValue…
…Type accessory types
- Loading branch information
1 parent
ec28678
commit 81de3eb
Showing
30 changed files
with
385 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Type\Accessory; | ||
|
||
use PHPStan\TrinaryLogic; | ||
use PHPStan\Type\CompoundType; | ||
use PHPStan\Type\Constant\ConstantFloatType; | ||
use PHPStan\Type\Constant\ConstantIntegerType; | ||
use PHPStan\Type\ErrorType; | ||
use PHPStan\Type\IntersectionType; | ||
use PHPStan\Type\MixedType; | ||
use PHPStan\Type\Traits\MaybeCallableTypeTrait; | ||
use PHPStan\Type\Traits\NonGeneralizableTypeTrait; | ||
use PHPStan\Type\Traits\NonGenericTypeTrait; | ||
use PHPStan\Type\Traits\NonObjectTypeTrait; | ||
use PHPStan\Type\Traits\NonRemoveableTypeTrait; | ||
use PHPStan\Type\Traits\TruthyBooleanTypeTrait; | ||
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait; | ||
use PHPStan\Type\Type; | ||
use PHPStan\Type\UnionType; | ||
use PHPStan\Type\VerbosityLevel; | ||
|
||
class OversizedArrayType implements CompoundType, AccessoryType | ||
{ | ||
|
||
use MaybeCallableTypeTrait; | ||
use NonObjectTypeTrait; | ||
use TruthyBooleanTypeTrait; | ||
use NonGenericTypeTrait; | ||
use UndecidedComparisonCompoundTypeTrait; | ||
use NonRemoveableTypeTrait; | ||
use NonGeneralizableTypeTrait; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public function getReferencedClasses(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function accepts(Type $type, bool $strictTypes): TrinaryLogic | ||
{ | ||
if ($type instanceof CompoundType) { | ||
return $type->isAcceptedBy($this, $strictTypes); | ||
} | ||
|
||
return $type->isArray() | ||
->and($type->isIterableAtLeastOnce()); | ||
} | ||
|
||
public function isSuperTypeOf(Type $type): TrinaryLogic | ||
{ | ||
if ($this->equals($type)) { | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
if ($type instanceof CompoundType) { | ||
return $type->isSubTypeOf($this); | ||
} | ||
|
||
return $type->isArray() | ||
->and($type->isOversizedArray()); | ||
} | ||
|
||
public function isSubTypeOf(Type $otherType): TrinaryLogic | ||
{ | ||
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) { | ||
return $otherType->isSuperTypeOf($this); | ||
} | ||
|
||
return $otherType->isArray() | ||
->and($otherType->isOversizedArray()) | ||
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()); | ||
} | ||
|
||
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic | ||
{ | ||
return $this->isSubTypeOf($acceptingType); | ||
} | ||
|
||
public function equals(Type $type): bool | ||
{ | ||
return $type instanceof self; | ||
} | ||
|
||
public function describe(VerbosityLevel $level): string | ||
{ | ||
return 'oversized-array'; | ||
} | ||
|
||
public function isOffsetAccessible(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
public function hasOffsetValueType(Type $offsetType): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createMaybe(); | ||
} | ||
|
||
public function getOffsetValueType(Type $offsetType): Type | ||
{ | ||
return new MixedType(); | ||
} | ||
|
||
public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $unionValues = true): Type | ||
{ | ||
return $this; | ||
} | ||
|
||
public function unsetOffset(Type $offsetType): Type | ||
{ | ||
return new ErrorType(); | ||
} | ||
|
||
public function isIterable(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
public function isIterableAtLeastOnce(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
public function getIterableKeyType(): Type | ||
{ | ||
return new MixedType(); | ||
} | ||
|
||
public function getIterableValueType(): Type | ||
{ | ||
return new MixedType(); | ||
} | ||
|
||
public function isArray(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
public function isOversizedArray(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createYes(); | ||
} | ||
|
||
public function isString(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function isNumericString(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function isNonEmptyString(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function isNonFalsyString(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function isLiteralString(): TrinaryLogic | ||
{ | ||
return TrinaryLogic::createNo(); | ||
} | ||
|
||
public function toNumber(): Type | ||
{ | ||
return new ErrorType(); | ||
} | ||
|
||
public function toInteger(): Type | ||
{ | ||
return new ConstantIntegerType(1); | ||
} | ||
|
||
public function toFloat(): Type | ||
{ | ||
return new ConstantFloatType(1.0); | ||
} | ||
|
||
public function toString(): Type | ||
{ | ||
return new ErrorType(); | ||
} | ||
|
||
public function toArray(): Type | ||
{ | ||
return new MixedType(); | ||
} | ||
|
||
public function traverse(callable $cb): Type | ||
{ | ||
return $this; | ||
} | ||
|
||
public static function __set_state(array $properties): Type | ||
{ | ||
return new self(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.