Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
CommentLevelsSniff Class Reference
Inheritance diagram for CommentLevelsSniff:

Public Member Functions

 register ()
 
 process (File $phpcsFile, $stackPtr)
 

Data Fields

const COMMENT_STRING = '//'
 
const FIRST_LEVEL_COMMENT = '_____________________________________________'
 
const SECOND_LEVEL_COMMENT = '--'
 
 $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]
 

Protected Attributes

 $levelComments
 

Detailed Description

Class CommentLevelsSniff

First and second level comments must be surrounded by empty lines. First, second and third level comments should have two spaces after "//". Inline comments should have one space after "//".

http://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#comments

Definition at line 21 of file CommentLevelsSniff.php.

Member Function Documentation

◆ process()

process ( File  $phpcsFile,
  $stackPtr 
)

{}

Definition at line 55 of file CommentLevelsSniff.php.

56  {
57  $tokens = $phpcsFile->getTokens();
58 
59  if ((T_STRING !== $tokens[$stackPtr]['code'])
60  || (self::COMMENT_STRING !== $tokens[$stackPtr]['content'])
61  || (1 === $tokens[$stackPtr]['line'])
62  ) {
63  return;
64  }
65 
66  $textInSameLine = $phpcsFile->findPrevious([T_STRING, T_STYLE], $stackPtr - 1);
67 
68  // is inline comment
69  if ((false !== $textInSameLine)
70  && ($tokens[$textInSameLine]['line'] === $tokens[$stackPtr]['line'])
71  ) {
72  $this->validateInlineComment($phpcsFile, $stackPtr, $tokens);
73  return;
74  }
75 
76  // validation of levels comments
77  if (!in_array($tokens[$stackPtr + 1]['content'], [
80  ])
81  ) {
82  $phpcsFile->addError('Level\'s comment does not have 2 spaces after "//"', $stackPtr, 'SpacesMissed');
83  }
84 
85  if (!$this->isNthLevelComment($phpcsFile, $stackPtr, $tokens)) {
86  return;
87  }
88 
89  if (!$this->checkNthLevelComment($phpcsFile, $stackPtr, $tokens)) {
90  $phpcsFile->addError(
91  'First and second level comments must be surrounded by empty lines',
92  $stackPtr,
93  'SpaceMissed'
94  );
95  }
96  }
$tokens
Definition: cards_list.phtml:9

◆ register()

register ( )

{}

Definition at line 47 of file CommentLevelsSniff.php.

48  {
49  return [T_STRING];
50  }

Field Documentation

◆ $levelComments

$levelComments
protected
Initial value:
= [
self::FIRST_LEVEL_COMMENT => T_STRING,
self::SECOND_LEVEL_COMMENT => T_DEC,
]

Definition at line 32 of file CommentLevelsSniff.php.

◆ $supportedTokenizers

$supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]

Definition at line 42 of file CommentLevelsSniff.php.

◆ COMMENT_STRING

const COMMENT_STRING = '//'

Definition at line 23 of file CommentLevelsSniff.php.

◆ FIRST_LEVEL_COMMENT

const FIRST_LEVEL_COMMENT = '_____________________________________________'

Definition at line 25 of file CommentLevelsSniff.php.

◆ SECOND_LEVEL_COMMENT

const SECOND_LEVEL_COMMENT = '--'

Definition at line 27 of file CommentLevelsSniff.php.


The documentation for this class was generated from the following file: