Phan\Language\UnionType::addType PHP Метод

addType() публичный Метод

Add a type name to the list of types
public addType ( Type $type ) : void
$type Type
Результат void
    public function addType(Type $type)
    {
        $this->type_set->attach($type);
    }

Same methods

UnionType::addType ( Type $type ) : void

Usage Example

Пример #1
0
 /**
  * @param CodeBase
  * The code base to use in order to find super classes, etc.
  *
  * @param $recursion_depth
  * This thing has a tendency to run-away on me. This tracks
  * how bad I messed up by seeing how far the expanded types
  * go
  *
  * @return UnionType
  * Expands class types to all inherited classes returning
  * a superset of this type.
  */
 public function asExpandedTypes(CodeBase $code_base, int $recursion_depth = 0) : UnionType
 {
     return $this->memoize(__METHOD__, function () use($code_base, $recursion_depth) : UnionType {
         // We're going to assume that if the type hierarchy
         // is taller than some value we probably messed up
         // and should bail out.
         assert($recursion_depth < 20, "Recursion has gotten out of hand for type {$this}");
         if ($this->isNativeType()) {
             return $this->asUnionType();
         }
         $union_type = $this->asUnionType();
         $class_fqsen = $this->isGenericArray() ? $this->genericArrayElementType()->asFQSEN() : $this->asFQSEN();
         if (!$code_base->hasClassWithFQSEN($class_fqsen)) {
             return $union_type;
         }
         $clazz = $code_base->getClassByFQSEN($class_fqsen);
         $union_type->addUnionType($this->isGenericArray() ? $clazz->getUnionType()->asGenericArrayTypes() : $clazz->getUnionType());
         // Resurse up the tree to include all types
         $recursive_union_type = new UnionType();
         foreach ($union_type->getTypeSet() as $clazz_type) {
             if ((string) $clazz_type != (string) $this) {
                 $recursive_union_type->addUnionType($clazz_type->asExpandedTypes($code_base, $recursion_depth + 1));
             } else {
                 $recursive_union_type->addType($clazz_type);
             }
         }
         return $recursive_union_type;
     });
 }
All Usage Examples Of Phan\Language\UnionType::addType