public function visitUnionType(UnionType $type)
 {
     $restricted = null;
     foreach ($type->getAlternates() as $alternate) {
         $restrictedAlternate = $alternate->visit($this);
         if (null !== $restrictedAlternate) {
             if (null === $restricted) {
                 $restricted = $restrictedAlternate;
             } else {
                 $restricted = $restrictedAlternate->getLeastSupertype($restricted);
             }
         }
     }
     return $restricted;
 }
 private function getByArrayRestrictedUnion(UnionType $type, $typeOfNonArrayTypes = null)
 {
     $types = array();
     $hasNoArray = false;
     foreach ($type->getAlternates() as $alt) {
         if (!$alt->isArrayType()) {
             $hasNoArray = true;
             continue;
         }
         $types[] = $alt;
     }
     if (null !== $typeOfNonArrayTypes && $hasNoArray) {
         $types[] = $typeOfNonArrayTypes;
     }
     return $this->registry->createUnionType($types);
 }
 public function visitUnionType(UnionType $type)
 {
     if (!$this->resultEqualsValue) {
         $types = array();
         foreach ($type->getAlternates() as $alt) {
             if ($this->getClassName($alt) === $this->value) {
                 continue;
             }
             $types[] = $alt;
         }
         return $this->registry->createUnionType($types);
     }
     foreach ($type->getAlternates() as $alt) {
         if ($alt->isNoObjectType()) {
             return $this->registry->getClassOrCreate($this->value);
         }
         $className = $this->getClassName($alt);
         if (null !== $className && $className === $this->value) {
             return $alt;
         }
     }
     return $this->registry->getNativeType('none');
 }