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\NodeAttributes; |
7: | use function sprintf; |
8: | |
9: | class ObjectShapeItemNode implements TypeNode |
10: | { |
11: | |
12: | use NodeAttributes; |
13: | |
14: | |
15: | public $keyName; |
16: | |
17: | |
18: | public $optional; |
19: | |
20: | |
21: | public $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: | |