~ubuntu-branches/ubuntu/vivid/php-codesniffer/vivid

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.5/CodeSniffer/CommentParser/SingleElement.php

  • Committer: Package Import Robot
  • Author(s): David Prévot, Greg Sherwood, Alexey, Emily, David Prévot
  • Date: 2014-09-26 13:44:35 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140926134435-wvjq16miqq4d60y0
Tags: 1.5.5-1
[ Greg Sherwood ]
* Improved closure support in Generic ScopeIndentSniff
* Improved indented PHP tag support in Generic ScopeIndentSniff
* Standards can now be located within hidden directories
 (further fix for bug #20323)
* Fixed bug #20373 : Inline comment sniff tab handling way
* Fixed bug #20378 : Report appended to existing file if no errors
  found in run
* Fixed bug #20381 : Invalid "Comment closer must be on a new line"
* PHP tokenizer no longer converts class/function names to special
  tokens types
* Fixed bug #20386 : Squiz.Commenting.ClassComment.SpacingBefore
  thrown if first block comment
* Squiz and PEAR FunctionCommentSnif now support _()
* PEAR ValidFunctionNameSniff no longer throws an error for _()
* Fixed bug #248 : FunctionCommentSniff expects ampersand on param name
* Fixed bug #248 in Squiz sniff as well
* Fixed bug #265 : False positives with type hints in ForbiddenFunctionsSniff
* Prepare for 1.5.5 release

[ Alexey ]
* Allowed single undersored methods and functions

[ Emily ]
* Added var_dump to discouraged functions sniff

[ David Prévot ]
* Revert "Add XS-Testsuite still needed for ci.d.n"
* Add self to uploaders
* Bump standards version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * A class to represent single element doc tags.
 
4
 *
 
5
 * PHP version 5
 
6
 *
 
7
 * @category  PHP
 
8
 * @package   PHP_CodeSniffer
 
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
 
10
 * @author    Marc McIntyre <mmcintyre@squiz.net>
 
11
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 
12
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 
13
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
14
 */
 
15
 
 
16
if (class_exists('PHP_CodeSniffer_CommentParser_AbstractDocElement', true) === false) {
 
17
    $error = 'Class PHP_CodeSniffer_CommentParser_AbstractDocElement not found';
 
18
    throw new PHP_CodeSniffer_Exception($error);
 
19
}
 
20
 
 
21
/**
 
22
 * A class to represent single element doc tags.
 
23
 *
 
24
 * A single element doc tag contains only one value after the tag itself. An
 
25
 * example would be the \@package tag.
 
26
 *
 
27
 * @category  PHP
 
28
 * @package   PHP_CodeSniffer
 
29
 * @author    Greg Sherwood <gsherwood@squiz.net>
 
30
 * @author    Marc McIntyre <mmcintyre@squiz.net>
 
31
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 
32
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 
33
 * @version   Release: 1.5.5
 
34
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
35
 */
 
36
class PHP_CodeSniffer_CommentParser_SingleElement extends PHP_CodeSniffer_CommentParser_AbstractDocElement
 
37
{
 
38
 
 
39
    /**
 
40
     * The content that exists after the tag.
 
41
     *
 
42
     * @var string
 
43
     * @see getContent()
 
44
     */
 
45
    protected $content = '';
 
46
 
 
47
    /**
 
48
     * The whitespace that exists before the content.
 
49
     *
 
50
     * @var string
 
51
     * @see getWhitespaceBeforeContent()
 
52
     */
 
53
    protected $contentWhitespace = '';
 
54
 
 
55
 
 
56
    /**
 
57
     * Constructs a SingleElement doc tag.
 
58
     *
 
59
     * @param PHP_CodeSniffer_CommentParser_DocElement $previousElement The element
 
60
     *                                                                  before this
 
61
     *                                                                  one.
 
62
     * @param array                                    $tokens          The tokens
 
63
     *                                                                  that comprise
 
64
     *                                                                  this element.
 
65
     * @param string                                   $tag             The tag that
 
66
     *                                                                  this element
 
67
     *                                                                  represents.
 
68
     * @param PHP_CodeSniffer_File                     $phpcsFile       The file that
 
69
     *                                                                  this element
 
70
     *                                                                  is in.
 
71
     */
 
72
    public function __construct(
 
73
        $previousElement,
 
74
        $tokens,
 
75
        $tag,
 
76
        PHP_CodeSniffer_File $phpcsFile
 
77
    ) {
 
78
        parent::__construct($previousElement, $tokens, $tag, $phpcsFile);
 
79
 
 
80
    }//end __construct()
 
81
 
 
82
 
 
83
    /**
 
84
     * Returns the element names that this tag is comprised of, in the order
 
85
     * that they appear in the tag.
 
86
     *
 
87
     * @return string[]
 
88
     * @see processSubElement()
 
89
     */
 
90
    protected function getSubElements()
 
91
    {
 
92
        return array('content');
 
93
 
 
94
    }//end getSubElements()
 
95
 
 
96
 
 
97
    /**
 
98
     * Processes the sub element with the specified name.
 
99
     *
 
100
     * @param string $name             The name of the sub element to process.
 
101
     * @param string $content          The content of this sub element.
 
102
     * @param string $whitespaceBefore The whitespace that exists before the
 
103
     *                                 sub element.
 
104
     *
 
105
     * @return void
 
106
     * @see getSubElements()
 
107
     */
 
108
    protected function processSubElement($name, $content, $whitespaceBefore)
 
109
    {
 
110
        $this->content           = $content;
 
111
        $this->contentWhitespace = $whitespaceBefore;
 
112
 
 
113
    }//end processSubElement()
 
114
 
 
115
 
 
116
    /**
 
117
     * Returns the content of this tag.
 
118
     *
 
119
     * @return string
 
120
     */
 
121
    public function getContent()
 
122
    {
 
123
        return $this->content;
 
124
 
 
125
    }//end getContent()
 
126
 
 
127
 
 
128
    /**
 
129
     * Returns the whitespace before the content of this tag.
 
130
     *
 
131
     * @return string
 
132
     */
 
133
    public function getWhitespaceBeforeContent()
 
134
    {
 
135
        return $this->contentWhitespace;
 
136
 
 
137
    }//end getWhitespaceBeforeContent()
 
138
 
 
139
 
 
140
    /**
 
141
     * Processes a content check for single doc element.
 
142
     *
 
143
     * @param PHP_CodeSniffer_File $phpcsFile    The file being scanned.
 
144
     * @param int                  $commentStart The line number where
 
145
     *                                           the error occurs.
 
146
     * @param string               $docBlock     Whether this is a file or
 
147
     *                                           class comment doc.
 
148
     *
 
149
     * @return void
 
150
     */
 
151
    public function process(
 
152
        PHP_CodeSniffer_File $phpcsFile,
 
153
        $commentStart,
 
154
        $docBlock
 
155
    ) {
 
156
        if ($this->content === '') {
 
157
            $errorPos = ($commentStart + $this->getLine());
 
158
            $error    = 'Content missing for %s tag in %s comment';
 
159
            $data     = array(
 
160
                         $this->tag,
 
161
                         $docBlock,
 
162
                        );
 
163
            $phpcsFile->addError($error, $errorPos, 'EmptyTagContent', $data);
 
164
        }
 
165
 
 
166
    }//end process()
 
167
 
 
168
 
 
169
}//end class
 
170
 
 
171
?>