Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #19469 PHP_CodeSniffer_File::getMemberProperties() sets wrong scope
Submitted: 2012-06-10 21:01 UTC
From: juanmf Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.4)
PHP Version: 5.3.8 OS: windows 7
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 26 + 34 = ?

 
 [2012-06-10 21:01 UTC] juanmf (Juan Fernandez)
Description: ------------ Hi, I'm using PHPCS 1.3.3 sicne 1.3.4 has lots of bugs with Windows paths when sniff are specified with this notation "PEAR.Commenting.FileComment". The problem is that PHP_CodeSniffer_File::getMemberProperties() says that $_key is public in code like the following (see Test script). Therefore the ValidVariableName sniff complains about the leading underscore. Thanks! Test script: --------------- class a { protected $_sheet, $_FieldParser, $_key; } Expected result: ---------------- $_key should pass since its protected. Actual result: -------------- $_key fires this: Public member variable "_key" must not contain a leading underscore.

Comments

 [2012-06-19 11:50 UTC] squiz (Greg Sherwood)
-Assigned To: +Assigned To: squiz
Firstly, this has nothing to do with Windows, so I'm not sure why you have mentioned the file comment sniff on windows. I'm ignoring that bit for now. Secondly, only private members can have a leading underscore in you are using the PEAR or Squiz standards (you don't say which specific sniff you are using) so you will have to remove the underscore from those protected vars if you want the sniff to pass. I will have a look into why the core is not getting the correct visibility, but it was certainly not written with the syntax you are using in mind. You'll need to split those member vars into separate lines if you want to conform with commenting standards. But PHPCS should parse it correctly regardless, so I will get it fixed.
 [2012-06-19 12:06 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
Fix committed to Github repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/669d7ef76b6c715819a974bb1 cfd651fe78b3637
 [2012-06-19 12:10 UTC] juanmf (Juan Fernandez)
Hi Squiz, I see you fixed it really fast, I had it already fixed in my local copy. But I added more tokens to the array (since variables can be asigned some values, in which case the loop wont get to the visibility keyword): $valid = array( T_PUBLIC, T_PRIVATE, T_PROTECTED, T_STATIC, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, /* BEGGINS MY ADDITION to overcome protected $a, $b;*/ T_COMMA, T_DOUBLE_ARROW, T_OPEN_PARENTHESIS, T_CLOSE_PARENTHESIS, T_ARRAY, T_VARIABLE, T_EQUAL, T_STRING, T_LNUMBER, T_SEMICOLON, T_CONSTANT_ENCAPSED_STRING, /* ENDS MY ADDITION to overcome protected $a, $b;*/ ); Thanks, Cheers!
 [2012-06-19 12:19 UTC] juanmf (Juan Fernandez)
Made a mistake, This T_SEMICOLON should not be there in $valid. Sorry. Thanks.