/** * Override the default getter to fill in a future * union type if available. */ public function getUnionType() : UnionType { if (null !== ($union_type = $this->getFutureUnionType())) { $this->getUnionType()->addUnionType($union_type); } return parent::getUnionType(); }
public function getUnionType() : UnionType { if (!empty($this->future_union_type)) { // null out the future_union_type before // we compute it to avoid unbounded // recursion $future_union_type = $this->future_union_type; $this->future_union_type = null; // Set a default value for my type in case // there's some unbounded recursion $this->setUnionType(new UnionType([IntType::instance(), FloatType::instance(), StringType::instance(), BoolType::instance()])); $this->setUnionType($future_union_type->get()); } return parent::getUnionType(); }
/** * @param Context $context * * @return UnionType * The type of this method in its given context. */ public function getUnionType() : UnionType { $union_type = parent::getUnionType(); // If the type is 'static', add this context's class // to the return type if ($union_type->hasStaticType()) { $union_type = clone $union_type; $union_type->addType($this->getFQSEN()->getFullyQualifiedClassName()->asType()); } // If the type is a generic array of 'static', add // a generic array of this context's class to the return type if ($union_type->genericArrayElementTypes()->hasStaticType()) { $union_type = clone $union_type; $union_type->addType($this->getFQSEN()->getFullyQualifiedClassName()->asType()->asGenericArrayType()); } return $union_type; }