Debian Codegraph @

vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php

raw
1 <?php declare(strict_types = 1);
2
3 namespace PHPStan\PhpDocParser\Ast\ConstExpr;
4
5 use PHPStan\PhpDocParser\Ast\NodeAttributes;
6 use function sprintf;
7
8 class ConstExprArrayItemNode implements ConstExprNode
9 {
10
11 use NodeAttributes;
12
13 public ?ConstExprNode $key = null;
14
15 public ConstExprNode $value;
16
17 public function __construct(?ConstExprNode $key, ConstExprNode $value)
18 {
19 $this->key = $key;
20 $this->value = $value;
21 }
22
23 public function __toString(): string
24 {
25 if ($this->key !== null) {
26 return sprintf('%s => %s', $this->key, $this->value);
27
28 }
29
30 return (string) $this->value;
31 }
32
33 /**
34 * @param array<string, mixed> $properties
35 */
36 public static function __set_state(array $properties): self
37 {
38 $instance = new self($properties['key'], $properties['value']);
39 if (isset($properties['attributes'])) {
40 foreach ($properties['attributes'] as $key => $value) {
41 $instance->setAttribute($key, $value);
42 }
43 }
44 return $instance;
45 }
46
47 }