feat: Implement method addMethod to add class methods with access modifier and imports#64
feat: Implement method addMethod to add class methods with access modifier and imports#64
Conversation
…on' into refactor-architecture
…on' into refactor-architecture
…on' into refactor-architecture
…ifier and imports refs: #63
Coverage Report for CI Build 25179073724Coverage increased (+0.5%) to 97.906%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
It inherits from this commit: #51 |
There was a problem hiding this comment.
💡 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) { |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
This package provides a code modification tool, ensuring the correctness of method names and compliance with PHP rules is the caller's responsibility.
|
@codex review |
There was a problem hiding this comment.
💡 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".
| 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, |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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".
refs: #63