Skip to content

Track nested classes correctly in CodeBlockAnalyser - #89

Merged
janedbal merged 1 commit into
masterfrom
jn-fix-nested-class-tracking
Oct 20, 2026
Merged

janedbal merged 1 commit into
masterfrom
jn-fix-nested-class-tracking

Conversation

@janedbal

Copy link
Copy Markdown
Member

CodeBlockAnalyser keeps the current class in one variable and the anonymous class state in one flag. Nested classes break both:

  • Named class declared inside a method: When the traversal leaves the inner class, the current class becomes null. The next method of the outer class then throws LogicException: Found class method without a class, should never happen.
  • Anonymous class inside an anonymous class: When the inner anonymous class ends, the flag is cleared. The outer anonymous class is still open. Its later methods are then reported as methods of the outer named class, e.g. Method App\AnonHost::b has no coverage. A rule that calls getMethodReflection() then fails, because such a method does not exist.

Now the analyser keeps a stack of the entered classes. The top of the stack is the class of the current method.

  • New fixture and test for each case. Both tests fail on master.

Co-Authored-By: Claude Code

CodeBlockAnalyser kept the current class in one variable and the
anonymous class state in one flag. Nested classes broke both:
- A named class declared inside a method reset the current class when
  the traversal left it. The next method of the outer class then threw
  "Found class method without a class, should never happen".
- An anonymous class inside an anonymous class cleared the flag too
  early. The methods after the inner class were then analysed and
  reported as methods of the outer named class. A rule that calls
  getMethodReflection() then failed, because such a method does not
  exist.

The analyser now keeps a stack of the entered classes. The top of the
stack is the class of the current method.

Co-Authored-By: Claude Code
@janedbal
janedbal marked this pull request as ready for review October 20, 2026 07:29
@janedbal
janedbal merged commit 2a3538c into master Oct 20, 2026
31 checks passed
@janedbal
janedbal deleted the jn-fix-nested-class-tracking branch October 20, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant