feat: ability remove method#72
Conversation
Coverage Report for CI Build 26564275919Coverage increased (+0.03%) to 98.584%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b2f9eaf252
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if ($node instanceof $this->nodeTypeClass && $node->name->toString() === $this->name) { | ||
| return NodeVisitor::REMOVE_NODE; |
There was a problem hiding this comment.
Restrict removeMethod to supported structures
When removeMethod() is used on an interface file, this visitor still deletes matching declarations because php-parser represents interface methods as ClassMethod nodes too, and the new visitor has no parent-type check like InsertCodeToMethod/AddTraits. This contradicts the documented scope of class/trait/enum and can silently strip an interface contract instead of rejecting the unsupported structure.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Implements a new PHPFileBuilder::removeMethod() feature intended to remove a method by name from a PHP class-like structure (per issue #70).
Changes:
- Added
PHPFileBuilder::removeMethod(string $methodName)API. - Introduced a new AST visitor (
RemoveNode) to remove nodes by name/type. - Added a PHPUnit test + fixture for removing a method from a class, and documented the new feature in README.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/Builders/PHPFileBuilder.php |
Adds the new removeMethod() public API. |
src/Visitors/RemoveNode.php |
Introduces a generic visitor to remove a node by name/type. |
tests/PHPFileBuilderTest.php |
Adds a test for removing a method from a class fixture. |
tests/fixtures/PHPFileBuilderTest/class_method_removed.php |
Expected output fixture after method removal. |
README.md |
Documents the new removeMethod feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function removeMethod(string $methodName): self | ||
| { | ||
| $this->traverser->addVisitor(new RemoveNode($methodName, ClassMethod::class)); | ||
|
|
||
| return $this; |
| public function leaveNode(Node $node): Node|int | ||
| { | ||
| if ($node instanceof $this->nodeTypeClass && $node->name->toString() === $this->name) { | ||
| return NodeVisitor::REMOVE_NODE; | ||
| } | ||
|
|
||
| return $node; |
| public function testRemoveMethod(): void | ||
| { | ||
| $file = $this->generateOriginalStructurePath('class.php'); | ||
|
|
||
| $this->mockNativeFunction( |
|
|
||
| #### removeMethod | ||
|
|
||
| Remove method from a class, trait, enum. |
refs: #70