Apply conservative Rector cleanup#70
Conversation
There was a problem hiding this comment.
Pull request overview
Applies a conservative, behavior-intended Rector cleanup across src/ and tests/, simplifying conditionals and modernizing a few string operations while keeping the overall plugin behavior the same.
Changes:
- Modernizes string checks/casts in a few places (e.g.,
str_contains,str_starts_with, explicit(string)casts). - Refactors some control-flow and return/assignment patterns (ternaries, simplified loops, return concatenation).
- Minor controller view-var setting refactors (
set([...])).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/TestCase/Model/Table/DatabaseLogsTableTest.php | Casts summary to string before mb_strlen() in test assertion. |
| tests/schema.php | Simplifies catch (ReflectionException $e) to catch (ReflectionException). |
| src/Model/Table/LazyTableTrait.php | Changes SQLite “unable to open” handling to throw a chained RuntimeException. |
| src/Model/Table/DatabaseLogsTable.php | Refactors date-expression selection logic; simplifies duplicate-removal loop; minor string casts/return refactor. |
| src/Model/Entity/DatabaseLog.php | Replaces strpos(...) === 0 with str_starts_with(...). |
| src/Log/Engine/DatabaseLog.php | Simplifies default model selection conditional. |
| src/Controller/Admin/LogsController.php | Replaces set(compact(...)) with explicit array mapping. |
| src/Controller/Admin/DatabaseLogController.php | Replaces set(compact(...)) with explicit array mapping. |
| src/Controller/Admin/DatabaseLogAppController.php | Removes redundant ForbiddenException rethrow catch in beforeFilter(). |
| src/Command/ShowCommand.php | Uses str_contains() and adds string cast before trimming message. |
| src/Command/ExportCommand.php | Condenses type-selection conditional into a ternary expression. |
Comments suppressed due to low confidence (2)
src/Controller/Admin/DatabaseLogAppController.php:98
- Removing the dedicated ForbiddenException catch changes behavior: a ForbiddenException thrown from the configured adminAccess gate will now be logged and replaced with the generic "admin access denied" message instead of propagating the original ForbiddenException. If preserving the gate’s intended exception/message is important, rethrow ForbiddenException before the generic Throwable handler (or narrow the catch).
try {
$allowed = $gate($this->request) === true;
} catch (Throwable $e) {
Log::warning(sprintf('DatabaseLog.adminAccess threw %s: %s', $e::class, $e->getMessage()));
throw new ForbiddenException(__d('database_log', 'DatabaseLog admin access denied.'));
}
src/Model/Table/DatabaseLogsTable.php:264
- Indentation is inconsistent within this conditional block (spaces vs tabs), and the closing brace alignment becomes off relative to surrounding code. Reformat this else/elseif chain to use tabs consistently per .editorconfig.
// MySQL
$dateExpr = "DATE_FORMAT(created, '%Y-%m-%d %H')";
} else {
$dateExpr = "DATE_FORMAT(created, '%Y-%m-%d')";
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/Controller/Admin/DatabaseLogAppController.php:98
- Removing the dedicated
catch (ForbiddenException)changes behavior: ifDatabaseLog.adminAccessintentionally throwsForbiddenException(e.g. with a specific message/status), it will now be caught by theThrowablehandler, logged as a warning, and replaced with a genericForbiddenException. Consider re-adding theForbiddenExceptioncatch to rethrow it (or checking$e instanceof ForbiddenExceptioninside theThrowablecatch and rethrowing) so intentional denials aren’t treated as unexpected errors.
try {
$allowed = $gate($this->request) === true;
} catch (Throwable $e) {
Log::warning(sprintf('DatabaseLog.adminAccess threw %s: %s', $e::class, $e->getMessage()));
throw new ForbiddenException(__d('database_log', 'DatabaseLog admin access denied.'));
}
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #70 +/- ##
============================================
+ Coverage 81.07% 81.46% +0.39%
Complexity 186 186
============================================
Files 17 17
Lines 634 626 -8
============================================
- Hits 514 510 -4
+ Misses 120 116 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Applies the same conservative, behavior-neutral Rector cleanup pass as used in dereuromark/cakephp-ide-helper#452, but without committing Rector config or dependency wiring here.
src/andtests/This was generated with a temporary local Rector config and followed with CS fixes where needed.