1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\PhpDocParser\Ast\PhpDoc;
4:
5: use PHPStan\PhpDocParser\Ast\NodeAttributes;
6: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
7: use function trim;
8:
9: class AssertTagValueNode implements PhpDocTagValueNode
10: {
11:
12: use NodeAttributes;
13:
14: public TypeNode $type;
15:
16: public string $parameter;
17:
18: public bool $isNegated;
19:
20: public bool $isEquality;
21:
22: /** @var string (may be empty) */
23: public string $description;
24:
25: public function __construct(TypeNode $type, string $parameter, bool $isNegated, string $description, bool $isEquality)
26: {
27: $this->type = $type;
28: $this->parameter = $parameter;
29: $this->isNegated = $isNegated;
30: $this->isEquality = $isEquality;
31: $this->description = $description;
32: }
33:
34: public function __toString(): string
35: {
36: $isNegated = $this->isNegated ? '!' : '';
37: $isEquality = $this->isEquality ? '=' : '';
38: return trim("{$isNegated}{$isEquality}{$this->type} {$this->parameter} {$this->description}");
39: }
40:
41: /**
42: * @param array<string, mixed> $properties
43: */
44: public static function __set_state(array $properties): self
45: {
46: $instance = new self($properties['type'], $properties['parameter'], $properties['isNegated'], $properties['description'], $properties['isEquality']);
47: if (isset($properties['attributes'])) {
48: foreach ($properties['attributes'] as $key => $value) {
49: $instance->setAttribute($key, $value);
50: }
51: }
52: return $instance;
53: }
54:
55: }
56: