1: <?php declare(strict_types = 1);
2:
3: namespace ApiGen\Info;
4:
5: use ApiGen\Index\Index;
6: use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode;
7: use PHPStan\PhpDocParser\Ast\Type\TypeNode;
8:
9: use function array_values;
10: use function count;
11:
12:
13: class ParameterInfo
14: {
15: /** @var string */
16: public string $name;
17:
18: /** @var int */
19: public int $position;
20:
21: /** @var PhpDocTextNode[] indexed by [] */
22: public array $description = [];
23:
24: /** @var TypeNode|null */
25: public ?TypeNode $type = null;
26:
27: /** @var bool */
28: public bool $byRef = false;
29:
30: /** @var bool */
31: public bool $variadic = false;
32:
33: /** @var ExprInfo|null */
34: public ?ExprInfo $default = null;
35:
36:
37: public function __construct(string $name, int $position)
38: {
39: $this->name = $name;
40: $this->position = $position;
41: }
42:
43:
44: /**
45: * @return PhpDocTextNode[] indexed by []
46: */
47: public function getEffectiveDescription(Index $index, ClassLikeInfo $classLike, MethodInfo $method): array
48: {
49: if (count($this->description) > 0) {
50: return $this->description;
51: }
52:
53: foreach ($method->ancestors($index, $classLike) as $ancestor) {
54: $ancestorMethod = $ancestor->methods[$method->nameLower];
55: $ancestorParameter = array_values($ancestorMethod->parameters)[$this->position] ?? null;
56: $description = $ancestorParameter?->getEffectiveDescription($index, $ancestor, $ancestorMethod) ?? [];
57:
58: if (count($description) > 0) {
59: return $description;
60: }
61: }
62:
63: return [];
64: }
65: }
66: