| 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 AssertTagMethodValueNode implements PhpDocTagValueNode |
| 10: | { |
| 11: | |
| 12: | use NodeAttributes; |
| 13: | |
| 14: | public TypeNode $type; |
| 15: | |
| 16: | public string $parameter; |
| 17: | |
| 18: | public string $method; |
| 19: | |
| 20: | public bool $isNegated; |
| 21: | |
| 22: | public bool $isEquality; |
| 23: | |
| 24: | |
| 25: | public string $description; |
| 26: | |
| 27: | public function __construct(TypeNode $type, string $parameter, string $method, bool $isNegated, string $description, bool $isEquality) |
| 28: | { |
| 29: | $this->type = $type; |
| 30: | $this->parameter = $parameter; |
| 31: | $this->method = $method; |
| 32: | $this->isNegated = $isNegated; |
| 33: | $this->isEquality = $isEquality; |
| 34: | $this->description = $description; |
| 35: | } |
| 36: | |
| 37: | public function __toString(): string |
| 38: | { |
| 39: | $isNegated = $this->isNegated ? '!' : ''; |
| 40: | $isEquality = $this->isEquality ? '=' : ''; |
| 41: | return trim("{$isNegated}{$isEquality}{$this->type} {$this->parameter}->{$this->method}() {$this->description}"); |
| 42: | } |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | public static function __set_state(array $properties): self |
| 48: | { |
| 49: | $instance = new self($properties['type'], $properties['parameter'], $properties['method'], $properties['isNegated'], $properties['description'], $properties['isEquality']); |
| 50: | if (isset($properties['attributes'])) { |
| 51: | foreach ($properties['attributes'] as $key => $value) { |
| 52: | $instance->setAttribute($key, $value); |
| 53: | } |
| 54: | } |
| 55: | return $instance; |
| 56: | } |
| 57: | |
| 58: | } |
| 59: | |