QuotesSniff.php 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 QuotesSniff
  11. *
  12. * Ensure that single quotes are used
  13. *
  14. * @link https://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#quotes
  15. */
  16. class QuotesSniff 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_CONSTANT_ENCAPSED_STRING];
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function process(File $phpcsFile, $stackPtr)
  35. {
  36. $tokens = $phpcsFile->getTokens();
  37. if (false !== strpos($tokens[$stackPtr]['content'], '"')) {
  38. $phpcsFile->addError('Use single quotes', $stackPtr, 'DoubleQuotes');
  39. }
  40. }
  41. }