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 <noreply@anthropic.com>
@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);

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