Permalink
Browse files

Fixed bug #20307 : PHP_CodeSniffer_Standards_AbstractVariableSniff an…

…alyze traits

Needed to also change a File method that was checking if a member var exists inside a class only.
  • Loading branch information...
1 parent cad80e0 commit 07c51b1c5dcf7feb2a734b9dc8044ca115c7b97e @gsherwood gsherwood committed Jun 24, 2014
View
3 CodeSniffer/File.php
@@ -2375,7 +2375,8 @@ public function getMemberProperties($stackPtr)
$conditions = array_keys($this->_tokens[$stackPtr]['conditions']);
$ptr = array_pop($conditions);
if (isset($this->_tokens[$ptr]) === false
- || $this->_tokens[$ptr]['code'] !== T_CLASS
+ || ($this->_tokens[$ptr]['code'] !== T_CLASS
+ && $this->_tokens[$ptr]['code'] !== T_TRAIT)
) {
if (isset($this->_tokens[$ptr]) === true
&& $this->_tokens[$ptr]['code'] === T_INTERFACE
View
1 CodeSniffer/Standards/AbstractVariableSniff.php
@@ -68,6 +68,7 @@ public function __construct()
{
$scopes = array(
T_CLASS,
+ T_TRAIT,
T_INTERFACE,
);
View
6 CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.inc
@@ -111,3 +111,9 @@ class a
var_dump($http_response_header);
var_dump($HTTP_RAW_POST_DATA);
var_dump($php_errormsg);
+
+trait MyTrait
+{
+ public $_varName = 'hello';
+ private $_varName = 'hello';
+}
View
68 CodeSniffer/Standards/Squiz/Tests/NamingConventions/ValidVariableNameUnitTest.php
@@ -42,35 +42,43 @@ class Squiz_Tests_NamingConventions_ValidVariableNameUnitTest extends AbstractSn
*/
public function getErrorList()
{
- return array(
- 3 => 1,
- 5 => 1,
- 10 => 1,
- 12 => 1,
- 15 => 1,
- 17 => 1,
- 20 => 1,
- 22 => 1,
- 25 => 1,
- 27 => 1,
- 31 => 1,
- 33 => 1,
- 36 => 1,
- 37 => 1,
- 39 => 1,
- 42 => 1,
- 44 => 1,
- 53 => 1,
- 58 => 1,
- 62 => 1,
- 63 => 1,
- 64 => 1,
- 67 => 1,
- 81 => 1,
- 106 => 1,
- 107 => 1,
- 108 => 1,
- );
+ $errors = array(
+ 3 => 1,
+ 5 => 1,
+ 10 => 1,
+ 12 => 1,
+ 15 => 1,
+ 17 => 1,
+ 20 => 1,
+ 22 => 1,
+ 25 => 1,
+ 27 => 1,
+ 31 => 1,
+ 33 => 1,
+ 36 => 1,
+ 37 => 1,
+ 39 => 1,
+ 42 => 1,
+ 44 => 1,
+ 53 => 1,
+ 58 => 1,
+ 62 => 1,
+ 63 => 1,
+ 64 => 1,
+ 67 => 1,
+ 81 => 1,
+ 106 => 1,
+ 107 => 1,
+ 108 => 1,
+ 117 => 1,
+ );
+
+ // The trait test will only work in PHP versions where traits exist.
+ if (version_compare(PHP_VERSION, '5.4.0') < 0) {
+ $errors[118] = 1;
+ }
+
+ return $errors;
}//end getErrorList()
@@ -91,5 +99,3 @@ public function getWarningList()
}//end class
-
-?>
View
1 package.xml
@@ -36,6 +36,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Ole Martin Handeland for the patch
- Fixed bug #20268 : Incorrect documentation titles in PEAR documentation
- Fixed bug #20296 : new array notion in function comma check fails
+ - Fixed bug #20307 : PHP_CodeSniffer_Standards_AbstractVariableSniff analyze traits
- Fixed bug #20309 : Use "member variable" term in sniff "processMemberVar" method
- Fixed bug #20310 : PSR2 does not check for space after function name
</notes>

0 comments on commit 07c51b1

Please sign in to comment.