Skip to content

Commit fc43997

Browse files
author
Kirill Nesmeyanov
committed
Remove null fields from json result and add hint fields
1 parent f639dd8 commit fc43997

18 files changed

+31
-129
lines changed

src/Node/NodeList.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ public function count(): int
4949

5050
public function jsonSerialize(): array
5151
{
52-
$items = [];
53-
54-
foreach ($this->items as $item) {
55-
$items[] = $item->jsonSerialize();
56-
}
57-
58-
return ['items' => $items];
52+
return ['items' => $this->items];
5953
}
6054
}

src/Node/Stmt/Callable/ParameterNode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public function __toString(): string
6161

6262
public function jsonSerialize(): array
6363
{
64-
return [
64+
return \array_filter([
6565
'name' => $this->name?->getValue(),
66-
'type' => $this->type?->jsonSerialize(),
66+
'type' => $this->type,
6767
'output' => $this->output,
6868
'variadic' => $this->variadic,
6969
'optional' => $this->optional,
70-
];
70+
], static fn (mixed $value): bool => $value !== null);
7171
}
7272
}

src/Node/Stmt/CallableTypeNode.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public function __construct(
1717

1818
public function jsonSerialize(): array
1919
{
20-
return [
20+
return \array_filter([
2121
'kind' => TypeKind::CALLABLE_KIND,
2222
'name' => $this->name->toString(),
23-
'parameters' => $this->parameters->jsonSerialize(),
24-
'type' => $this->type?->jsonSerialize(),
25-
];
23+
'parameters' => $this->parameters,
24+
'type' => $this->type,
25+
], static fn (mixed $value): bool => $value !== null);
2626
}
2727
}

src/Node/Stmt/ClassConstMaskNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function __construct(
2323

2424
public function jsonSerialize(): array
2525
{
26-
return [
26+
return \array_filter([
2727
'kind' => TypeKind::CLASS_CONST_MASK_KIND,
2828
'class' => $this->class->toString(),
2929
'constant' => $this->constant?->toString(),
30-
];
30+
], static fn (mixed $value): bool => $value !== null);
3131
}
3232
}

src/Node/Stmt/ClassConstNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public function __construct(Name $class, Identifier|string $constant)
1919

2020
public function jsonSerialize(): array
2121
{
22-
return [
22+
return \array_filter([
2323
'kind' => TypeKind::CLASS_CONST_KIND,
2424
'class' => $this->class->toString(),
2525
'constant' => $this->constant?->toString(),
26-
];
26+
], static fn (mixed $value): bool => $value !== null);
2727
}
2828
}

src/Node/Stmt/Condition/Condition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public function jsonSerialize(): array
1818
{
1919
return [
2020
'kind' => ConditionKind::UNKNOWN,
21-
'subject' => $this->subject->jsonSerialize(),
22-
'target' => $this->target->jsonSerialize(),
21+
'subject' => $this->subject,
22+
'target' => $this->target,
2323
];
2424
}
2525
}

src/Node/Stmt/ConstMaskNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function jsonSerialize(): array
2121
{
2222
return [
2323
'kind' => TypeKind::CONST_MASK_KIND,
24-
'name' => $this->name->jsonSerialize(),
24+
'name' => $this->name,
2525
];
2626
}
2727
}

src/Node/Stmt/GenericTypeStmt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function jsonSerialize(): array
2020
{
2121
return [
2222
...parent::jsonSerialize(),
23-
'type' => $this->type->jsonSerialize(),
23+
'type' => $this->type,
2424
];
2525
}
2626

src/Node/Stmt/LogicalTypeNode.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,9 @@ public function count(): int
5959

6060
public function jsonSerialize(): array
6161
{
62-
$items = [];
63-
64-
foreach ($this->statements as $statement) {
65-
$items[] = $statement->jsonSerialize();
66-
}
67-
6862
return [
6963
...parent::jsonSerialize(),
70-
'items' => $items,
64+
'items' => $this->statements,
7165
];
7266
}
7367

src/Node/Stmt/NamedTypeNode.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,11 @@ public function __construct(
2626

2727
public function jsonSerialize(): array
2828
{
29-
$result = [
29+
return \array_filter([
3030
'kind' => TypeKind::TYPE_KIND,
3131
'name' => $this->name->toString(),
32-
];
33-
34-
if ($this->arguments !== null) {
35-
$arguments = [];
36-
37-
foreach ($this->arguments as $argument) {
38-
$arguments[] = $argument->value->jsonSerialize();
39-
}
40-
41-
$result['arguments'] = $arguments;
42-
}
43-
44-
if ($this->fields !== null) {
45-
$result['fields'] = $this->fields->jsonSerialize();
46-
}
47-
48-
return $result;
32+
'arguments' => $this->arguments,
33+
'fields' => $this->fields,
34+
], static fn (mixed $value): bool => $value !== null);
4935
}
5036
}

0 commit comments

Comments
 (0)