Skip to content
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

Add 'clone' and 'echo' to the list of known PHP statements to avoid the use of parenthesis. #63

Merged
merged 1 commit into from Mar 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
146 changes: 0 additions & 146 deletions Sniffs/Files/IncludingFileSniff.php

This file was deleted.

57 changes: 57 additions & 0 deletions Sniffs/Functions/StatementNotFunctionSniff.php
@@ -0,0 +1,57 @@
<?php
/**
* Joomla_Sniffs_Functions_StatementNotFunctionSniff.
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* Joomla_Sniffs_Functions_StatementNotFunctionSniff.
*
* Checks that language statements do no use brackets.
*
* @since 1.1
*/
class Joomla_Sniffs_Functions_StatementNotFunctionSniff implements PHP_CodeSniffer_Sniff
{
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(
T_INCLUDE_ONCE,
T_REQUIRE_ONCE,
T_REQUIRE,
T_INCLUDE,
T_CLONE,
T_ECHO
);
}

/**
* 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();

$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);

if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS)
{
$error = '"%s" is a statement not a function; no parentheses are required';
$data = array($tokens[$stackPtr]['content']);
$phpcsFile->addError($error, $stackPtr, 'BracketsNotRequired', $data);
}
}
}