PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/script/lib/PHP/CodeSniffer/Standards/MySource/Sniffs/CSS/BrowserSpecificStylesSniff.php

https://bitbucket.org/chamilo/chamilo-dev/
PHP | 98 lines | 31 code | 12 blank | 55 comment | 4 complexity | 4d94e6fb027c783833a86745c2907308 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT
  1. <?php
  2. /**
  3. * MySource_Sniffs_CSS_BrowserSpecificStylesSniff.
  4. *
  5. * PHP version 5
  6. *
  7. * @category PHP
  8. * @package PHP_CodeSniffer
  9. * @author Greg Sherwood <gsherwood@squiz.net>
  10. * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
  11. * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
  12. * @version CVS: $Id: ForbiddenStylesSniff.php 268254 2008-11-04 05:08:07Z squiz $
  13. * @link http://pear.php.net/package/PHP_CodeSniffer
  14. */
  15. /**
  16. * MySource_Sniffs_CSS_BrowserSpecificStylesSniff.
  17. *
  18. * Ensure that browser-specific styles are not used.
  19. *
  20. * @category PHP
  21. * @package PHP_CodeSniffer
  22. * @author Greg Sherwood <gsherwood@squiz.net>
  23. * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
  24. * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
  25. * @version Release: 1.2.2
  26. * @link http://pear.php.net/package/PHP_CodeSniffer
  27. */
  28. class MySource_Sniffs_CSS_BrowserSpecificStylesSniff implements PHP_CodeSniffer_Sniff
  29. {
  30. /**
  31. * A list of tokenizers this sniff supports.
  32. *
  33. * @var array
  34. */
  35. public $supportedTokenizers = array('CSS');
  36. /**
  37. * A list of specific stylsheet suffixes we allow.
  38. *
  39. * These stylsheets contain browser specific styles
  40. * so this sniff ignore them files in the form:
  41. * *_moz.css and *_ie7.css etc.
  42. *
  43. * @var array
  44. */
  45. protected $specificStylesheets = array('moz', 'ie', 'ie7', 'ie8', 'webkit');
  46. /**
  47. * Returns the token types that this sniff is interested in.
  48. *
  49. * @return array(int)
  50. */
  51. public function register()
  52. {
  53. return array(T_STYLE);
  54. } //end register()
  55. /**
  56. * Processes the tokens that this sniff is interested in.
  57. *
  58. * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
  59. * @param int $stackPtr The position in the stack where
  60. * the token was found.
  61. *
  62. * @return void
  63. */
  64. public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
  65. {
  66. // Ignore files with browser-specific suffixes.
  67. $filename = $phpcsFile->getFilename();
  68. $breakChar = strrpos($filename, '_');
  69. if ($breakChar !== false && substr($filename, - 4) === '.css')
  70. {
  71. $specific = substr($filename, ($breakChar + 1), - 4);
  72. if (in_array($specific, $this->specificStylesheets) === true)
  73. {
  74. return;
  75. }
  76. }
  77. $tokens = $phpcsFile->getTokens();
  78. $content = $tokens[$stackPtr]['content'];
  79. if ($content{0} === '-')
  80. {
  81. $error = 'Browser-specific styles are not allowed';
  82. $phpcsFile->addError($error, $stackPtr, 'ForbiddenStyle');
  83. }
  84. } //end process()
  85. } //end class
  86. ?>