Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Browse all series

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

  1. Defensive Programming Basics (3)
    1. 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.
    2. 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.
    3. 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.
  2. Embracing Immutability (4)
    1. 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.
    2. 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.
    3. 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.
    4. 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.
  3. Power of Value Objects (3)
    1. Value Objects

      In this episode, we'll explore the concept of value objects and how they can help us model our domain more effectively.
    2. 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.
    3. Value Objects With Eloquent

      Now that we understand value objects, let's explore how to integrate them with Eloquent models.
  4. Static Analysis With PHPStan (4)
    1. 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.
    2. 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.
    3. 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.
    4. Phpstan: Integrating With Laravel

      Let's install Larastan to help PHPStan fully understand our Laravel application and explore some of its additional features.
  5. Domain Design Tools (2)
    1. 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.
    2. 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.
  6. Automation and CI (2)
    1. Continuous Integration With Github Actions

      Let's set up our test suite, PHPStan, and Rector to run on every push to our repository using GitHub Actions.
    2. Closing Thoughts

      You've made it! In this final episode, we'll recap the core fundamentals and reinforce when to apply what you've learned.

Continue Learning