Skip to content

Issue 12 update php codesniffer #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_Array_ArraySniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\Arrays;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

class ArraySniff implements Sniff
{


Expand All @@ -45,11 +52,11 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$lastItem = $phpcsFile->findPrevious(
PHP_CodeSniffer_Tokens::$emptyTokens,
Tokens::$emptyTokens,
($tokens[$stackPtr]['parenthesis_closer'] - 1),
$stackPtr,
true
Expand All @@ -67,12 +74,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
if ($tokens[$lastItem]['code'] !== T_COMMA && $isInlineArray === false
&& $tokens[($lastItem + 1)]['code'] !== T_CLOSE_PARENTHESIS
) {
$phpcsFile->addWarning('A comma should follow the last multiline array item. Found: '.$tokens[$lastItem]['content'], $lastItem);

$phpcsFile->addWarning('A comma should follow the last multiline array item. Found: '.$tokens[$lastItem]['content'], $lastItem, 'MissingComma');
return;
}

if ($tokens[$lastItem]['code'] === T_COMMA && $isInlineArray === true) {
$phpcsFile->addWarning('Last item of an inline array must not be followed by a comma', $lastItem);
$phpcsFile->addWarning('Last item of an inline array must not be followed by a comma', $lastItem, 'ExtraComma');
}

if ($isInlineArray === true) {
Expand All @@ -84,7 +92,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$comma2 = $phpcsFile->findNext(T_COMMA, ($comma1 + 1), $tokens[$stackPtr]['parenthesis_closer']);
if ($comma2 !== false) {
$error = 'If the line declaring an array spans longer than 80 characters, each element should be broken into its own line';
$phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration');
$phpcsFile->addError($error, $stackPtr, 'LongLineDeclaration', 'ArrayTooLong');
}
}
}
Expand Down Expand Up @@ -132,7 +140,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$newLineStart = $lineStart;
while ($tokens[$newLineStart]['line'] == $tokens[$lineStart]['line']) {
$newLineStart = $phpcsFile->findNext(
PHP_CodeSniffer_Tokens::$emptyTokens,
Tokens::$emptyTokens,
($newLineStart + 1),
($tokens[$stackPtr]['parenthesis_closer'] + 1),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_CSS_ClassDefinitionClosingBraceSpaceSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\CSS;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

class ClassDefinitionClosingBraceSpaceSniff implements Sniff
{

/**
Expand Down Expand Up @@ -50,7 +57,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand All @@ -61,7 +68,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}

$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($prev !== false && $tokens[$prev]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
$error = 'Expected exactly one new line before closing brace of class definition';
$phpcsFile->addError($error, $stackPtr, 'SpacingBeforeClose');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_CSS_ClassDefinitionNameSpacingSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\CSS;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class ClassDefinitionNameSpacingSniff implements Sniff
{

/**
Expand Down Expand Up @@ -50,7 +56,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_CSS_ClassDefinitionOpeningBraceSpaceSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\CSS;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class ClassDefinitionOpeningBraceSpaceSniff implements Sniff
{

/**
Expand Down Expand Up @@ -50,7 +56,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand Down
10 changes: 8 additions & 2 deletions coder_sniffer/Backdrop/Sniffs/CSS/ColourDefinitionSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_CSS_ColourDefinitionSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\CSS;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class ColourDefinitionSniff implements Sniff
{

/**
Expand Down Expand Up @@ -50,7 +56,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$colour = $tokens[$stackPtr]['content'];
Expand Down
9 changes: 7 additions & 2 deletions coder_sniffer/Backdrop/Sniffs/CSS/IndentationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_CSS_IndentationSniff implements PHP_CodeSniffer_Sniff
namespace Backdrop\Sniffs\CSS;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class IndentationSniff implements Sniff
{

/**
Expand Down Expand Up @@ -56,7 +61,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

Expand Down
14 changes: 10 additions & 4 deletions coder_sniffer/Backdrop/Sniffs/Classes/ClassCreateInstanceSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
* @author Peter Philipp <[email protected]>
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_Classes_ClassCreateInstanceSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\Classes;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class ClassCreateInstanceSniff implements Sniff
{


Expand All @@ -47,20 +53,20 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

$nextParenthesis = $phpcsFile->findNext(array(T_OPEN_PARENTHESIS,T_SEMICOLON), $stackPtr, null, false, null, true);
if ($tokens[$nextParenthesis]['code'] != T_OPEN_PARENTHESIS || $tokens[$nextParenthesis]['line'] != $tokens[$stackPtr]['line']) {
$error = 'Calling class constructors must always include parentheses';
$phpcsFile->addError($error, $nextParenthesis);
$phpcsFile->addError($error, $nextParenthesis, 'ClassConstructor');
return;
}

if ($tokens[$nextParenthesis-1]['code'] == T_WHITESPACE) {
$error = 'Between the class name and the opening parenthesis spaces are not welcome';
$phpcsFile->addError($error, $nextParenthesis-1);
$phpcsFile->addError($error, $nextParenthesis-1, 'SpaceAfterClassName');
return;
}
}//end process()
Expand Down
18 changes: 12 additions & 6 deletions coder_sniffer/Backdrop/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
* @version Release: 1.2.0RC3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_Classes_ClassDeclarationSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\Classes;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class ClassDeclarationSniff implements Sniff
{


Expand Down Expand Up @@ -55,15 +61,15 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

if (isset($tokens[$stackPtr]['scope_opener']) === false) {
$error = 'Possible parse error: ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' missing opening or closing brace';
$phpcsFile->addWarning($error, $stackPtr);
$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace');
return;
}

Expand All @@ -75,7 +81,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$error = 'Opening brace of a ';
$error .= $tokens[$stackPtr]['content'];
$error .= ' must be on the same line as the definition';
$phpcsFile->addError($error, $curlyBrace);
$phpcsFile->addError($error, $curlyBrace, 'OpeningBrace');
return;
} /* else if ($braceLine > ($classLine + 1)) {
$difference = ($braceLine - $classLine - 1);
Expand All @@ -92,7 +98,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar && $tokens[($curlyBrace + 1)]['code'] !== T_CLOSE_CURLY_BRACKET) {
$type = strtolower($tokens[$stackPtr]['content']);
$error = "Opening $type brace must be on a line by itself";
$phpcsFile->addError($error, $curlyBrace);
$phpcsFile->addError($error, $curlyBrace, 'OpeningBrace');
}

if ($tokens[($curlyBrace - 1)]['code'] != T_WHITESPACE) {
Expand All @@ -102,7 +108,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$spaces = strlen($blankSpace);
if ($spaces !== 0) {
$error = "Expected 1 space before opening brace; $spaces found";
$phpcsFile->addError($error, $curlyBrace);
$phpcsFile->addError($error, $curlyBrace, 'OpeningBrace');
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions coder_sniffer/Backdrop/Sniffs/Classes/InterfaceNameSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_Classes_InterfaceNameSniff implements PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\Classes;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

class InterfaceNameSniff implements Sniff
{


Expand All @@ -41,7 +47,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$namePtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
* @package PHP_CodeSniffer
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class Backdrop_Sniffs_Commenting_DocCommentAlignmentSniff implements
PHP_CodeSniffer_Sniff

namespace Backdrop\Sniffs\Commenting;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Tokens;

class Backdrop_Sniffs_Commenting_DocCommentAlignmentSniff implements Sniff
{


Expand All @@ -45,12 +51,12 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();

// We are only interested in function/class/interface doc block comments.
$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
$nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
$ignore = array(
T_CLASS,
T_INTERFACE,
Expand All @@ -64,7 +70,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

if (in_array($tokens[$nextToken]['code'], $ignore) === false) {
// Could be a file comment.
$prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) {
return;
}
Expand Down
17 changes: 12 additions & 5 deletions coder_sniffer/Backdrop/Sniffs/Commenting/FileCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found');
}

/**
* Parses and verifies the doc comments for files.
Expand All @@ -27,7 +24,17 @@
* @link http://pear.php.net/package/PHP_CodeSniffer
*/

class Backdrop_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff
namespace Backdrop\Sniffs\Commenting;

use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
//use PHP_CodeSniffer\Exceptions\RuntimeException

//if (class_exists('PHP_CodeSniffer_CommentParser_ClassCommentParser', true) === false) {
// throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_CommentParser_ClassCommentParser not found');
//}

class Backdrop_Sniffs_Commenting_FileCommentSniff implements Sniff
{


Expand All @@ -52,7 +59,7 @@ public function register()
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr)
{
// We are only interested if this is the first open tag.
if ($stackPtr !== 0) {
Expand Down
Loading