| 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 count; |
| 8: | use function implode; |
| 9: | |
| 10: | class MethodTagValueNode implements PhpDocTagValueNode |
| 11: | { |
| 12: | |
| 13: | use NodeAttributes; |
| 14: | |
| 15: | public bool $isStatic; |
| 16: | |
| 17: | public ?TypeNode $returnType = null; |
| 18: | |
| 19: | public string $methodName; |
| 20: | |
| 21: | |
| 22: | public array $templateTypes; |
| 23: | |
| 24: | |
| 25: | public array $parameters; |
| 26: | |
| 27: | |
| 28: | public string $description; |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $parameters, string $description, array $templateTypes) |
| 35: | { |
| 36: | $this->isStatic = $isStatic; |
| 37: | $this->returnType = $returnType; |
| 38: | $this->methodName = $methodName; |
| 39: | $this->parameters = $parameters; |
| 40: | $this->description = $description; |
| 41: | $this->templateTypes = $templateTypes; |
| 42: | } |
| 43: | |
| 44: | public function __toString(): string |
| 45: | { |
| 46: | $static = $this->isStatic ? 'static ' : ''; |
| 47: | $returnType = $this->returnType !== null ? "{$this->returnType} " : ''; |
| 48: | $parameters = implode(', ', $this->parameters); |
| 49: | $description = $this->description !== '' ? " {$this->description}" : ''; |
| 50: | $templateTypes = count($this->templateTypes) > 0 ? '<' . implode(', ', $this->templateTypes) . '>' : ''; |
| 51: | return "{$static}{$returnType}{$this->methodName}{$templateTypes}({$parameters}){$description}"; |
| 52: | } |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public static function __set_state(array $properties): self |
| 58: | { |
| 59: | $instance = new self($properties['isStatic'], $properties['returnType'], $properties['methodName'], $properties['parameters'], $properties['description'], $properties['templateTypes']); |
| 60: | if (isset($properties['attributes'])) { |
| 61: | foreach ($properties['attributes'] as $key => $value) { |
| 62: | $instance->setAttribute($key, $value); |
| 63: | } |
| 64: | } |
| 65: | return $instance; |
| 66: | } |
| 67: | |
| 68: | } |
| 69: | |