CombinatorIndentationSniff.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sniffs\Less;
  7. use PHP_CodeSniffer\Sniffs\Sniff;
  8. use PHP_CodeSniffer\Files\File;
  9. /**
  10. * Class CombinatorIndentationSniff
  11. *
  12. * Ensure that spaces are used before and after combinators
  13. *
  14. * @link https://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#combinator-indents
  15. */
  16. class CombinatorIndentationSniff implements Sniff
  17. {
  18. /**
  19. * A list of tokenizers this sniff supports.
  20. *
  21. * @var array
  22. */
  23. public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS];
  24. /**
  25. * @inheritdoc
  26. */
  27. public function register()
  28. {
  29. return [T_PLUS];
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function process(File $phpcsFile, $stackPtr)
  35. {
  36. $tokens = $phpcsFile->getTokens();
  37. $prevPtr = $stackPtr - 1;
  38. $nextPtr = $stackPtr + 1;
  39. if (($tokens[$prevPtr]['code'] !== T_WHITESPACE) || ($tokens[$nextPtr]['code'] !== T_WHITESPACE)) {
  40. $phpcsFile->addError('Spaces should be before and after combinators', $stackPtr, 'NoSpaces');
  41. }
  42. }
  43. }