Defensive Laravel
In this series, we'll take a deep-dive into various strategies and tools that will help you write robust and reliable code. We'll explore core defensive programming concepts, from strict typing and immutable objects to leveraging value objects for more effective domain modeling. Okay, let's dig in!
Progress
Series Info
- Episodes
- 18
- Run Time
- 3h 7m
- Difficulty
- Advanced
- Last Updated
- Jul 28, 2025
- Version
- Latest
Series Episodes
- Defensive Programming Basics (3)
Introduction To Defensive Programming
To get started, let's explore the concept of defensive programming and see how we can use it to create more robust and reliable software.Strict Typing
Ever been burned by PHP's type juggling? Don't know what that is? No worries! Let's flip on strict types and see how that simple switch keeps surprises out of our code.Guard Clauses And Avoiding Invalid State
We're going to explore how to use guard clauses to stop code execution early and avoid invalid state in our application.
- Embracing Immutability (4)
Immutable Dates
Mutable DateTime objects can be sneaky. We're going to take a brief look at immutability and see how it can help us avoid bugs in our date handling.Objects As Pseudo Structs
Sometimes, we just need a lightweight container for data. Let's explore how we can leverage behaviorless objects as safe, self-documenting structs.Rich Objects And Data Bags
As those structs start picking up rules, it's natural to graduate them into richer objects. We'll walk through that evolution together.Writing Our Own Immutable Objects
Now that we understand the benefits of immutability, let's create our own immutable objects and see how they can help us write cleaner, safer code.
- Power of Value Objects (3)
Value Objects
In this episode, we'll explore the concept of value objects and how they can help us model our domain more effectively.Cooperation Between Value Objects
Value objects can interact with each other in interesting ways. Let's see how we can leverage these interactions to create more powerful abstractions.Value Objects With Eloquent
Now that we understand value objects, let's explore how to integrate them with Eloquent models.
- Static Analysis With PHPStan (4)
Phpstan: An Introduction
In this episode, we're going to take a quick look at static analysis. We'll get PHPStan running in minutes and fix our first errors together.Phpstan: Generics And Class Strings
Let's dive deeper into PHPStan and explore how we can use generics to improve type safety and code quality. We're also going to see how class strings can help us narrow our types.Phpstan: Edge Cases, Multi Type Generics, And More
Let's cover some of the common edge cases we might encounter when using PHPStan and how to handle them. We'll also explore multi-type generics and other advanced features.Phpstan: Integrating With Laravel
Let's install Larastan to help PHPStan fully understand our Laravel application and explore some of its additional features.
- Domain Design Tools (2)
Domain Invariants And Business Rules
Business rules shouldn't live only in our heads. We'll encode them as domain invariants so they're enforced at all times.Automated Refactoring With Rector
Let's install and set up Rector, a powerful tool for automated refactoring in PHP. We'll see how it can help us apply best practices and improve our codebase.
- Automation and CI (2)
