Skip to content

Commit d451269

Browse files
author
Kirill Nesmeyanov
committed
Removed extra parentheses from logical argument types in pretty printer
1 parent 6a9905a commit d451269

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

src/PrettyPrinter.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ protected function printCallableArgumentNode(ParameterNode $node): string
402402
$type = $this->make($node->type);
403403
}
404404

405-
if ($node->type instanceof LogicalTypeNode) {
406-
$type = \sprintf('(%s)', $type);
407-
}
408-
409405
$result = [$type];
410406

411407
if ($node->name !== null) {
@@ -443,10 +439,14 @@ protected function shouldWrapReturnType(TypeStatement $type): bool
443439
class: LogicalTypeNode::class,
444440
break: static function (Node $node): bool {
445441
// Break on non-empty template parameters.
446-
$isInTemplate = $node instanceof NamedTypeNode && $node->arguments !== null && $node->arguments->items !== [];
442+
$isInTemplate = $node instanceof NamedTypeNode
443+
&& $node->arguments !== null
444+
&& $node->arguments->items !== [];
447445

448446
// Break on non-empty shape fields.
449-
$isInShape = $node instanceof NamedTypeNode && $node->fields !== null && $node->fields->items !== [];
447+
$isInShape = $node instanceof NamedTypeNode
448+
&& $node->fields !== null
449+
&& $node->fields->items !== [];
450450

451451
return $isInTemplate || $isInShape;
452452
},
@@ -466,15 +466,11 @@ protected function printUnionTypeNode(UnionTypeNode $node): string
466466
{
467467
$delimiter = $this->wrapUnionType ? ' | ' : '|';
468468

469-
try {
470-
return \vsprintf($this->nesting > 0 ? '(%s)' : '%s', [
471-
\implode($delimiter, [
472-
...$this->unwrapAndPrint($node),
473-
]),
474-
]);
475-
} finally {
476-
++$this->nesting;
477-
}
469+
return \vsprintf($this->nesting++ > 0 ? '(%s)' : '%s', [
470+
\implode($delimiter, [
471+
...$this->unwrapAndPrint($node),
472+
]),
473+
]);
478474
}
479475

480476
/**
@@ -486,15 +482,11 @@ protected function printIntersectionTypeNode(IntersectionTypeNode $node): string
486482
{
487483
$delimiter = $this->wrapIntersectionType ? ' & ' : '&';
488484

489-
try {
490-
return \vsprintf($this->nesting > 0 ? '(%s)' : '%s', [
491-
\implode($delimiter, [
492-
...$this->unwrapAndPrint($node),
493-
]),
494-
]);
495-
} finally {
496-
++$this->nesting;
497-
}
485+
return \vsprintf($this->nesting++ > 0 ? '(%s)' : '%s', [
486+
\implode($delimiter, [
487+
...$this->unwrapAndPrint($node),
488+
]),
489+
]);
498490
}
499491

500492
/**

0 commit comments

Comments
 (0)