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

Bug #20137 Overriding method to change visibility classified as Useless method overriding
Submitted: 2013-11-28 22:36 UTC
From: siebrand Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version Unknown)
PHP Version: 5.4.22 OS: Linux
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 : 39 + 17 = ?

 
 [2013-11-28 22:36 UTC] siebrand (Siebrand Mazeland)
Description: ------------ In for example https://gerrit.wikimedia.org/r/#/c/96456/2/includes/db/ORMTable.php, protected DBAccessBase::releaseConnection is overridden as public ORMTable::releaseConnection. Running CodeSniffer on this, leads to a "useless method overriding" warning. However, the visibility is intentional and valid, so CodeSniffer should not warn. Test script: --------------- <?php class DBAccessBase { protected function releaseConnection( DatabaseBase $db ) { } } class ORMTable extends DBAccessBase { public function releaseConnection( DatabaseBase $db ) { parent::releaseConnection( $db ); // just make it public } } Expected result: ---------------- No warning. Actual result: -------------- -------------------------------------------------------------------------------- FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 9 | WARNING | Useless method overriding detected | | (Generic.CodeAnalysis.UselessOverridingMethod.Found) --------------------------------------------------------------------------------

Comments

 [2013-11-28 22:37 UTC] siebrand (Siebrand Mazeland)
 [2013-11-29 09:56 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
There is nothing this sniff can do about this case because it doesn't keep track of usage throughout the project. It's one of those cases where you'd need a more intensive search, and probably a dedicated tool, to find it properly. Otherwise this sniff would need to search your entire code base to work properly, forcing you to run over the whole thing even if you just want to check a single file or directory. If you're finding that specific sniff useful in other cases, then keep using it. But if you get a lot of false positives, you may want to just consider removing it from your standard. The alternative is to use a comment to suppress the error: class ORMTable extends DBAccessBase { // @codingStandardsIgnoreStart public function releaseConnection( DatabaseBase $db ) { parent::releaseConnection( $db ); // just make it public } // @codingStandardsIgnoreEnd } I'm not personally a big fan of doing this, but it might work for you.
 [2014-01-22 09:40 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Closed