Source: juststeveking.uk

Reducing code duplication
Code duplication is the most painful thing for a lot of developers, you think you have solved the problem, but there are several instances of the same issue. In this tutorial, I will walk through how you can approach writing code with a focus on reducing code duplication.

We have a Laravel application that is an e-commerce store, and once a day, we want to generate a report on all the sales and the status of shipments.

final class SalesFigures extends Command { public $signature = 'reports:sales'; public $description = 'Run a daily report on sales.'; public function handle(): int

final class ReportService implements ReportServiceContract { public function __construct( private readonly ResultsForPeriodContract $periodFilter, ) {} public function dailySales(CarbonInterface $start, CarbonInterface $end): Collection
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners