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