cvs: pear /PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods OpeningMethodBraceSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Tests/Methods OpeningMethodBraceUnitTest.inc OpeningMethodBraceUnitTest.php

From: Date: Sun, 01 Oct 2006 01:48:52 +0000
Subject: cvs: pear /PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods OpeningMethodBraceSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Tests/Methods OpeningMethodBraceUnitTest.inc OpeningMethodBraceUnitTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-42329@lists.php.net to get a copy of this message
squiz Sun Oct 1 01:48:52 2006 UTC Removed files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Tests/Methods OpeningMethodBraceUnitTest.inc OpeningMethodBraceUnitTest.php Modified files: /pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods OpeningMethodBraceSniff.php Log: Noew using generic sniff http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods/OpeningMethodBraceSniff.php?r1=1.1.1.1&r2=1.2&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods/OpeningMethodBraceSniff.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods/OpeningMethodBraceSniff.php:1.1.1.1 pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods/OpeningMethodBraceSniff.php:1.2 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods/OpeningMethodBraceSniff.php:1.1.1.1 Thu Sep 7 09:58:22 2006 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Methods/OpeningMethodBraceSniff.php Sun Oct 1 01:48:52 2006 @@ -30,7 +30,7 @@ * @author Squiz Pty Ltd */ -require_once 'PHP/CodeSniffer/Sniff.php'; +require_once 'PHP/CodeSniffer/Standards/Generic/Sniffs/Methods/OpeningMethodBraceBsdAllmanSniff.php'; /** @@ -43,90 +43,9 @@ * @category PEAR_Coding_Standards * @author Squiz Pty Ltd */ -class PEAR_Sniffs_Methods_OpeningMethodBraceSniff implements PHP_CodeSniffer_Sniff +class PEAR_Sniffs_Methods_OpeningMethodBraceSniff extends Generic_Sniffs_Methods_OpeningMethodBraceBsdAllmanSniff { - - /** - * Registers the tokens that this sniff wants to listen for. - * - * @return void - */ - public function register() - { - return array(T_FUNCTION); - - }//end register() - - - /** - * Processes this test, when one of its tokens is encountered. - * - * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. - * @param int $stackPtr The position of the current token in the - * stack passed in $tokens. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if (!isset($tokens[$stackPtr]['scope_opener'])) { - return; - } - - $openingBrace = $tokens[$stackPtr]['scope_opener']; - - // The end of the function occurs at the end of the argument list. Its - // like this because some people like to break long function declarations - // over multiple lines. - $functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line']; - $braceLine = $tokens[$openingBrace]['line']; - - $lineDifference = $braceLine - $functionLine; - - if ($lineDifference === 0) { - $error = 'Opening function brace should be on a new line.'; - $phpcsFile->addError($error, $openingBrace); - return; - } - - if ($lineDifference > 1) { - $ender = (($lineDifference - 1) === 1) ? 'line' : 'lines'; - $error = 'Opening function brace should be on the line after the declaration. Found '.($lineDifference - 1).' blank '.$ender.'.'; - $phpcsFile->addError($error, $openingBrace); - return; - } - - // We need to actually find the first piece of content on this line, - // as if this is a method with tokens before it (public, static etc) - // or an if with an else before it, then we need to start the scope - // checking from there, rather than the current token. - $lineStart = $stackPtr; - while (($lineStart = $phpcsFile->findPrevious(array(T_WHITESPACE), ($lineStart - 1), null, false)) !== false) { - if (strpos($tokens[$lineStart]['content'], "\n") !== false) { - break; - } - } - - // We found a new line, now go forward and find the first non-whitespace - // token. - $lineStart = $phpcsFile->findNext(array(T_WHITESPACE), $lineStart, null, true); - - // The opening brace is on the correct line, now it needs to be - // checked to be correctly indented. - $startColumn = $tokens[$lineStart]['column']; - $braceIndent = $tokens[$openingBrace]['column']; - - if ($braceIndent !== $startColumn) { - $error = 'Opening Brace Indented Incorrectly. Expected '.($startColumn - 1).' spaces, but found '.($braceIndent - 1).'.'; - $phpcsFile->addError($error, $openingBrace); - } - - }//end process() - - }//end class ?>

« previous php.pear.cvs (#42329) next »