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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
<?php /** * Parses and verifies the doc comments for functions. * * PHP version 5 * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @link http://pear.php.net/package/PHP_CodeSniffer */
if (class_exists('Squiz_Sniffs_Commenting_FunctionCommentSniff', true) === false) { $error = 'Class Squiz_Sniffs_Commenting_FunctionCommentSniff not found'; throw new PHP_CodeSniffer_Exception($error); }
/** * Parses and verifies the doc comments for functions. * * Same as the Squiz standard, but adds support for API tags. * * @category PHP * @package PHP_CodeSniffer * @author Greg Sherwood <gsherwood@squiz.net> * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence * @version Release: 1.3.3 * @link http://pear.php.net/package/PHP_CodeSniffer */ class MySource_Sniffs_Commenting_FunctionCommentSniff extends Squiz_Sniffs_Commenting_FunctionCommentSniff {
/** * Process a list of unknown tags. * * @param int $commentStart The position in the stack where the comment started. * @param int $commentEnd The position in the stack where the comment ended. * * @return void */ protected function processUnknownTags($commentStart, $commentEnd) { $unknownTags = $this->commentParser->getUnknown(); $words = $this->commentParser->getWords(); $hasApiTag = false; $apiLength = 3; foreach ($unknownTags as $errorTag) { $pos = $errorTag['pos']; if ($errorTag['tag'] === 'api') { if ($hasApiTag === true) { // We've come across an API tag already, which means // we were not the first tag in the API list. $error = 'The @api tag must come first in the @api tag list in a function comment'; $this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiNotFirst'); }
$hasApiTag = true;
// There needs to be a blank line before the @api tag. // So expect a single space before the tag, then 2 newlines before // that, then some content. if (trim($words[($pos - 2)]) !== '' || strpos($words[($pos - 2)], $this->currentFile->eolChar) === false || strpos($words[($pos - 3)], $this->currentFile->eolChar) === false || trim($words[($pos - 4)]) === '' ) { $error = 'There must be one blank line before the @api tag in a function comment'; $this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiSpacing'); } } else if (substr($errorTag['tag'], 0, 4) === 'api-') { $hasApiTag = true;
$tagLength = strlen($errorTag['tag']); if ($tagLength > $apiLength) { $apiLength = $tagLength; }
if (trim($words[($pos - 2)]) !== '' || strpos($words[($pos - 2)], $this->currentFile->eolChar) === false || trim($words[($pos - 3)]) === '' ) { $error = 'There must be no blank line before the @%s tag in a function comment'; $data = array($errorTag['tag']); $this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiTagSpacing', $data); } } else { $error = '@%s tag is not allowed in function comment'; $data = array($errorTag['tag']); $this->currentFile->addWarning($error, ($commentStart + $errorTag['line']), 'TagNotAllowed', $data); }//end if }//end foreach
if ($hasApiTag === true) { // API tags must be the last tags in a function comment. $order = $this->commentParser->getTagOrders(); $lastTag = array_pop($order); if ($lastTag !== 'api' && substr($lastTag, 0, 4) !== 'api-' ) { $error = 'The @api tags must be the last tags in a function comment'; $this->currentFile->addError($error, $commentEnd, 'ApiNotLast'); }
// Check API tag indenting. foreach ($unknownTags as $errorTag) { if ($errorTag['tag'] === 'api' || substr($errorTag['tag'], 0, 4) === 'api-' ) { $expected = ($apiLength - strlen($errorTag['tag']) + 1); $found = strlen($words[($errorTag['pos'] + 1)]); if ($found !== $expected) { $error = '@%s tag indented incorrectly; expected %s spaces but found %s'; $data = array( $errorTag['tag'], $expected, $found, ); $this->currentFile->addError($error, ($commentStart + $errorTag['line']), 'ApiTagIndent', $data); } } } }//end if
}//end processUnknownTags()
}//end class
?>
|