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

Bug #19763 Use statements for traits not recognised correctly for PSR2 code style
Submitted: 2013-01-01 19:12 UTC
From: hinikato Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version SVN)
PHP Version: 5.4.7 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 : 43 - 40 = ?

 
 [2013-01-01 19:12 UTC] hinikato (Hinikato Dubrai)
Description: ------------ The following code is reported as invalid. If I add a one empty line, it detected as invalid also: FILE: x:\path\Component\Container.php -------------------------------------------------------------------------------- FOUND 1 ERROR(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 8 | ERROR | The closing brace for the class must go on the next line after the | | body -------------------------------------------------------------------------------- So it seems like there is a conflict between this two checks also. Test script: --------------- <?php namespace Myak\Component; class Container extends Component implements IContainer { use TContainer; } Expected result: ---------------- File is valid. Actual result: -------------- FILE: x:\path\Component\Container.php -------------------------------------------------------------------------------- FOUND 1 ERROR(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 6 | ERROR | There must be one blank line after the last USE statement; 0 | | found; --------------------------------------------------------------------------------

Comments

 [2013-01-07 02:17 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
Your code contains a parse error. Use statements cannot be included inside class declarations like that. See "Scoping rules for importing" here: http://php.net/manual/en/language.namespaces.importing.php If you put the use statement in the global scope, or inside a namespace block, the checks will work correctly.
 [2013-01-07 03:17 UTC] squiz (Greg Sherwood)
Sorry, my mistake. I was testing on php 5.3 and this has obviously been changed in 5.4 with the introduction of traits, even though the docs have not been. The doc example doesn't actually give a parse error in 5.4, as the manual indicates, as it is now valid syntax for traits.
 [2013-01-07 03:58 UTC] squiz (Greg Sherwood)
-Summary: Traits don't recognized right for PSR2 code style +Summary: Use statements for traits not recognised correctly for PSR2 code style
 [2013-01-07 04:01 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Closed
Fix committed to gthub repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/ab0465ecdf244fd3e9d1224c9f6 0db6a51915833