Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

HTTP_*_VARS are now removed in PHP 5.4 #4

Closed
wants to merge 1 commit into from
This page is out of date. Refresh to see the latest.
3  README.markdown
View
@@ -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)
@@ -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
-------------
70 src/PHP/CodeSniffer/Standards/PHP54Compatibility/Sniffs/PHP/DeprecatedLongArraysSniff.php
View
@@ -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);
+ }
+ }
+}
Something went wrong with that request. Please try again.