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:
35: public function __toString(): string
36: {
37: if ($this->keyName !== null) {
38: return sprintf(
39: '%s%s: %s',
40: (string) $this->keyName,
41: $this->optional ? '?' : '',
42: (string) $this->valueType,
43: );
44: }
45:
46: return (string) $this->valueType;
47: }
48:
49: }
50: