Skip to content

Commit

Permalink
Apply rector, simplifying Printer
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Nov 29, 2023
1 parent f248835 commit b16bd96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
20 changes: 6 additions & 14 deletions src/Language/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ public function printAST(Node $node): string
}

/** @throws \JsonException */
protected function p(?Node $node, bool $isDescription = false): string
protected function p(?Node $node): string
{
if ($node === null) {
return '';
}

switch (true) {
case $node instanceof ArgumentNode:
case $node instanceof ObjectFieldNode:
return $this->p($node->name) . ': ' . $this->p($node->value);

case $node instanceof BooleanValueNode:
Expand Down Expand Up @@ -166,6 +167,9 @@ protected function p(?Node $node, bool $isDescription = false): string
);

case $node instanceof EnumValueNode:
case $node instanceof FloatValueNode:
case $node instanceof IntValueNode:
case $node instanceof NameNode:
return $node->value;

case $node instanceof FieldDefinitionNode:
Expand Down Expand Up @@ -219,9 +223,6 @@ protected function p(?Node $node, bool $isDescription = false): string
' '
);

case $node instanceof FloatValueNode:
return $node->value;

case $node instanceof FragmentDefinitionNode:
// Note: fragment variable definitions are experimental and may be changed or removed in the future.
return 'fragment ' . $this->p($node->name)
Expand Down Expand Up @@ -310,18 +311,12 @@ protected function p(?Node $node, bool $isDescription = false): string
' '
);

case $node instanceof IntValueNode:
return $node->value;

case $node instanceof ListTypeNode:
return '[' . $this->p($node->type) . ']';

case $node instanceof ListValueNode:
return '[' . $this->printList($node->values, ', ') . ']';

case $node instanceof NameNode:
return $node->value;

case $node instanceof NamedTypeNode:
return $this->p($node->name);

Expand All @@ -331,9 +326,6 @@ protected function p(?Node $node, bool $isDescription = false): string
case $node instanceof NullValueNode:
return 'null';

case $node instanceof ObjectFieldNode:
return $this->p($node->name) . ': ' . $this->p($node->value);

case $node instanceof ObjectTypeDefinitionNode:
return $this->addDescription($node->description, $this->join(
[
Expand Down Expand Up @@ -511,7 +503,7 @@ protected function printListBlock(NodeList $list): string
/** @throws \JsonException */
protected function addDescription(?StringValueNode $description, string $body): string
{
return $this->join([$this->p($description, true), $body], "\n");
return $this->join([$this->p($description), $body], "\n");
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tests/Type/EnumTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ public function setUp(): void
}

if ($args['provideTwo'] ?? false) {
return ['two', 'TWO'];
return [
'two',
'TWO',
];
}

return $args['fromEnum'];
Expand Down

0 comments on commit b16bd96

Please sign in to comment.