Return early for invalid or exceptional cases so the happy path stays flat: ~~~php public function process(?User $user): Result { if ($user === null) { return Result::failure('User not found'); } if (!$user->isActive()) { return Result::failure('User is inactive'); } return $this->processor->process($user); } ~~~ Avoid an else after a return and keep nesting shallow.
Installs into .claude/skills of the current project.
Are you the author of Php Best Practices?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-php-best-practices-8502434a)
Return early for invalid or exceptional cases so the happy path stays flat:
~~~php
public function process(?User $user): Result
{
if ($user === null) {
return Result::failure('User not found');
}
if (!$user->isActive()) {
return Result::failure('User is inactive');
}
return $this->processor->process($user);
}
~~~
Avoid an else after a return and keep nesting shallow.