stronk7

Untitled

Nov 8th, 2021 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.95 KB | None | 0 0
  1. index b3993e8..ca4e8b0 100644
  2. --- a/moodle/Sniffs/Files/MoodleInternalSniff.php
  3. +++ b/moodle/Sniffs/Files/MoodleInternalSniff.php
  4. @@ -30,6 +30,7 @@ namespace MoodleCodeSniffer\moodle\Sniffs\Files;
  5.  use PHP_CodeSniffer\Sniffs\Sniff;
  6.  use PHP_CodeSniffer\Files\File;
  7.  use PHP_CodeSniffer\Util\Tokens;
  8. +use MoodleCodeSniffer\moodle\Util\MoodleUtil;
  9.  
  10.  class MoodleInternalSniff implements Sniff {
  11.      /**
  12. @@ -47,14 +48,29 @@ class MoodleInternalSniff implements Sniff {
  13.       * @param int $pointer The position in the stack.
  14.       */
  15.      public function process(File $file, $pointer) {
  16. -        // Special dispensation for behat files.
  17. -        if (basename(dirname($file->getFilename())) === 'behat') {
  18. -            return;
  19. -        }
  20. +        // Guess moodle root, so we can do better dispensations below.
  21. +        $moodleRoot = MoodleUtil::getMoodleRoot($file);
  22. +        if ($moodleRoot) {
  23. +            $relPath = str_replace('\\', '/', substr($file->path, strlen($moodleRoot)));
  24. +            // Special dispensation for behat dirs at any level.
  25. +            if (strpos($relPath, '/behat/') !== false) {
  26. +                return;
  27. +            }
  28. +            // Special dispensation for lang dirs at any level.
  29. +            if (strpos($relPath, '/lang/') !== false) {
  30. +                return;
  31. +            }
  32. +        } else {
  33. +            // Falback to simpler dispensations, only looking 1 level.
  34. +            // Special dispensation for behat files.
  35. +            if (basename(dirname($file->getFilename())) === 'behat') {
  36. +                return;
  37. +            }
  38.  
  39. -        // Special dispensation for lang files.
  40. -        if (basename(dirname(dirname($file->getFilename()))) === 'lang') {
  41. -            return;
  42. +            // Special dispensation for lang files.
  43. +            if (basename(dirname(dirname($file->getFilename()))) === 'lang') {
  44. +                return;
  45. +            }
  46.          }
  47.  
  48.          // We only want to do this once per file.
Add Comment
Please, Sign In to add comment