-
Notifications
You must be signed in to change notification settings - Fork 101
/
ClassCommentSniff.php
126 lines (117 loc) · 3.85 KB
/
ClassCommentSniff.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
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
<?php
/**
* This file is part of the Symfony-coding-standard (phpcs standard)
*
* PHP version 5
*
* @category PHP
* @package Symfony-coding-standard
* @author Authors <Symfony-coding-standard@djoos.github.com>
* @license http://spdx.org/licenses/MIT MIT License
* @link https://github.com/djoos/Symfony-coding-standard
*/
namespace Symfony\Sniffs\Commenting;
use PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\ClassCommentSniff as Sniff;
/**
* Parses and verifies the doc comments for classes.
*
* Verifies that :
* <ul>
* <li>A doc comment exists.</li>
* <li>There is a blank newline after the short description.</li>
* <li>There is a blank newline between the long and short description.</li>
* <li>There is a blank newline between the long description and tags.</li>
* <li>Check the order of the tags.</li>
* <li>Check the indentation of each tag.</li>
* <li>Check required and optional tags and the format of their content.</li>
* </ul>
*
* PHP version 5
*
* @category PHP
* @package Symfony-coding-standard
* @author Authors <Symfony-coding-standard@djoos.github.com>
* @license http://spdx.org/licenses/MIT MIT License
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class ClassCommentSniff extends Sniff
{
/**
* Tags in correct order and related info.
*
* @var array
*/
protected $tags = array(
'category' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'precedes @package',
),
'author' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @subpackage (if used) or @package',
),
'copyright' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @author',
),
'license' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @copyright (if used) or @author',
),
'version' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @license',
),
'link' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @version',
),
'see' => array(
'required' => false,
'allow_multiple' => true,
'order_text' => 'follows @link',
),
'since' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @see (if used) or @link',
),
'deprecated' => array(
'required' => false,
'allow_multiple' => false,
'order_text' => 'follows @since (if used) or @see (if used) or @link',
),
);
protected $blacklist = array(
'@package',
'@subpackage',
);
/**
* Processes each tag and raise an error if there are blacklisted tags.
*
* @param File $phpcsFile The file where the token was found.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
* @param int $commentStart Position in the stack where the comment started.
*
* @return void
*/
protected function processTags($phpcsFile, $stackPtr, $commentStart)
{
$tokens = $phpcsFile->getTokens();
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
$name = $tokens[$tag]['content'];
if (in_array($name, $this->blacklist)) {
$error = sprintf('The %s tag is not allowed.', $name);
$phpcsFile->addError($error, $tag, 'Blacklisted');
}
}
parent::processTags($phpcsFile, $stackPtr, $commentStart);
}
}