1 | <?php |
||
37 | class ResolveInlineLinkAndSeeTags implements CompilerPassInterface |
||
38 | { |
||
39 | const COMPILER_PRIORITY = 9002; |
||
40 | |||
41 | const REGEX_INLINE_LINK_OR_SEE_TAG = '/\{\@(see|link)[\ ]+([^\}]+)\}/'; |
||
42 | |||
43 | /** @var Queue */ |
||
44 | private $router; |
||
45 | |||
46 | /** @var DescriptorAbstract */ |
||
47 | private $descriptor; |
||
48 | |||
49 | /** @var Collection */ |
||
50 | private $elementCollection; |
||
51 | |||
52 | /** |
||
53 | * Registers the router queue with this pass. |
||
54 | */ |
||
55 | 5 | public function __construct(Queue $router) |
|
56 | { |
||
57 | 5 | $this->router = $router; |
|
58 | 5 | } |
|
59 | |||
60 | 1 | public function getDescription(): string |
|
64 | |||
65 | /** |
||
66 | * Iterates through each element in the project and replaces its inline @see and @link tag with a markdown |
||
67 | * representation. |
||
68 | */ |
||
69 | 4 | public function execute(ProjectDescriptor $project): void |
|
78 | |||
79 | /** |
||
80 | * Resolves all @see and @link tags in the description of the given descriptor to their markdown representation. |
||
81 | * |
||
82 | * @uses self::resolveTag() |
||
83 | */ |
||
84 | 4 | private function resolveSeeAndLinkTags(DescriptorAbstract $descriptor): void |
|
97 | |||
98 | /** |
||
99 | * Resolves an individual tag, indicated by the results of the Regex used to extract tags. |
||
100 | * |
||
101 | * @param string[] $match |
||
102 | * @return string|string[] |
||
103 | */ |
||
104 | 2 | private function resolveTag(array $match) |
|
126 | |||
127 | /** |
||
128 | * Determines if the given link string represents a URL by checking if it is prefixed with a URI scheme. |
||
129 | */ |
||
130 | 2 | private function isUrl(string $link): bool |
|
134 | |||
135 | /** |
||
136 | * Checks if the link represents a Fully Qualified Structural Element Name. |
||
137 | * |
||
138 | * @param Fqsen|string $link |
||
139 | */ |
||
140 | 2 | private function isFqsen($link): bool |
|
144 | |||
145 | /** |
||
146 | * Creates a Tag Reflector from the given array of tag line, tag name and tag content. |
||
147 | * |
||
148 | * @param string[] $match |
||
149 | */ |
||
150 | 2 | private function createLinkOrSeeTagFromRegexMatch(array $match): Tag |
|
167 | |||
168 | /** |
||
169 | * Resolves a QSEN to a FQSEN. |
||
170 | * |
||
171 | * If a relative QSEN is provided then this method will attempt to resolve it given the current namespace and |
||
172 | * namespace aliases. |
||
173 | * |
||
174 | * @param Fqsen|string $link |
||
175 | * @return Fqsen|string |
||
176 | */ |
||
177 | 2 | private function resolveQsen($link) |
|
185 | |||
186 | /** |
||
187 | * Generates a Markdown link to the given Descriptor or returns the link text if no route to the Descriptor could |
||
188 | * be matched. |
||
189 | * |
||
190 | * @param Fqsen|string $link |
||
191 | */ |
||
192 | 1 | private function resolveElement(DescriptorAbstract $element, $link, ?string $description = null): string |
|
203 | |||
204 | /** |
||
205 | * Returns the link for the given reflector. |
||
206 | * |
||
207 | * Because the link tag and the see tag have different methods to acquire the link text we abstract that into this |
||
208 | * method. |
||
209 | */ |
||
210 | 2 | private function getLinkText(Tag $tagReflector): ?string |
|
222 | |||
223 | /** |
||
224 | * Tries to find an element with the given FQSEN in the elements listing for this project. |
||
225 | * |
||
226 | * @param Fqsen|string $fqsen |
||
227 | */ |
||
228 | 2 | private function findElement($fqsen): ?DescriptorAbstract |
|
232 | |||
233 | /** |
||
234 | * Creates a DocBlock context containing the namespace and aliases for the current descriptor. |
||
235 | */ |
||
236 | 2 | private function createDocBlockContext(): Context |
|
246 | |||
247 | /** |
||
248 | * Generates a Markdown-formatted string representing a link with a description. |
||
249 | * |
||
250 | * @param Fqsen|string $link |
||
251 | */ |
||
252 | 1 | private function generateMarkdownLink($link, string $description): string |
|
256 | } |
||
257 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.