Debian Codegraph @

vendor/phpstan/phpdoc-parser/src/Ast/NodeAttributes.php

raw
1 <?php declare(strict_types = 1);
2
3 namespace PHPStan\PhpDocParser\Ast;
4
5 use function array_key_exists;
6
7 trait NodeAttributes
8 {
9
10 /** @var array<string, mixed> */
11 private array $attributes = [];
12
13 /**
14 * @param mixed $value
15 */
16 public function setAttribute(string $key, $value): void
17 {
18 if ($value === null) {
19 unset($this->attributes[$key]);
20 return;
21 }
22 $this->attributes[$key] = $value;
23 }
24
25 public function hasAttribute(string $key): bool
26 {
27 return array_key_exists($key, $this->attributes);
28 }
29
30 /**
31 * @return mixed
32 */
33 public function getAttribute(string $key)
34 {
35 if ($this->hasAttribute($key)) {
36 return $this->attributes[$key];
37 }
38
39 return null;
40 }
41
42 }