moodlehq / moodle-cs

Moodle Coding Style

Home Page:https://github.com/moodlehq/moodle-cs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Codechecker hangs when parsing abstract functions

PhMemmel opened this issue · comments

The codechecker hangs (apache process goes up to 100% CPU usage, will not stop until being killed by hand) when trying to parse a function in a test class of the following scheme:
abstract function test_SOME_NAME_OF_THE_FUNCTION();

It does not hang if the abstract function does not start with "test_" prefix.

Perhaps d8c6e97?

Note: I'm not able to reproduce locally. Do you have a more-complete example?

I condensed the problematic class to the following example:

  • I put the following content as moodlecs_test.php into one of my activity plugins: mod/myplugin/tests/moodlecs_test.php
  • Content of the file:
<?php
abstract class moodlecs_test extends \advanced_testcase {
    abstract public function test_some_function_name(): void;
}
  • Latest moodle vanilla, commit f30110b5ebf9090ee484986e020d43a7819fc436
  • Latest local_codechecker, commit 8be89339db4982e9f884f12087dd9e6837a05e6a

Ok,

so, for sure, it's some of the other PHPUnit Sniffs that is not handling the abstract methods properly. Note that, for some Sniffs, we already have this protection.

My blind bet is moodle.PHPUnit.TestCaseProvider (because of the way it works), but will create a new test to reproduce it against all the moodle.PHPUnit.* sniffs.

Ciao :-)

Would be great if you can confirm that this change fixes your case and allows code-checker to complete ok.

diff --git a/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php b/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php
index 5072602..dcf1431 100644
--- a/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php
+++ b/moodle/Sniffs/PHPUnit/TestCaseProviderSniff.php
@@ -128,7 +128,7 @@ class TestCaseProviderSniff implements Sniff {
                 }
 
                 // Advance until the end of the method, if possible, to find the next one quicker.
-                $mStart = $tokens[$mStart]['scope_closer'] ?? $pointer + 1;
+                $mStart = $tokens[$mStart]['scope_closer'] ?? $mStart + 1;
             }
         }
     }

In the mean time, I'm building here a new unit test to have that covered.

Ciao :-)

Can confirm: this fixes it, good job and thank you very much!

HI, as far as #94 should have fixed this, it's closed now.

I'll try to make a new moodle-cs release today and, then, a local_codechecker one with the fix applied.

Ciao :-)