Skip to content

feat: ability remove method#72

Open
AZabolotnikov wants to merge 1 commit into
masterfrom
remove-method
Open

feat: ability remove method#72
AZabolotnikov wants to merge 1 commit into
masterfrom
remove-method

Conversation

@AZabolotnikov
Copy link
Copy Markdown
Contributor

refs: #70

@AZabolotnikov AZabolotnikov self-assigned this May 28, 2026
Copilot AI review requested due to automatic review settings May 28, 2026 08:40
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 26564275919

Coverage increased (+0.03%) to 98.584%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 6 of 6 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 353
Covered Lines: 348
Line Coverage: 98.58%
Coverage Strength: 9.47 hits per line

💛 - Coveralls

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +19 to +20
if ($node instanceof $this->nodeTypeClass && $node->name->toString() === $this->name) {
return NodeVisitor::REMOVE_NODE;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +90 to +94
public function removeMethod(string $methodName): self
{
$this->traverser->addVisitor(new RemoveNode($methodName, ClassMethod::class));

return $this;
Comment on lines +17 to +23
public function leaveNode(Node $node): Node|int
{
if ($node instanceof $this->nodeTypeClass && $node->name->toString() === $this->name) {
return NodeVisitor::REMOVE_NODE;
}

return $node;
Comment on lines +534 to +538
public function testRemoveMethod(): void
{
$file = $this->generateOriginalStructurePath('class.php');

$this->mockNativeFunction(
Comment thread README.md

#### removeMethod

Remove method from a class, trait, enum.
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.

3 participants