Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LanguageConstructsSniff.php
Go to the documentation of this file.
1 <?php
7 
8 use PHP_CodeSniffer\Sniffs\Sniff;
9 use PHP_CodeSniffer\Files\File;
10 
19 class LanguageConstructsSniff implements Sniff
20 {
26  protected $errorMessage = 'Use of %s language construct is discouraged.';
27 
33  // @codingStandardsIgnoreLine
34  protected $errorMessageBacktick = 'Incorrect usage of back quote string constant. Back quotes should be always inside strings.';
35 
41  protected $backtickCode = 'WrongBackQuotesUsage';
42 
48  protected $directOutput = 'DirectOutput';
49 
53  public function register()
54  {
55  return [
56  T_ECHO,
57  T_PRINT,
58  T_BACKTICK,
59  ];
60  }
61 
65  public function process(File $phpcsFile, $stackPtr)
66  {
67  $tokens = $phpcsFile->getTokens();
68  if ($tokens[$stackPtr]['code'] === T_BACKTICK) {
69  if ($phpcsFile->findNext(T_BACKTICK, $stackPtr + 1)) {
70  return;
71  }
72  $phpcsFile->addError($this->errorMessageBacktick, $stackPtr, $this->backtickCode);
73  return;
74  }
75  $phpcsFile->addError($this->errorMessage, $stackPtr, $this->directOutput, [$tokens[$stackPtr]['content']]);
76  }
77 }
$tokens
Definition: cards_list.phtml:9