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

Bug #19956 phpcs warns for Type Hint missing Resource
Submitted: 2013-05-25 02:09 UTC
From: stevetauber Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.4.5)
PHP Version: 5.3.25 OS: Mac OS X
Roadmaps: (Not assigned)    
Subscription  


 [2013-05-25 02:09 UTC] stevetauber (Steve Tauber)
Description: ------------ See: https://github.com/squizlabs/PHP_CodeSniffer/blob/b63ca2ea9b4 48d26269ab3e8b554cd7a9276d06f/CodeSniffer/Standards/Squiz/ Sniffs/Commenting/FunctionCommentSniff.php#L655 If a type is not array or of these allowedTypes https://github.com/squizlabs/PHP_CodeSniffer/blob/b63ca2ea9b4 48d26269ab3e8b554cd7a9276d06f/CodeSniffer.php#L163 then type hint will kick in. Resource isn't a valid type hint. Test script: --------------- Attached. Run `phpcs --standard=Squiz Test.php` Expected result: ---------------- $ phpcs --standard=Squiz Test.php FILE: ~/Desktop/untitled1/Test.php --------------------------------------------------------------------------- ----- FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 2 LINE(S) --------------------------------------------------------------------------- ----- 1 | ERROR | Class found in ".php" file; use ".inc" extension instead 44 | WARNING | Line exceeds 85 characters; contains 211 characters --------------------------------------------------------------------------- ----- Time: 0 seconds, Memory: 9.00Mb Actual result: -------------- $ phpcs --standard=Squiz Test.php FILE: ~/Desktop/untitled1/Test.php --------------------------------------------------------------------------- ----- FOUND 2 ERROR(S) AND 1 WARNING(S) AFFECTING 3 LINE(S) --------------------------------------------------------------------------- ----- 1 | ERROR | Class found in ".php" file; use ".inc" extension instead 35 | ERROR | Type hint "resource" missing for $image at position 1 44 | WARNING | Line exceeds 85 characters; contains 211 characters --------------------------------------------------------------------------- ----- Time: 0 seconds, Memory: 9.00Mb

Comments

 [2013-05-25 02:13 UTC] stevetauber (Steve Tauber)
I couldn't figure out how to upload the Test.php file. Here it is: <?php /** * Demo file for PHPCS Bug. * * PHP Version 5 * * @package Something * @subpackage SubSomething * @author Squiz Pty Ltd <products@squiz.net> * @copyright 2006-2012 Squiz Pty Ltd (ACN 084 670 600) * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GPLv2 */ /** * Class resourceBug. */ class Test { /** * Image. * * @var resource */ public $image; /** * Set Image. * * @param resource $image Image resource. * * @return void */ public function setImage($image) { $this->image = $image; }//end setImage() }//end class $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABlBMVEUAAAD///+l2 Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDrEX4IJTRkb7lobNUStXsB0jIXIAMSsQnWls V+wULF4Avk9fLq2r8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='; $data = base64_decode($data); $data = imagecreatefromstring($data); $z = new ResourceBug(); $z->setImage($data);
 [2013-06-03 05:46 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
Fix committed to github repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/ba8e2abc30be01699e2dc4dbcd 8f9498ebcef9dd Adding resource to the allowedTypes array doesn't seem to break anything, and makes sense anyway. Also fixes this problem.