Function: A named block of reusable code that performs a specific task. In functional programming, a pure function produces the same output for the same input and has no side effects. A function is a named block of code that performs one task and can be reused. It takes input through parameters and usually returns a result, like calculateVat($amount).
Good functions are small and do one thing, with a name that says what. A reader should understand the purpose from the name and parameters without reading the body.
What should you keep in mind with Function?
A pure function always returns the same output for the same input and changes nothing outside itself. Pure functions are the easiest code to test and reason about. Real applications need side effects, such as saving data or sending email. A good structure keeps those at the edges, while the calculations and decisions in the middle stay in pure functions you can test without a database.
Apply Spatie's Laravel and PHP coding standards for any task that creates, edits, reviews, refactors, or formats Laravel/PHP code or Blade templates; use for controllers, Eloquent models, routes, config, validation, migrations, tests, and related files to align with Laravel conventions and PSR-12.
Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.