Skip to content

Commit

Permalink
Intersection types
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Oct 3, 2021
1 parent f1976de commit 356777b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 108 deletions.
200 changes: 94 additions & 106 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/Reflection/ReflectionIntersectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Roave\BetterReflection\Reflection;

use PhpParser\Node\IntersectionType;

use function array_map;
use function implode;

class ReflectionIntersectionType extends ReflectionType
{
/** @var list<ReflectionNamedType> */
private array $types;

public function __construct(IntersectionType $type, bool $allowsNull)
{
parent::__construct($allowsNull);
$this->types = array_filter(
array_map(static fn ($type): ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType => ReflectionType::createFromTypeAndReflector($type), $type->types),
static fn (ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType $type): bool => $type instanceof ReflectionNamedType,
);
}

/**
* @return list<ReflectionNamedType>
*/
public function getTypes(): array
{
return $this->types;
}

public function __toString(): string
{
return implode('&', array_map(static fn (ReflectionType $type): string => (string) $type, $this->types));
}
}
Loading

0 comments on commit 356777b

Please sign in to comment.