coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

phpcbf breaks /** @var ... */

Open kenjis opened this issue 4 years ago • 6 comments

--- a/system/BaseModel.php
+++ b/system/BaseModel.php
@@ -299,7 +299,9 @@ abstract class BaseModel
        $this->tempUseSoftDeletes = $this->useSoftDeletes;
        $this->tempAllowCallbacks = $this->allowCallbacks;
 
-       /** @var Validation $validation */
+       /**
+ * @var Validation $validation
+*/
        $validation = $validation ?? Services::validation(null, false);
 
        $this->validation = $validation;

kenjis avatar Mar 02 '21 01:03 kenjis

$ vendor/bin/phpcs --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 --encoding=utf-8 system/BaseModel.php 

FILE: /Users/kenji/work/codeigniter/CodeIgniter4/system/BaseModel.php
---------------------------------------------------------------------------------
FOUND 32 ERRORS AND 3 WARNINGS AFFECTING 31 LINES
---------------------------------------------------------------------------------
   10 | ERROR   | [ ] Missing @package tag in class comment
   10 | ERROR   | [ ] Missing @author tag in class comment
   10 | ERROR   | [ ] Missing @license tag in class comment
   46 | ERROR   | [ ] Missing @package tag in class comment
  302 | ERROR   | [x] The open comment tag must be the only content on the line
  302 | ERROR   | [ ] Missing short description in doc comment
  302 | ERROR   | [x] The close comment tag must be the only content on the line
  327 | ERROR   | [ ] Comment missing for @throws tag in function comment
  371 | WARNING | [ ] Line exceeds 120 characters; contains 133 characters
  395 | ERROR   | [ ] Comment missing for @throws tag in function comment
  397 | WARNING | [ ] Line exceeds 120 characters; contains 134 characters
  408 | ERROR   | [ ] Comment missing for @throws tag in function comment
  478 | ERROR   | [ ] Comment missing for @throws tag in function comment
  534 | ERROR   | [ ] Comment missing for @throws tag in function comment
  644 | ERROR   | [ ] Comment missing for @throws tag in function comment
  701 | ERROR   | [ ] Comment missing for @throws tag in function comment
  775 | ERROR   | [ ] Parameter comment must start with a capital letter
  782 | ERROR   | [ ] Comment missing for @throws tag in function comment
  843 | ERROR   | [ ] Comment missing for @throws tag in function comment
  912 | ERROR   | [ ] Comment missing for @throws tag in function comment
  913 | ERROR   | [ ] Comment missing for @throws tag in function comment
  974 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1166 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1198 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1217 | ERROR   | [ ] Parameter comment must start with a capital letter
 1221 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1246 | ERROR   | [ ] Parameter comment must start with a capital letter
 1465 | ERROR   | [ ] Parameter comment must start with a capital letter
 1496 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1560 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1591 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1627 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1628 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1629 | ERROR   | [ ] Comment missing for @throws tag in function comment
 1635 | WARNING | [ ] Line exceeds 120 characters; contains 122 characters
---------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------

Time: 613ms; Memory: 16MB

kenjis avatar Mar 02 '21 05:03 kenjis

Can you please paste me a simplified example of the original file so I can create a unit test for it?

louisl avatar Mar 05 '21 10:03 louisl

<?php

namespace CodeIgniter;

abstract class Sample
{
	public function test()
	{
		/** @var Validation $validation */
		$validation = Services::validation(null, false);
	}
}

kenjis avatar Mar 05 '21 11:03 kenjis

$ ./vendor/bin/phpcs --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 system/Sample.php 

FILE: /Users/kenji/work/codeigniter/CodeIgniter4/system/Sample.php
----------------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------------
 2 | ERROR | [ ] Missing file doc comment
 5 | ERROR | [ ] Missing class doc comment
 5 | ERROR | [ ] Missing doc comment for class Sample
 7 | ERROR | [ ] Missing doc comment for function test()
 9 | ERROR | [x] The open comment tag must be the only content on the line
 9 | ERROR | [ ] Missing short description in doc comment
 9 | ERROR | [x] The close comment tag must be the only content on the line
----------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------

Time: 196ms; Memory: 10MB

It seems the rules are:

  • Generic.Commenting.DocComment.ContentAfterOpen
  • Generic.Commenting.DocComment.ContentBeforeClose

kenjis avatar Mar 19 '21 00:03 kenjis

Should the comment like /** @var Validation $validation */ be not permitted in CI4 coding standard? I don't think so...

kenjis avatar Mar 19 '21 00:03 kenjis

We definitely want to support single-line comment. This is becoming a standard for inline annotations.

MGatner avatar Mar 19 '21 11:03 MGatner