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: /** @var bool */
16: public $isStatic;
17:
18: /** @var TypeNode|null */
19: public $returnType;
20:
21: /** @var string */
22: public $methodName;
23:
24: /** @var TemplateTagValueNode[] */
25: public $templateTypes;
26:
27: /** @var MethodTagValueParameterNode[] */
28: public $parameters;
29:
30: /** @var string (may be empty) */
31: public $description;
32:
33: /**
34: * @param MethodTagValueParameterNode[] $parameters
35: * @param TemplateTagValueNode[] $templateTypes
36: */
37: public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $parameters, string $description, array $templateTypes = [])
38: {
39: $this->isStatic = $isStatic;
40: $this->returnType = $returnType;
41: $this->methodName = $methodName;
42: $this->parameters = $parameters;
43: $this->description = $description;
44: $this->templateTypes = $templateTypes;
45: }
46:
47:
48: public function __toString(): string
49: {
50: $static = $this->isStatic ? 'static ' : '';
51: $returnType = $this->returnType !== null ? "{$this->returnType} " : '';
52: $parameters = implode(', ', $this->parameters);
53: $description = $this->description !== '' ? " {$this->description}" : '';
54: $templateTypes = count($this->templateTypes) > 0 ? '<' . implode(', ', $this->templateTypes) . '>' : '';
55: return "{$static}{$returnType}{$this->methodName}{$templateTypes}({$parameters}){$description}";
56: }
57:
58: }
59: