3
* Squiz_Sniffs_Whitespace_ScopeIndentSniff.
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
17
if (class_exists('Generic_Sniffs_WhiteSpace_ScopeIndentSniff', true) === false) {
18
throw new PHP_CodeSniffer_Exception('Class Generic_Sniffs_WhiteSpace_ScopeIndentSniff not found');
22
* Squiz_Sniffs_Whitespace_ScopeIndentSniff.
24
* Checks that control structures are structured correctly, and their content
25
* is indented correctly.
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
36
class Squiz_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
41
* Calculates the expected indent of a token.
43
* Looks for ob_start() calls because those act as scope openers in the
44
* Squiz coding standard, and so require additional indentation.
46
* @param array $tokens The stack of tokens for this file.
47
* @param int $stackPtr The position of the token to get indent for.
51
protected function calculateExpectedIndent(array $tokens, $stackPtr)
53
$expectedIndent = parent::calculateExpectedIndent($tokens, $stackPtr);
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
60
$tokenConditions = $tokens[$stackPtr]['conditions'];
61
foreach ($tokenConditions as $id => $condition) {
62
if ($condition === T_FUNCTION) {
63
$checkTo = ($tokens[$id]['scope_opener'] + 1);
67
for ($i = ($stackPtr - 1); $i >= $checkTo; $i--) {
68
if ($tokens[$i]['code'] !== T_STRING) {
72
if ($tokens[$i]['content'] === 'ob_start') {
73
$expectedIndent += $this->indent;
76
$bufferClosers = array(
83
if (in_array($tokens[$i]['content'], $bufferClosers) === true) {
84
$expectedIndent -= $this->indent;
88
return $expectedIndent;
90
}//end calculateExpectedIndent()