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

Request #20189 Missing @return tag in function comment
Submitted: 2014-01-29 22:38 UTC
From: azkhem Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.5.1)
PHP Version: 5.5.6 OS: Debian
Roadmaps: (Not assigned)    
Subscription  


 [2014-01-29 22:38 UTC] azkhem (Matthieu GAuthier)
Description: ------------ Hi, According to submitted PSR5, for functions and methods without a return value, the @return tag may be omitted, in which case an interpreter MUST interpret this as if @return void is provided. So, if the lack of "@return void" tag in a docblock should not be considered as a violation. Can you look at this? Thanks, Matthieu. Test script: --------------- <?php class A { /** * Want to do something without return */ public function b() { echo "something"; } } $a = new A(); $a->b(); Expected result: ---------------- FILE: class.php -------------------------------------------------------------------------------- FOUND 2 ERROR(S) AFFECTING 2 LINE(S) -------------------------------------------------------------------------------- 2 | ERROR | Missing file doc comment 3 | ERROR | Missing class doc comment -------------------------------------------------------------------------------- Actual result: -------------- FILE: class.php -------------------------------------------------------------------------------- FOUND 3 ERROR(S) AFFECTING 3 LINE(S) -------------------------------------------------------------------------------- 2 | ERROR | Missing file doc comment 3 | ERROR | Missing class doc comment 7 | ERROR | Missing @return tag in function comment --------------------------------------------------------------------------------

Comments

 [2014-01-30 04:19 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
You're probably using the PEAR coding standard, which explicitly states that a function should use @return void if nothing is returned (http://pear.php.net/manual/en/standards.sample.php) If you instead use the PSR1 (--standard=PSR1) or PSR2 (--standard=PSR2) standards, you'll find they don't care about function comments at all and you can do whatever you like. If PSR-5 is ratified, I will certainly consider including a PSR5 standard in PHP_CodeSniffer so you can use it (e.g., --standard=PSR2,PSR5), but I wont be changing any of the other included standards unless their authors change the written version first. It is important that PHPCS exactly follows the written standards out there, but I don't actually control any of them. The only one I have a say in is the Squiz standard. I hope that explains things.