Have you ever written Laravel code that works… but feels messy, hard to test, or hard to maintain?
That’s where Object Calisthenics comes in — a set of 9 simple rules that help you write cleaner, more focused, and maintainable object-oriented code.

What is Object Calisthenics?

Created by Jeff Bay, Object Calisthenics is a list of 9 rules to train good object-oriented habits.
Think of it as a workout for your code — maybe you won't follow all the rules every time, but practicing helps you improve.


The 9 Rules with PHP (Laravel) Examples.

Only One Level of Indentation per Method

Avoid deeply nested if statements. Extract logic into methods.

if (! $user->isActive()) return;
if (! $user->hasRole('admin')) return;

$this->grantAccess();

Wrap All Primitives and Strings

Avoid passing raw values. Create Value Objects.

public function updateStatus(Status $status)

Don’t Use the ELSE Keyword

Make your code easier to read by removing else.

if ($user->isActive()) return 'Active';

return 'Inactive';

One Dot per Line

Avoid calling multiple methods in a chain — it creates tight coupling.

// Instead of
return $user->profile->address->city;

// Do
return $user->getCity();

First Class Collections

Don’t use plain arrays — wrap them in a class.

class Order {
    public OrderItems $items;
}

Don’t Abbreviate

Use clear and complete names.

// Bad
$usr = new UsrSvc();

// Good
$userService = new UserService();

Keep All Entities Small

If a class is too long, it’s doing too much. Split it into smaller classes.


No Getters/Setters

Avoid exposing internals. Use intention-revealing methods.

// bad
$user->setName('John');

// good
$user->renameTo('John');

No More Than Two Instance Variables per Class

Limit how much a class depends on.
If your class needs 4+ services, split the responsibilities.


Helpful Tools


Conclusion

Object Calisthenics isn’t a strict rule it’s a discipline.
By using these techniques in your PHP/Laravel projects, your code will become more:

  • Readable
  • Testable
  • Cohesive
  • Maintainable

Do you already follow any of these rules? Which one helped you the most?

Drop a comment below!