~ubuntu-branches/ubuntu/saucy/php-codesniffer/saucy

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.1.0/CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/ScopeIndentSniff.php

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2012-05-31 16:37:24 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120531163724-u6aiaubu8ks5dh5z
Tags: 1.3.4-0.1
* Non-maintainer upload.
* New upstream release (Closes: #599617, #634825).
* Swtiched debian/copyright to format 1.0 (rewrite was needed anyway, as the
upstream license changed).
* Switched package to pkg-php-tools and debhelper 8 sequencer.
* Now running unit tests at build time (so depends on phpunit (>= 3.6)).
* Section is now PHP.
* Added missing Build-Depends-Indep: php-pear.
* Added missing ${misc:Depends}.
* Added Vcs fields.
* Added homepage field.
* Reviewed short and long description.
* Added dependency on php-timer.
* Standards-Version: is now 3.9.3 (lots of changes, see above...).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Squiz_Sniffs_Whitespace_ScopeIndentSniff.
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 Squiz Pty Ltd (ABN 77 084 670 600)
12
 
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
13
 
 * @version   CVS: $Id: ScopeIndentSniff.php,v 1.7 2008/03/03 03:28:15 squiz Exp $
14
 
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 
 */
16
 
 
17
 
if (class_exists('Generic_Sniffs_WhiteSpace_ScopeIndentSniff', true) === false) {
18
 
    throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_WhiteSpace_ScopeIndentSniff not found');
19
 
}
20
 
 
21
 
/**
22
 
 * Squiz_Sniffs_Whitespace_ScopeIndentSniff.
23
 
 *
24
 
 * Checks that control structures are structured correctly, and their content
25
 
 * is indented correctly.
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 Squiz Pty Ltd (ABN 77 084 670 600)
32
 
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
33
 
 * @version   Release: 1.1.0
34
 
 * @link      http://pear.php.net/package/PHP_CodeSniffer
35
 
 */
36
 
class Squiz_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
37
 
{
38
 
 
39
 
 
40
 
    /**
41
 
     * Calculates the expected indent of a token.
42
 
     *
43
 
     * Looks for ob_start() calls because those act as scope openers in the
44
 
     * Squiz coding standard, and so require additional indentation.
45
 
     *
46
 
     * @param array $tokens   The stack of tokens for this file.
47
 
     * @param int   $stackPtr The position of the token to get indent for.
48
 
     *
49
 
     * @return int
50
 
     */
51
 
    protected function calculateExpectedIndent(array $tokens, $stackPtr)
52
 
    {
53
 
        $expectedIndent = parent::calculateExpectedIndent($tokens, $stackPtr);
54
 
 
55
 
        // If we are in a function, check all tokens to the start of the
56
 
        // function. If we are not in a function, check all tokens to the
57
 
        // start of the file.
58
 
        $checkTo = 0;
59
 
 
60
 
        $tokenConditions = $tokens[$stackPtr]['conditions'];
61
 
        foreach ($tokenConditions as $id => $condition) {
62
 
            if ($condition === T_FUNCTION) {
63
 
                $checkTo = ($tokens[$id]['scope_opener'] + 1);
64
 
            }
65
 
        }
66
 
 
67
 
        for ($i = ($stackPtr - 1); $i >= $checkTo; $i--) {
68
 
            if ($tokens[$i]['code'] !== T_STRING) {
69
 
                continue;
70
 
            }
71
 
 
72
 
            if ($tokens[$i]['content'] === 'ob_start') {
73
 
                $expectedIndent += $this->indent;
74
 
            }
75
 
 
76
 
            $bufferClosers = array(
77
 
                              'ob_end_clean',
78
 
                              'ob_end_flush',
79
 
                              'ob_get_clean',
80
 
                              'ob_get_flush',
81
 
                             );
82
 
 
83
 
            if (in_array($tokens[$i]['content'], $bufferClosers) === true) {
84
 
                $expectedIndent -= $this->indent;
85
 
            }
86
 
        }//end for
87
 
 
88
 
        return $expectedIndent;
89
 
 
90
 
    }//end calculateExpectedIndent()
91
 
 
92
 
 
93
 
}//end class
94
 
 
95
 
?>