Skip to content

feat: Implement method addMethod to add class methods with access modifier and imports#64

Open
artengin wants to merge 20 commits intomasterfrom
create-addMethod
Open

feat: Implement method addMethod to add class methods with access modifier and imports#64
artengin wants to merge 20 commits intomasterfrom
create-addMethod

Conversation

@artengin
Copy link
Copy Markdown
Contributor

refs: #63

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 30, 2026

Coverage Report for CI Build 25179073724

Coverage increased (+0.5%) to 97.906%

Details

  • Coverage increased (+0.5%) from the base build.
  • Patch coverage: 3 uncovered changes across 2 files (136 of 139 lines covered, 97.84%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/Support/NodeValueComparator.php 14 12 85.71%
src/Support/StatementDuplicateChecker.php 17 16 94.12%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 382
Covered Lines: 374
Line Coverage: 97.91%
Coverage Strength: 10.07 hits per line

💛 - Coveralls

@artengin
Copy link
Copy Markdown
Contributor Author

It inherits from this commit: #51

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: 92e7d92e05

ℹ️ 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".

protected function modify(Node $node): Node
{
foreach ($node->stmts as $stmt) {
if ($stmt instanceof ClassMethod && $stmt->name->name === $this->name) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Detect all method-name collisions before inserting

The duplicate guard only checks ClassMethod names with a case-sensitive equality, which misses real PHP collisions: method names are case-insensitive, and enums also have implicit methods like cases (and from/tryFrom on backed enums). As a result, calls like adding SomeMethod when someMethod already exists, or adding cases to an enum, pass this check and produce files that fail at load time with Cannot redeclare ... errors.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This package provides a code modification tool, ensuring the correctness of method names and compliance with PHP rules is the caller's responsibility.

@artengin
Copy link
Copy Markdown
Contributor Author

@codex review

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: 504935b18a

ℹ️ 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 +67 to +70
default: $param->default !== DefaultValue::None ? BuilderHelpers::normalizeValue($param->default) : null,
type: $param->type !== null ? BuilderHelpers::normalizeType($param->type) : null,
byRef: $param->byRef,
variadic: $param->variadic,
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 Reject default values on variadic method params

When MethodParam is created with variadic: true and a non-None default, this code still assigns default on the generated Param. PHP does not allow defaults for variadic parameters, so addMethod() can emit code that immediately fails to parse (Variadic parameter cannot have a default value). Please guard this combination (and fail early) before constructing the AST node.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We intentionally do not validate parameter combinations, ensuring they comply with PHP rules is the caller's responsibility. The package is a code modification tool, not a PHP syntax validator.

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: 504935b18a

ℹ️ 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 thread src/Visitors/MethodVisitors/AddMethod.php
@artengin artengin self-assigned this Apr 30, 2026
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