Skip to content

Conversation

@dereuromark
Copy link
Owner

Summary

This PR adds a new illuminator task that automatically replaces string field names with entity FIELD_* constants in Table class queries.

Addresses #389

What it does

  • Targets Table classes and identifies query builder method calls (select, where, orderBy, groupBy, etc.)
  • Replaces string literals with corresponding entity constants when they exist
  • Automatically adds the necessary use statement for the entity class

Example

Before:

$this->find()
    ->select(['id', 'name', 'content'])
    ->where(['name' => 'test'])
    ->orderBy(['created' => 'ASC']);

After:

$this->find()
    ->select([Vehicle::FIELD_ID, Vehicle::FIELD_NAME, Vehicle::FIELD_CONTENT])
    ->where([Vehicle::FIELD_NAME => 'test'])
    ->orderBy([Vehicle::FIELD_CREATED => 'ASC']);

Limitations (documented)

  • Only works within Table classes (derives entity from table name)
  • Skips dotted field names (e.g., Wheels.name) to avoid false positives with joins
  • Requires entity constants to already exist (run illuminate for EntityFieldTask first)
  • Won't handle associations/related table queries (single entity context only)

Configuration

The task supports custom method configuration via IdeHelper.illuminatorTasks config if needed.

Test plan

  • Unit tests for FieldConstantUsageTask
  • Tests for edge cases (no changes when already converted, skipping dotted fields, unknown entities)
  • PHPStan passes
  • PHPCS passes
  • Full test suite passes

🤖 Generated with Claude Code

…ants

This task automatically replaces string field names with entity FIELD_*
constants in Table class queries. It targets specific query builder methods
(select, where, orderBy, groupBy, etc.) and only replaces strings when
the corresponding entity has a matching constant.

Addresses #389

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Nov 23, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/field-constant-usage-task

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dereuromark
Copy link
Owner Author

One idea would be to separate this into "refactor" which we know can be "false positive", and keep the actual task "safe":

		$commands->add('illuminate code', IlluminateCommand::class);
		$commands->add('illuminate refactor', RefactorCommand::class);

@dereuromark
Copy link
Owner Author

@rochamarcelo And "refactor" should always run after "code"

@rochamarcelo
Copy link

I agree, having a refactor can avoid issues and don't change the original behavior.

@dereuromark
Copy link
Owner Author

Do you want make a 2nd command here and use this as first task?

@dereuromark dereuromark reopened this Nov 27, 2025
@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 83.42857% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.51%. Comparing base (0ae91aa) to head (edf1938).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Illuminator/Task/FieldConstantUsageTask.php 83.42% 29 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             master     #405    +/-   ##
==========================================
  Coverage     84.51%   84.51%            
- Complexity     2044     2109    +65     
==========================================
  Files           121      122     +1     
  Lines          5560     5735   +175     
==========================================
+ Hits           4699     4847   +148     
- Misses          861      888    +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rochamarcelo
Copy link

Yes, I can take a look into this.

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.

4 participants