Unverified Commit d1bb7ea7 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

feat(VariableComment): Allow omitting @var doc tags on typed class properties...

feat(VariableComment): Allow omitting @var doc tags on typed class properties (#3123282 by claudiu-cristea, Kingdutch)
parent e98e6b97
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -111,6 +111,12 @@ class VariableCommentSniff extends AbstractVariableSniff

        // The @var tag is the only one we require.
        if ($foundVar === null) {
            // If there's an inline type argument then you may omit the @var comment.
            // Check if there's a type between the variable name and the comment end.
            if ($phpcsFile->findPrevious([T_STRING], $stackPtr, $commentEnd) !== false) {
                return;
            }

            $error = 'Missing @var tag in member variable comment';
            $phpcsFile->addError($error, $commentEnd, 'MissingVar');
            return;
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class Test {
  protected $missingComment;

  /**
   * A typed property should still contain a variable comment.
   * A variable comment is optional for a typed property.
   */
  public ?Bar $bar;

+1 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ class Test {
  protected $missingComment;

  /**
   * A typed property should still contain a variable comment.
   * A variable comment is optional for a typed property.
   */
  public ?Bar $bar;

+0 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ class VariableCommentUnitTest extends CoderSniffUnitTest
            42 => 1,
            45 => 1,
            47 => 1,
            51 => 1,
        ];

    }//end getErrorList()
+5 −0
Original line number Diff line number Diff line
@@ -613,6 +613,11 @@ class Bar {
   */
  public ?Bar $bar;

  /**
   * A typed property may omit @var.
   */
  public Bar $baz;

  /**
   * Public static variables use camelCase, too.
   *