This repository was archived by the owner on Apr 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhpDocInfo.php
97 lines (80 loc) · 2.17 KB
/
PhpDocInfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php declare(strict_types=1);
namespace Symplify\BetterReflectionDocBlock\PhpDocParser;
use Nette\Utils\Strings;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
final class PhpDocInfo
{
/**
* @var PhpDocNode
*/
private $phpDocNode;
/**
* @var mixed[]
*/
private $tokens = [];
/**
* @var PhpDocNode
*/
private $originalPhpDocNode;
/**
* @var string
*/
private $originalContent;
/**
* @param mixed[] $tokens
*/
public function __construct(PhpDocNode $phpDocNode, array $tokens, string $originalContent)
{
$this->phpDocNode = $phpDocNode;
$this->tokens = $tokens;
$this->originalPhpDocNode = clone $phpDocNode;
$this->originalContent = $originalContent;
}
public function getOriginalContent(): string
{
return $this->originalContent;
}
public function getPhpDocNode(): PhpDocNode
{
return $this->phpDocNode;
}
public function getOriginalPhpDocNode(): PhpDocNode
{
return $this->originalPhpDocNode;
}
/**
* @return mixed[]
*/
public function getTokens(): array
{
return $this->tokens;
}
public function getParamTagValueByName(string $name): ?ParamTagValueNode
{
$phpDocNode = $this->getPhpDocNode();
foreach ($phpDocNode->getParamTagValues() as $paramTagValue) {
if (Strings::match($paramTagValue->parameterName, '#^(\$)?' . $name . '$#')) {
return $paramTagValue;
}
}
return null;
}
public function getVarTagValue(): ?VarTagValueNode
{
return $this->getPhpDocNode()->getVarTagValues()[0] ?? null;
}
public function getReturnTagValue(): ?ReturnTagValueNode
{
return $this->getPhpDocNode()->getReturnTagValues()[0] ?? null;
}
/**
* @return ParamTagValueNode[]
*/
public function getParamTagValues(): array
{
return $this->getPhpDocNode()->getParamTagValues();
}
}