Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0fe292d

Browse files
[BCB] ArrayShapeItemNode and ObjectShapeItemNode are not standalone TypeNode, just Node
1 parent 5504a3b commit 0fe292d

File tree

5 files changed

+33
-30
lines changed

5 files changed

+33
-30
lines changed

‎UPGRADING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ The line with `some text in the middle` in phpdoc-parser 2.0 is now part of the
126126
* Constructor parameter `$isReference` in `TypelessParamTagValueNode` made required
127127
* Constructor parameter `$templateTypes` in `CallableTypeNode` made required
128128
* Constructor parameters `$expectedTokenValue` and `$currentTokenLine` in `ParserException` made required
129+
* `ArrayShapeItemNode` and `ObjectShapeItemNode` are not standalone TypeNode, just Node

‎src/Ast/Type/ArrayShapeItemNode.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
66
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
7+
use PHPStan\PhpDocParser\Ast\Node;
78
use PHPStan\PhpDocParser\Ast\NodeAttributes;
89
use function sprintf;
910

10-
class ArrayShapeItemNode implements TypeNode
11+
class ArrayShapeItemNode implements Node
1112
{
1213

1314
use NodeAttributes;

‎src/Ast/Type/ObjectShapeItemNode.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
namespace PHPStan\PhpDocParser\Ast\Type;
44

55
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
6+
use PHPStan\PhpDocParser\Ast\Node;
67
use PHPStan\PhpDocParser\Ast\NodeAttributes;
78
use function sprintf;
89

9-
class ObjectShapeItemNode implements TypeNode
10+
class ObjectShapeItemNode implements Node
1011
{
1112

1213
use NodeAttributes;

‎src/Printer/Printer.php‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,30 @@ function (PhpDocChildNode $child): string {
248248
if ($node instanceof DoctrineArrayItem) {
249249
return (string) $node;
250250
}
251+
if ($node instanceof ArrayShapeItemNode) {
252+
if ($node->keyName !== null) {
253+
return sprintf(
254+
'%s%s: %s',
255+
$this->print($node->keyName),
256+
$node->optional ? '?' : '',
257+
$this->printType($node->valueType),
258+
);
259+
}
260+
261+
return $this->printType($node->valueType);
262+
}
263+
if ($node instanceof ObjectShapeItemNode) {
264+
if ($node->keyName !== null) {
265+
return sprintf(
266+
'%s%s: %s',
267+
$this->print($node->keyName),
268+
$node->optional ? '?' : '',
269+
$this->printType($node->valueType),
270+
);
271+
}
272+
273+
return $this->printType($node->valueType);
274+
}
251275

252276
throw new LogicException(sprintf('Unknown node type %s', get_class($node)));
253277
}
@@ -364,26 +388,14 @@ private function printTagValue(PhpDocTagValueNode $node): string
364388
private function printType(TypeNode $node): string
365389
{
366390
if ($node instanceof ArrayShapeNode) {
367-
$items = array_map(fn (ArrayShapeItemNode $item): string => $this->printType($item), $node->items);
391+
$items = array_map(fn (ArrayShapeItemNode $item): string => $this->print($item), $node->items);
368392

369393
if (! $node->sealed) {
370394
$items[] = '...' . ($node->unsealedType === null ? '' : $this->print($node->unsealedType));
371395
}
372396

373397
return $node->kind . '{' . implode(', ', $items) . '}';
374398
}
375-
if ($node instanceof ArrayShapeItemNode) {
376-
if ($node->keyName !== null) {
377-
return sprintf(
378-
'%s%s: %s',
379-
$this->print($node->keyName),
380-
$node->optional ? '?' : '',
381-
$this->printType($node->valueType),
382-
);
383-
}
384-
385-
return $this->printType($node->valueType);
386-
}
387399
if ($node instanceof ArrayTypeNode) {
388400
return $this->printOffsetAccessType($node->type) . '[]';
389401
}
@@ -469,22 +481,10 @@ private function printType(TypeNode $node): string
469481
return '?' . $this->printType($node->type);
470482
}
471483
if ($node instanceof ObjectShapeNode) {
472-
$items = array_map(fn (ObjectShapeItemNode $item): string => $this->printType($item), $node->items);
484+
$items = array_map(fn (ObjectShapeItemNode $item): string => $this->print($item), $node->items);
473485

474486
return 'object{' . implode(', ', $items) . '}';
475487
}
476-
if ($node instanceof ObjectShapeItemNode) {
477-
if ($node->keyName !== null) {
478-
return sprintf(
479-
'%s%s: %s',
480-
$this->print($node->keyName),
481-
$node->optional ? '?' : '',
482-
$this->printType($node->valueType),
483-
);
484-
}
485-
486-
return $this->printType($node->valueType);
487-
}
488488
if ($node instanceof OffsetAccessTypeNode) {
489489
return $this->printOffsetAccessType($node->type) . '[' . $this->printType($node->offset) . ']';
490490
}

‎tests/PHPStan/Parser/TypeParserTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,7 @@ public function dataLinesAndIndexes(): iterable
28882888
6,
28892889
],
28902890
[
2891-
static fn (ArrayShapeNode $typeNode): TypeNode => $typeNode->items[0],
2891+
static fn (ArrayShapeNode $typeNode): Node => $typeNode->items[0],
28922892
'foo: int',
28932893
1,
28942894
1,
@@ -2924,7 +2924,7 @@ public function dataLinesAndIndexes(): iterable
29242924
6,
29252925
],
29262926
[
2927-
static fn (ObjectShapeNode $typeNode): TypeNode => $typeNode->items[0],
2927+
static fn (ObjectShapeNode $typeNode): Node => $typeNode->items[0],
29282928
'foo: int',
29292929
1,
29302930
1,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /