@@ -49,11 +49,16 @@ public function process(File $file, $pointer) {
4949
5050 // Before starting any check, let's look for various things.
5151
52- // Get the moodle branch being analysed.
53- $ moodleBranch = MoodleUtil::getMoodleBranch ($ file );
52+ // If we aren't checking Moodle 4.0dev (400) and up, nothing to check.
53+ // Make and exception for codechecker phpunit tests, so they are run always.
54+ if (!MoodleUtil::meetsMinimumMoodleVersion ($ file , 400 ) && !MoodleUtil::isUnitTestRunning ()) {
55+ return ; // @codeCoverageIgnore
56+ }
5457
55- // Detect if we are running PHPUnit.
56- $ runningPHPUnit = defined ('PHPUNIT_TEST ' ) && PHPUNIT_TEST ;
58+ // If the file is not a unit test file, nothing to check.
59+ if (!MoodleUtil::isUnitTest ($ file ) && !MoodleUtil::isUnitTestRunning ()) {
60+ return ; // @codeCoverageIgnore
61+ }
5762
5863 // We have all we need from core, let's start processing the file.
5964
@@ -70,24 +75,6 @@ public function process(File $file, $pointer) {
7075 return ; // @codeCoverageIgnore
7176 }
7277
73- // If we aren't checking Moodle 4.0dev (400) and up, nothing to check.
74- // Make and exception for codechecker phpunit tests, so they are run always.
75- if (isset ($ moodleBranch ) && $ moodleBranch < 400 && !$ runningPHPUnit ) {
76- return ; // @codeCoverageIgnore
77- }
78-
79- // If the file isn't under tests directory, nothing to check.
80- if (stripos ($ file ->getFilename (), '/tests/ ' ) === false ) {
81- return ; // @codeCoverageIgnore
82- }
83-
84- // If the file isn't called, _test.php, nothing to check.
85- // Make an exception for codechecker own phpunit fixtures here, allowing any name for them.
86- $ fileName = basename ($ file ->getFilename ());
87- if (substr ($ fileName , -9 ) !== '_test.php ' && !$ runningPHPUnit ) {
88- return ; // @codeCoverageIgnore
89- }
90-
9178 // Iterate over all the classes (hopefully only one, but that's not this sniff problem).
9279 $ cStart = $ pointer ;
9380 while ($ cStart = $ file ->findNext (T_CLASS , $ cStart + 1 )) {
0 commit comments