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\Node; |
8: | use PHPStan\PhpDocParser\Ast\NodeAttributes; |
9: | use function sprintf; |
10: | |
11: | class ArrayShapeItemNode implements Node |
12: | { |
13: | |
14: | use NodeAttributes; |
15: | |
16: | |
17: | public $keyName; |
18: | |
19: | public bool $optional; |
20: | |
21: | public TypeNode $valueType; |
22: | |
23: | |
24: | |
25: | |
26: | public function __construct($keyName, bool $optional, TypeNode $valueType) |
27: | { |
28: | $this->keyName = $keyName; |
29: | $this->optional = $optional; |
30: | $this->valueType = $valueType; |
31: | } |
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: | |