1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\Type;
4:
5: use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
6: use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
7: use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
8: use PHPStan\PhpDocParser\Ast\Node;
9: use PHPStan\PhpDocParser\Ast\NodeAttributes;
10: use function sprintf;
11:
12: class ArrayShapeItemNode implements Node
13: {
14:
15: use NodeAttributes;
16:
17: /** @var ConstExprIntegerNode|ConstExprStringNode|ConstFetchNode|IdentifierTypeNode|null */
18: public $keyName;
19:
20: public bool $optional;
21:
22: public TypeNode $valueType;
23:
24: /**
25: * @param ConstExprIntegerNode|ConstExprStringNode|ConstFetchNode|IdentifierTypeNode|null $keyName
26: */
27: public function __construct($keyName, bool $optional, TypeNode $valueType)
28: {
29: $this->keyName = $keyName;
30: $this->optional = $optional;
31: $this->valueType = $valueType;
32: }
33:
34: public function __toString(): string
35: {
36: if ($this->keyName !== null) {
37: return sprintf(
38: '%s%s: %s',
39: (string) $this->keyName,
40: $this->optional ? '?' : '',
41: (string) $this->valueType,
42: );
43: }
44:
45: return (string) $this->valueType;
46: }
47:
48: }
49: