1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Compiler\Pass; |
14
|
|
|
|
15
|
|
|
use phpDocumentor\Compiler\CompilerPassInterface; |
16
|
|
|
use phpDocumentor\Descriptor\Collection; |
17
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor; |
18
|
|
|
|
19
|
|
|
final class ResolveInlineMarkers implements CompilerPassInterface |
20
|
|
|
{ |
21
|
|
|
const COMPILER_PRIORITY = 9000; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* {@inheritDoc} |
25
|
|
|
*/ |
26
|
|
|
public function getDescription(): string |
27
|
|
|
{ |
28
|
|
|
return 'Collect all markers in a file'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Scans the files for markers and records them in the markers property of a file. |
33
|
|
|
*/ |
34
|
1 |
|
public function execute(ProjectDescriptor $project): void |
35
|
|
|
{ |
36
|
1 |
|
$markerTerms = $project->getSettings()->getMarkers(); |
37
|
|
|
|
38
|
1 |
|
foreach ($project->getFiles() as $file) { |
39
|
1 |
|
$marker_data = []; |
40
|
1 |
|
$matches = []; |
41
|
1 |
|
preg_match_all( |
42
|
1 |
|
'~//[\s]*(' . implode('|', $markerTerms) . ')\:?[\s]*(.*)~', |
43
|
1 |
|
$file->getSource(), |
44
|
1 |
|
$matches, |
45
|
1 |
|
PREG_SET_ORDER | PREG_OFFSET_CAPTURE |
46
|
|
|
); |
47
|
|
|
|
48
|
1 |
|
foreach ($matches as $match) { |
|
|
|
|
49
|
1 |
|
list($before) = str_split($file->getSource(), $match[1][1]); // fetches all the text before the match |
50
|
|
|
|
51
|
1 |
|
$line_number = strlen($before) - strlen(str_replace("\n", '', $before)) + 1; |
52
|
|
|
|
53
|
1 |
|
$marker_data[] = ['type' => trim($match[1][0], '@'), 'line' => $line_number, $match[2][0]]; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
$file->setMarkers(new Collection($marker_data)); |
57
|
|
|
} |
58
|
1 |
|
} |
59
|
|
|
} |
60
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.