~ubuntu-branches/ubuntu/wily/php-codesniffer/wily

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.0RC2/CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-07-21 14:42:41 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140721144241-g4orlcuk4jzn9mhs
Tags: 1.5.3-1
* Team upload
* Focus on stable release
* Update copyright
* Bump standards version to 3.9.5
* Update Homepage
* Use ${phppear:…} instead of hardcoding them
* Run tests in dh_auto_test
* Update patch with gbp pq
* Simplify configuration installation
* Edit package.xml to move script
* Add DEP-8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Squiz_Sniffs_Strings_EchoedStringsSniff.
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-2012 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
 
/**
17
 
 * Squiz_Sniffs_Strings_EchoedStringsSniff.
18
 
 *
19
 
 * Makes sure that any strings that are "echoed" are not enclosed in brackets
20
 
 * like a function call.
21
 
 *
22
 
 * @category  PHP
23
 
 * @package   PHP_CodeSniffer
24
 
 * @author    Greg Sherwood <gsherwood@squiz.net>
25
 
 * @author    Marc McIntyre <mmcintyre@squiz.net>
26
 
 * @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
27
 
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
28
 
 * @version   Release: 1.5.0RC2
29
 
 * @link      http://pear.php.net/package/PHP_CodeSniffer
30
 
 */
31
 
class Squiz_Sniffs_Strings_EchoedStringsSniff implements PHP_CodeSniffer_Sniff
32
 
{
33
 
 
34
 
 
35
 
    /**
36
 
     * Returns an array of tokens this test wants to listen for.
37
 
     *
38
 
     * @return array
39
 
     */
40
 
    public function register()
41
 
    {
42
 
        return array(T_ECHO);
43
 
 
44
 
    }//end register()
45
 
 
46
 
 
47
 
    /**
48
 
     * Processes this test, when one of its tokens is encountered.
49
 
     *
50
 
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
 
     * @param int                  $stackPtr  The position of the current token in the
52
 
     *                                        stack passed in $tokens.
53
 
     *
54
 
     * @return void
55
 
     */
56
 
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
57
 
    {
58
 
        $tokens = $phpcsFile->getTokens();
59
 
 
60
 
        $firstContent = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true);
61
 
        // If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
62
 
        if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) {
63
 
            return;
64
 
        }
65
 
 
66
 
        $endOfStatement = $phpcsFile->findNext(array(T_SEMICOLON), $stackPtr, null, false);
67
 
 
68
 
        // If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
69
 
        if ($tokens[($endOfStatement - 1)]['code'] !== T_CLOSE_PARENTHESIS) {
70
 
            return;
71
 
        }
72
 
 
73
 
        if (($phpcsFile->findNext(PHP_CodeSniffer_Tokens::$operators, $stackPtr, $endOfStatement, false)) === false) {
74
 
            // There are no arithmetic operators in this.
75
 
            $error = 'Echoed strings should not be bracketed';
76
 
            $phpcsFile->addError($error, $stackPtr, 'HasBracket');
77
 
        }
78
 
 
79
 
    }//end process()
80
 
 
81
 
 
82
 
}//end class
83
 
 
84
 
?>