Skip to content

refactor: replace abstract visitor hierarchy with contract-based polymorphic dispatch#67

Open
artengin wants to merge 10 commits into
masterfrom
refactor-architecture-2
Open

refactor: replace abstract visitor hierarchy with contract-based polymorphic dispatch#67
artengin wants to merge 10 commits into
masterfrom
refactor-architecture-2

Conversation

@artengin

@artengin artengin commented May 6, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@artengin

artengin commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@artengin

artengin commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

It inherits from this commit: #51

@coveralls

coveralls commented May 6, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27781967069

Coverage decreased (-0.08%) to 98.611%

Details

  • Coverage decreased (-0.08%) from the base build.
  • Patch coverage: 41 of 41 lines across 5 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: 360
Covered Lines: 355
Line Coverage: 98.61%
Coverage Strength: 10.8 hits per line

💛 - Coveralls

@artengin artengin self-assigned this May 6, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

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

@artengin artengin assigned DenTray and unassigned artengin May 7, 2026

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

Copy link
Copy Markdown

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: d13ce08389

ℹ️ 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/AddTraits.php Outdated
Comment on lines +29 to +30
fn ($trait) => new TraitUse([new Name(class_basename($trait))]),
array_unique(array_filter($this->traits)),

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 Deduplicate trait names after basename normalization

getInsertableNodes() now calls array_unique() before class_basename(), so inputs like ['App\\Traits\\Loggable', 'Loggable'] produce two identical TraitUse nodes. filterExistingNodes() only removes traits already present in the file, not duplicates within the new candidate list, so this can emit duplicate use Loggable; entries and generate invalid class composition when the same trait is applied twice.

Useful? React with 👍 / 👎.

@DenTray DenTray left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@artengin let's make another way to code optimization. Instead of implementing new contract let's change the addImports and addTraits methods logic to add the same visitor N times. It should simplify architecture and AddImports/AddTraits visitors logic and

@DenTray DenTray assigned artengin and unassigned DenTray May 21, 2026
@artengin

Copy link
Copy Markdown
Contributor Author

@codex review

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

Copy link
Copy Markdown

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: 7e18bad878

ℹ️ 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 +68
foreach ($imports as $import) {
$this->traverser->addVisitor(new AddImport($import));

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 Filter invalid import entries before adding visitors

addImports() now forwards each raw array element directly into new AddImport($import), but AddImport::__construct requires a string and no longer benefits from the old filter() step. If callers pass optional values (for example null or empty strings from config/merge pipelines), this now throws a TypeError (for null) or can emit an invalid use ; statement (for empty string), where the previous implementation silently skipped those values.

Useful? React with 👍 / 👎.

Comment on lines +76 to +77
foreach ($traits as $trait) {
$this->traverser->addVisitor(new AddTrait($trait));

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 Sanitize trait list before constructing AddTrait visitors

addTraits() also removed the prior filter() behavior and now instantiates AddTrait for every raw element. Passing nullable/empty trait entries (common when composing arrays conditionally) now fails at runtime (TypeError for null) or may build malformed trait/use nodes for empty strings, instead of being ignored as before, so this refactor introduces a backward-incompatible failure mode.

Useful? React with 👍 / 👎.

@artengin artengin assigned DenTray and unassigned artengin May 22, 2026
@DenTray

DenTray commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@artengin please resolve conflicts

@DenTray DenTray assigned artengin and unassigned DenTray Jun 8, 2026
@artengin artengin assigned DenTray and unassigned artengin Jun 8, 2026

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

Copy link
Copy Markdown

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: 18ad99c1d7

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

{
$this->traverser->addVisitor(new AddImports($imports));
foreach ($imports as $import) {
$this->traverser->addVisitor(new AddImport($import));

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 Preserve import order when adding per-import visitors

When callers pass multiple new imports, this now enqueues one AddImport visitor per item, but the project’s NodeTraverser::traverse() reverses the visitor list before traversal. Since these imports are inserted from AddImport::afterTraverse(), they are applied last-to-first, so addImports([SecondClass, ThirdClass]) emits ThirdClass before SecondClass (and addTraits() inherits the same reversed import order), breaking the previously preserved caller order and the existing fixture expectations.

Useful? React with 👍 / 👎.

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

Copy link
Copy Markdown

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: 6ee2921474

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

{
$this->traverser->addVisitor(new AddTraits($traits));
foreach ($traits as $trait) {
$this->traverser->addVisitor(new AddTrait($trait));

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 Preserve trait insertion order

When addTraits() receives multiple new traits for a class/trait/enum with no existing trait uses, this loop registers one AddTrait visitor per trait, but NodeTraverser::traverse() reverses the visitor list before traversal. Since each AddTrait inserts during leaveNode, addTraits([FirstTrait, SecondTrait, ThirdTrait]) emits the trait-use statements as ThirdTrait, SecondTrait, FirstTrait, rather than the caller order expected by the existing add_traits_to_enum.php/add_traits_to_trait.php fixtures.

Useful? React with 👍 / 👎.

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