rector/packages/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php
Abdul Malik Ikhsan fc10fce13d
[Rectify] [Php81] Enable Rectify on Readonly Property only (#1384)
* re-enable rectify and ecs

* [Rectify] [Php81] Enable Rectify on Readonly Property only

* comment

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
2021-12-04 15:32:52 +03:00

40 lines
859 B
PHP

<?php
declare(strict_types=1);
namespace Rector\BetterPhpDocParser\ValueObject\Type;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Stringable;
final class BracketsAwareUnionTypeNode extends UnionTypeNode implements Stringable
{
/**
* @param TypeNode[] $types
*/
public function __construct(
array $types,
private readonly bool $isWrappedInBrackets = false
) {
parent::__construct($types);
}
/**
* Preserve common format
*/
public function __toString(): string
{
if (! $this->isWrappedInBrackets) {
return implode('|', $this->types);
}
return '(' . implode('|', $this->types) . ')';
}
public function isWrappedInBrackets(): bool
{
return $this->isWrappedInBrackets;
}
}