public function combineWith(Type $otherType) : Type { if ($otherType instanceof self && $this->getClass() == $otherType->getClass()) { return new self($this->getClass(), $this->isNullable() || $otherType->isNullable()); } if ($otherType instanceof NullType) { return $this->makeNullable(); } return new MixedType($this->isNullable() || $otherType->isNullable()); }
public function combineWith(Type $otherType) : Type { if ($otherType instanceof ArrayType) { return new self($this->getItemType()->combineWith($otherType->getItemType()), $this->isNullable() || $otherType->isNullable(), $this->isItemTypeInferredFromLiteralArray() || $otherType->isItemTypeInferredFromLiteralArray(), $this->isPossiblyCallable() || $otherType->isPossiblyCallable()); } if ($otherType instanceof NullType) { return $this->makeNullable(); } return new MixedType($this->isNullable() || $otherType->isNullable()); }
public function combineWith(Type $otherType) : Type { if ($otherType instanceof IterableType) { return new self($this->getItemType()->combineWith($otherType->getItemType()), $this->isNullable() || $otherType->isNullable()); } if ($otherType instanceof NullType) { return $this->makeNullable(); } return new MixedType($this->isNullable() || $otherType->isNullable()); }
public function combineWith(Type $otherType) : Type { if ($otherType instanceof $this) { $thisClass = get_class($this); return new $thisClass($this->isNullable() || $otherType->isNullable()); } if ($otherType instanceof NullType) { return $this->makeNullable(); } return new MixedType($this->isNullable() || $otherType->isNullable()); }
public function combineWith(Type $otherType) : Type { if ($otherType instanceof self) { return new self($this->isNullable() || $otherType->isNullable()); } if ($otherType instanceof ArrayType && $otherType->isPossiblyCallable()) { return $this; } if ($otherType instanceof NullType) { return $this->makeNullable(); } return new MixedType($this->isNullable() || $otherType->isNullable()); }
public static function decideType(Type $type, Type $phpDocType = null) : Type { if ($phpDocType !== null) { if ($type instanceof IterableType && $phpDocType instanceof ArrayType) { if ($type instanceof IterableIterableType) { $phpDocType = new IterableIterableType($phpDocType->getItemType(), $type->isNullable() || $phpDocType->isNullable()); } elseif ($type instanceof ArrayType) { $type = new ArrayType($phpDocType->getItemType(), $type->isNullable() || $phpDocType->isNullable()); } } if ($type->accepts($phpDocType)) { return $phpDocType; } } return $type; }
public static function decideType(\ReflectionType $reflectionType = null, Type $phpDocType = null, string $selfClass = null, bool $isVariadic = false) : Type { if ($reflectionType === null) { return $phpDocType !== null ? $phpDocType : new MixedType(true); } $reflectionTypeString = (string) $reflectionType; if ($isVariadic) { $reflectionTypeString .= '[]'; } $type = self::getTypeObjectFromTypehint($reflectionTypeString, $reflectionType->allowsNull(), $selfClass); if ($phpDocType !== null) { if ($type instanceof ArrayType && $phpDocType instanceof ArrayType) { $type = new ArrayType($phpDocType->getItemType(), $type->isNullable() || $phpDocType->isNullable()); } if ($type->accepts($phpDocType)) { return $phpDocType; } } return $type; }
public function combineWith(Type $otherType) : Type { return new self($this->baseClass, $this->isNullable() || $otherType->isNullable()); }