Commit 9ac24f25 authored by Jakub Piasecki's avatar Jakub Piasecki Committed by Klaus Purer
Browse files

fix(VariableComment): Find missing comments for member variables (#2909393 by zaporylie)

parent 50475f0f
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -40,13 +40,21 @@ class VariableCommentSniff extends AbstractVariableSniff
    public function processMemberVar(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $commentToken = [
            T_COMMENT,
            T_DOC_COMMENT_CLOSE_TAG,
        $ignore = [
            T_PUBLIC,
            T_PRIVATE,
            T_PROTECTED,
            T_VAR,
            T_STATIC,
            T_WHITESPACE,
        ];

        $commentEnd = $phpcsFile->findPrevious($commentToken, $stackPtr);
        if ($commentEnd === false) {
        $commentEnd = $phpcsFile->findPrevious($ignore, ($stackPtr - 1), null, true);
        if ($commentEnd === false
            || ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG
            && $tokens[$commentEnd]['code'] !== T_COMMENT)
        ) {
            $phpcsFile->addError('Missing member variable doc comment', $stackPtr, 'Missing');
            return;
        }

+2 −0
Original line number Diff line number Diff line
@@ -44,4 +44,6 @@ class Test {
  // Wrong style with var keyword.
  var $varStyle;

  protected $missingComment;

}
+2 −0
Original line number Diff line number Diff line
@@ -48,4 +48,6 @@ class Test {
   */
  public $varStyle;

  protected $missingComment;

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

    }//end getErrorList()
+5 −0
Original line number Diff line number Diff line
@@ -1353,6 +1353,11 @@ class NodeType extends ConfigEntityBundleBase {
 */
class OperatorTest {

  /**
   * Seen IDs.
   *
   * @var array
   */
  protected static $seenIds;

  /**