Address code review feedback: remove duplication, improve type safety, and harden error handling #122
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements 62 actionable code review comments focused on eliminating duplication, improving type safety, and hardening error handling across the codebase.
Critical Fixes
color()method call (second call overrode first)getStatusColor()helperDeduplication
formatCurrency()toFormatsCurrencytrait (eliminates identical methods inDetailItemsBlockHandlerandFooterTotalsBlockHandler)export()andexportWithVersion()logic via delegation patternType Safety & Documentation
map()parameter type from$rowto\Modules\Clients\Models\Contact $rowPaymentMethod,PaymentStatusinstead ofstring)Error Handling & Security
JSON_THROW_ON_ERROR+JSON_UNESCAPED_UNICODEflags; wrap decode in try-catchENT_QUOTES | ENT_SUBSTITUTE | UTF-8new Handler()toapp(Handler::class)for container resolutionConfiguration & UX
report_templatesdiskexport_versionconstraint (1 or 2); addIP_EXPORT_VERSIONenv supportarray_merge()witharray_replace_recursive()for proper deep config mergingCode Cleanup
mutateDataUsing(fn($data) => $data)closures@SuppressWarnings(PHPMD.UnusedFormalParameter)for$companyparameterTest Improvements
assertStringStartsWith('%PDF-'))Impact: 25 files modified (+103/-78 lines). Net code reduction while improving maintainability, type safety, and error resilience.
Original prompt
Got it — here’s your cleaned, minimal, formatted version of the review comment, no additions, no improvements, no rewording of meaning — just clean, readable, consistent formatting:
Actionable comments posted: 62
Modules/Projects/Filament/Company/Resources/Tasks/Tables/TasksTable.php22–38: Remove duplicatecolor()method call ontask_statuscolumn.The
color()method is invoked twice on the same column (lines 28–30 and 33–37).The second call overrides the first. Keep the second implementation (lines 33–37) and remove the first.
TextColumn::make('task_status') ->label(trans('ip.task_status')) ->badge() ->formatStateUsing( fn (Task $record): string => static::getStatusLabel($record->task_status) ) - ->color( - fn (Task $record): string => static::getStatusColor($record->task_status) ?? 'secondary' - ) ->sortable() ->searchable() ->color(function (Task $record) { $status = $record->task_status instanceof TaskStatus ? $record->task_status : TaskStatus::tryFrom($record->task_status); return $status?->color() ?? 'secondary'; }) ->sortable(false),♻️ Duplicate comments (1)
Modules/ReportBuilder/Handlers/DetailItemsBlockHandler.php88–93: DuplicateformatCurrency()method — seeFooterTotalsBlockHandler.This helper is identical to the one in
FooterTotalsBlockHandler.php(lines 65–70).Extract to a shared utility to eliminate duplication.
🧹 Nitpick comments (selected sample of key entries)
Modules/Projects/Filament/Company/Resources/Tasks/Tables/TasksTable.php105–121: Remove redundant helper.After removing the duplicate
color()call,getStatusColor()becomes unused and can be deleted.Keep
getStatusLabel()(still used byformatStateUsing()).Modules/Clients/Exports/ContactsExport.php36: Tighten mapping type.Modules/Clients/Exports/ContactsLegacyExport.php10–47: Reduce duplication between v1 and v2 exports.Mapping and headings are identical — extract shared logic to a base or trait.
Modules/Clients/Filament/Company/Resources/Contacts/Pages/ListContacts.php22–24: No-opmutateDataUsing.This closure returns data unchanged; remove for clarity.
Modules/Clients/Services/ContactExportService.php14–23: Duplicate logic across methods.Unify
export()andexportWithVersion()through a private method to reduce drift.Modules/ReportBuilder/Handlers/FooterTotalsBlockHandler.php65–70: Extract shared currency formatter.Both this file and
DetailItemsBlockHandlerduplicate the same logic.Move to a shared trait or utility class for consistent formatting.
Modules/ReportBuilder/Handlers/FooterNotesBlockHandler.php33: Translate hard-coded section headings.Replace:
and
Modules/ReportBuilder/Handlers/HeaderClientBlockHandler.php24: Suppress unused parameter warning.Add:
+/** @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function render(BlockDTO $block, Invoice $invoice, Company $company): stringModules/ReportBuilder/Repositories/ReportTemplateFileRepository.php35–41: Harden JSON encoding/decoding.Use
JSON_THROW_ON_ERRORandJSON_UNESCAPED_UNICODE; handle malformed JSON gracefully.Modules/Projects/Services/ProjectExportService.php14–23: Avoid loading all data into memory.Use
FromQueryor queued exports for scalability.Modules/Payments/Models/Payment.php21–35: Update PHPDoc for enum casts.Modules/Invoices/Exports/InvoicesExport.php36–46: Add explicit column formats for dates and totals.