Skip to content

perf: cache validator severity and drop per-comparison reflection#148

Open
konradmichalik wants to merge 1 commit into
mainfrom
perf/cli-severity-cache
Open

perf: cache validator severity and drop per-comparison reflection#148
konradmichalik wants to merge 1 commit into
mainfrom
perf/cli-severity-cache

Conversation

@konradmichalik

@konradmichalik konradmichalik commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When sorting issues/validator groups by severity, the CLI renderer created a ReflectionClass and a fresh validator instance on every pairwise comparison to read resultTypeOnValidationFailure(). For a file with many issues this meant thousands of reflection instantiations.
  • The already-available validator instance is now used directly, and the resolved severity is cached per validator class. Reflection is removed entirely from this path.

Changes

  • src/Result/ValidationResultCliRenderer.php — resolve severity from the validator instance with a per-class cache; route group sorting through the same path; drop the reflection-based helper and its now-unused imports

Summary by CodeRabbit

  • Bug Fixes
    • Improved the ordering of validation issues by severity in command-line output.
    • Increased consistency when determining and displaying validator failure severity.
    • Improved handling for schema validation results.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

ValidationResultCliRenderer now resolves issue severity from validator instances, caches results by validator class, and removes reflection-based validator instantiation and throwable handling.

Changes

Severity resolution

Layer / File(s) Summary
Instance-based severity caching
src/Result/ValidationResultCliRenderer.php
Symfony Console imports are updated, severity results are cached by validator class, and severity resolution uses the validator instance with a SchemaValidator special case.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main performance change: caching severity and removing reflection.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/cli-severity-cache

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.2.2)

PHPStan was skipped because the config uses disallowed bootstrapFiles, bootstrapFile, or includes directives.


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.

@konradmichalik

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@konradmichalik

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/Result/ValidationResultCliRenderer.php (1)

227-229: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer instanceof XliffSchemaValidator here. str_contains($class, 'SchemaValidator') is brittle name-based dispatch; a direct type check is clearer and keeps the special case tied to the actual validator class. Add use MoveElevator\ComposerTranslationValidator\Validator\XliffSchemaValidator;.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Result/ValidationResultCliRenderer.php` around lines 227 - 229, The
severity special case in the severity resolution logic uses brittle class-name
matching. Import XliffSchemaValidator and replace the str_contains($class,
'SchemaValidator') condition with an instanceof XliffSchemaValidator check,
preserving the existing cached severity behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/Result/ValidationResultCliRenderer.php`:
- Around line 227-229: The severity special case in the severity resolution
logic uses brittle class-name matching. Import XliffSchemaValidator and replace
the str_contains($class, 'SchemaValidator') condition with an instanceof
XliffSchemaValidator check, preserving the existing cached severity behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 513dc6fb-7d13-42ab-be11-83d1d2abb64b

📥 Commits

Reviewing files that changed from the base of the PR and between c69ebc9 and ccec652.

📒 Files selected for processing (1)
  • src/Result/ValidationResultCliRenderer.php

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.

1 participant