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

HTTP_*_VARS are now removed in PHP 5.4 #4

Closed
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Installation
* Install PHP54Compatibility with `pear install proofek/PHP54Compatibility` (requires PHP_CodeSniffer 1.3+)
* Use the coding standard with `phpcs --standard=PHP54Compatibility`.

Sniffs
Sniffs
------

* Prohibits the use of break/continue $var syntax (PHP54Compatibility_Sniffs_PHP_BreakContinueVarSyntaxSniff)
Expand Down Expand Up @@ -60,6 +60,7 @@ Sniffs
* hash_init('salsa20')
* hash_file('salsa10')
* hash_file('salsa20')
* Usage of long arrays is now forbidden (PHP54Compatibility_Sniffs_PHP_DeprecatedLongArraysSniff)

Build package
-------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* PHP54Compatibility_Sniffs_PHP_DeprecatedLongArraysSniff.
*
* PHP version 5.4
*
* @category PHP
* @package PHP53Compatibility
* @author Ben Selby <bselby@plus.net>
* @copyright 2012 Ben Selby
*/

/**
* PHP54Compatibility_Sniffs_PHP_DeprecatedLongArraysSniff.
*
* Marks the use of HTTP_*_VARS as removed, and therefore throws an error
*
* PHP version 5.4
*
* @category PHP
* @package PHP53Compatibility
* @author Ben Selby <bselby@plus.net>
* @copyright 2012 Ben Selby
*/
class PHP54Compatibility_Sniffs_PHP_DeprecatedLongArraysSniff implements PHP_CodeSniffer_Sniff
{
/**
* Array of HTTP_*_VARS that are now deprecated
*
* @var array
*/
protected $deprecated = array(
'HTTP_POST_VARS',
'HTTP_GET_VARS',
'HTTP_ENV_VARS',
'HTTP_SERVER_VARS',
'HTTP_COOKIE_VARS',
'HTTP_SESSION_VARS',
'HTTP_POST_FILES'
);

/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register()
{
return array(T_VARIABLE);
}

/**
* 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 ($tokens[$stackPtr]['type'] == 'T_VARIABLE' && in_array(substr($tokens[$stackPtr]['content'], 1), $this->deprecated)) {
$error = '[PHP 5.4] The use of long predefined variables (' . implode($this->deprecated, ', ') . ') has now been removed';
$phpcsFile->addError($error, $stackPtr);
}
}
}