|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright MediaCT. All rights reserved. |
|
4
|
|
|
* https://www.mediact.nl |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Mediact\CodingStandard; |
|
7
|
|
|
|
|
8
|
|
|
use PHP_CodeSniffer\Files\File; |
|
|
|
|
|
|
9
|
|
|
use PHP_CodeSniffer\Util\Tokens; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
trait PhpDocCommentTrait |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Gets the end of a PHPDoc comment that is directly above an element. |
|
15
|
|
|
* |
|
16
|
|
|
* @param File $file |
|
17
|
|
|
* @param int $elementIndex |
|
18
|
|
|
* |
|
19
|
|
|
* @return bool|int |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function findCommentEndIndex(File $file, $elementIndex) |
|
22
|
|
|
{ |
|
23
|
|
|
$searchTypes = array_merge(Tokens::$methodPrefixes, [T_WHITESPACE]); |
|
24
|
|
|
$previousToken = $file->findPrevious($searchTypes, $elementIndex - 1, null, true); |
|
25
|
|
|
if ($previousToken |
|
26
|
|
|
&& $file->getTokens()[$previousToken]['code'] == T_DOC_COMMENT_CLOSE_TAG |
|
|
|
|
|
|
27
|
|
|
) { |
|
28
|
|
|
return $previousToken; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
return false; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gets the start of a PHPDoc comment based on the end index. |
|
36
|
|
|
* |
|
37
|
|
|
* @param File $file |
|
38
|
|
|
* @param int $commentEnd |
|
39
|
|
|
* |
|
40
|
|
|
* @return bool|int |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function findCommentStartIndex(File $file, $commentEnd) |
|
43
|
|
|
{ |
|
44
|
|
|
if (!$commentEnd) { |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $file->getTokens()[$commentEnd]['comment_opener']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Gets the index of a PHPDoc tag. |
|
54
|
|
|
* |
|
55
|
|
|
* @param File $file |
|
56
|
|
|
* @param int $commentStart |
|
57
|
|
|
* @param string $tagName |
|
58
|
|
|
* |
|
59
|
|
|
* @return bool|int |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function findSingleCommentTagIndex(File $file, $commentStart, $tagName) |
|
62
|
|
|
{ |
|
63
|
|
|
$indexes = $this->findCommentTagIndexes($file, $commentStart, $tagName); |
|
64
|
|
|
return count($indexes) |
|
65
|
|
|
? array_shift($indexes) |
|
66
|
|
|
: false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Gets the indexes of a PHPDoc tag. |
|
71
|
|
|
* |
|
72
|
|
|
* @param File $file |
|
73
|
|
|
* @param int $commentStart |
|
74
|
|
|
* @param string $tagName |
|
75
|
|
|
* |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function findCommentTagIndexes(File $file, $commentStart, $tagName) |
|
79
|
|
|
{ |
|
80
|
|
|
$indexes = []; |
|
81
|
|
|
$tokens = $file->getTokens(); |
|
82
|
|
|
|
|
83
|
|
|
foreach ($tokens[$commentStart]['comment_tags'] as $index) { |
|
84
|
|
|
if ($tokens[$index]['content'] === $tagName) { |
|
85
|
|
|
$indexes[] = $index; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $indexes; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths