1: <?php declare(strict_types = 1);
2:
3: namespace ApiGen\Info;
4:
5: use ApiGen\Index\Index;
6: use ApiGen\Info\Traits\HasGenericParameters;
7: use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
8: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
9:
10: use function count;
11: use function strtolower;
12:
13:
14: class MethodInfo extends MemberInfo
15: {
16: use HasGenericParameters;
17:
18:
19: /** @var string */
20: public string $nameLower;
21:
22: /** @var ParameterInfo[] indexed by [parameterName] */
23: public array $parameters = [];
24:
25: /** @var TypeNode|null */
26: public ?TypeNode $returnType = null;
27:
28: /** @var PhpDocTextNode[] indexed by [] */
29: public array $returnDescription = [];
30:
31: /** @var bool */
32: public bool $byRef = false;
33:
34: /** @var bool */
35: public bool $static = false;
36:
37: /** @var bool */
38: public bool $abstract = false;
39:
40: /** @var bool */
41: public bool $final = false;
42:
43:
44: public function __construct(string $name)
45: {
46: parent::__construct($name);
47: $this->nameLower = strtolower($name);
48: }
49:
50:
51: /**
52: * @return PhpDocTextNode[] indexed by []
53: */
54: public function getEffectiveDescription(Index $index, ClassLikeInfo $classLike): array
55: {
56: if (count($this->description) > 0) {
57: return $this->description;
58: }
59:
60: foreach ($this->ancestors($index, $classLike) as $ancestor) {
61: $description = $ancestor->methods[$this->nameLower]->getEffectiveDescription($index, $ancestor);
62:
63: if (count($description) > 0) {
64: return $description;
65: }
66: }
67:
68: return [];
69: }
70:
71:
72: /**
73: * @return PhpDocTextNode[] indexed by []
74: */
75: public function getEffectiveReturnDescription(Index $index, ClassLikeInfo $classLike): array
76: {
77: if (count($this->returnDescription) > 0) {
78: return $this->returnDescription;
79: }
80:
81: foreach ($this->ancestors($index, $classLike) as $ancestor) {
82: $description = $ancestor->methods[$this->nameLower]->getEffectiveReturnDescription($index, $ancestor);
83:
84: if (count($description) > 0) {
85: return $description;
86: }
87: }
88:
89: return [];
90: }
91:
92:
93: /**
94: * @return iterable<ClassLikeInfo>
95: */
96: public function ancestors(Index $index, ClassLikeInfo $classLike): iterable
97: {
98: yield from $index->methodOverrides[$classLike->name->fullLower][$this->nameLower] ?? [];
99: yield from $index->methodImplements[$classLike->name->fullLower][$this->nameLower] ?? [];
100: }
101: }
102: