Phan\Language\UnionType::asExpandedTypes PHP Method

asExpandedTypes() public method

public asExpandedTypes ( CodeBase $code_base, integer $recursion_depth ) : UnionType
$code_base Phan\CodeBase
$recursion_depth integer 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 all class types to all inherited classes returning a superset of this type.
    public function asExpandedTypes(CodeBase $code_base, int $recursion_depth = 0) : UnionType
    {
        assert($recursion_depth < 10, "Recursion has gotten out of hand");
        $union_type = new UnionType();
        foreach ($this->type_set as $type) {
            $union_type->addUnionType($type->asExpandedTypes($code_base, $recursion_depth + 1));
        }
        return $union_type;
    }

Usage Example

Example #1
0
 /**
  * @param UnionType $target
  * The type we'd like to see if this type can cast
  * to
  *
  * @param CodeBase $code_base
  * The code base used to expand types
  *
  * @return bool
  * Test to see if this type can be cast to the
  * given type after expanding both union types
  * to include all ancestor types
  */
 public function canCastToExpandedUnionType(UnionType $target, CodeBase $code_base) : bool
 {
     $this_expanded = $this->asExpandedTypes($code_base);
     $target_expanded = $target->asExpandedTypes($code_base);
     return $this_expanded->canCastToUnionType($target_expanded);
 }