Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: natmchugh/PHP54Compatibility
base: 7a192cbb4a
...
head fork: natmchugh/PHP54Compatibility
compare: 587f00e0ec
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 11, 2012
Nathaniel McHugh new reserved word sniff and test 9802fdd
Nathaniel McHugh add comments 587f00e
View
67 src/PHP/CodeSniffer/Standards/PHP54Compatibility/Sniffs/PHP/NewReservedWordsSniff.php
@@ -0,0 +1,67 @@
+<?php
+/**
+ * PHP54Compatibility_Sniffs_PHP_ForbiddenParameterNameSniff.
+ *
+ * PHP version 5.4
+ *
+ * @category PHP
+ * @package PHP54Compatibility
+ * @author Nathaniel McHugh <nat@fishtrap.co.uk>
+ * @copyright 2012 Nathaniel McHugh
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @link https://github.com/proofek/PHP54Compatibility
+ */
+
+/**
+ * PHP54Compatibility_Sniffs_PHP_ForbiddenParameterNamesSniff.
+ *
+ * Prohibits the use of particular parameter names.
+ *
+ * @category PHP
+ * @package PHP54Compatibility
+ * @author Nathaniel McHugh <nat@fishtrap.co.uk>
+ * @copyright 2012 Nathaniel McHugh
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @link https://github.com/proofek/PHP54Compatibility
+ */
+class PHP54Compatibility_Sniffs_PHP_NewReservedWordsSniff implements PHP_CodeSniffer_Sniff
+{
+
+ /**
+ * A list of new reserved words.
+ *
+ * @var array(string)
+ */
+ public $newReservedWords = array(
+ 'trait',
+ 'insteadof',
+ 'callable'
+ );
+ /**
+ * Returns an array of tokens this test wants to listen for.
+ *
+ * @return array
+ */
+ public function register()
+ {
+ return array(T_FUNCTION, T_CLASS, T_INTERFACE, T_NAMESPACE);
+ }
+
+ /**
+ * 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)
+ {
+ $name = strtolower($phpcsFile->getDeclarationName($stackPtr));
+ if (in_array($name, $this->newReservedWords) === true) {
+ $error = "[PHP 5.4] $name is now a reserved word.";
+ $phpcsFile->addError($error, $stackPtr);
+ }
+ }
+}
View
45 tests/newReservedWords.php
@@ -0,0 +1,45 @@
+<?php
+trait A {
+ public function smallTalk() {
+ echo 'a';
+ }
+ public function bigTalk() {
+ echo 'A';
+ }
+}
+
+trait B {
+ public function smallTalk() {
+ echo 'b';
+ }
+ public function bigTalk() {
+ echo 'B';
+ }
+}
+
+class Talker {
+ use A, B {
+ B::smallTalk insteadof A;
+ A::bigTalk insteadof B;
+ }
+}
+
+class Aliased_Talker {
+ use A, B {
+ B::smallTalk insteadof A;
+ A::bigTalk insteadof B;
+ B::bigTalk as talk;
+ }
+}
+
+interface insteadOf {
+ public function callable();
+}
+
+class trait implements insteadOf {
+
+ function callable() {
+ echo 'called';
+ return true;
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.