Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShortEchoSyntaxSniff.php
Go to the documentation of this file.
1 <?php
7 
8 use PHP_CodeSniffer\Sniffs\Sniff;
9 use PHP_CodeSniffer\Files\File;
10 use PHP_CodeSniffer\Util\Tokens;
11 
12 class ShortEchoSyntaxSniff implements Sniff
13 {
17  public function register()
18  {
19  return [T_OPEN_TAG];
20  }
21 
25  public function process(File $phpcsFile, $stackPtr)
26  {
27  $tokens = $phpcsFile->getTokens();
28  $openTag = $tokens[$stackPtr];
29 
30  // HHVM Will classify <?= as a T_OPEN_TAG
31  if ($openTag['content'] === '<?=') {
32  return;
33  }
34 
35  $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
36  if ($tokens[$nextToken]['code'] == T_ECHO) {
37  $phpcsFile->addError(
38  'Short echo tag syntax must be used; expected "<?=" but found "<?php echo"',
39  $stackPtr,
40  'ShortEchoTag'
41  );
42  }
43  }
44 }
$tokens
Definition: cards_list.phtml:9