Methods Should Do One Thing
Single responsibility scales down to methods. Small, well-named methods replace comments, keep changes local and make stack traces readable.

The Single Responsibility Principle is usually discussed at the level of classes. The same idea scales down to methods, and that is where most of the day-to-day readability is won or lost. A method should do one thing, do it well, and have a name that tells you what that thing is.
A method that does three things
Here is an accessor that looks innocent at first glance:
public function getFullNameAttribute(): string
{
if (auth()->user() && auth()->user()->hasRole('admin') && auth()->user()->isVerified()) {
return 'Admin '.$this->first_name.' '.$this->last_name;
} else {
return $this->first_name[0].'. '.$this->last_name;
}
}
It answers a permission question, formats a long name and formats a short name, all in one block. To understand what it returns, you have to evaluate a three-part condition in your head and then read two string concatenations. To change how admins are detected, you edit a method called "full name".
Split it until every piece has a name
public function getFullNameAttribute(): string
{
return $this->isVerifiedAdmin() ? $this->formatFullName() : $this->formatShortName();
}
private function isVerifiedAdmin(): bool
{
$user = auth()->user();
return $user && $user->hasRole('admin') && $user->isVerified();
}
private function formatFullName(): string
{
return 'Admin '.$this->first_name.' '.$this->last_name;
}
private function formatShortName(): string
{
return strtoupper($this->first_name[0]).'. '.ucfirst($this->last_name);
}
The top-level method now reads like a sentence: if this is a verified admin, show the full name,
otherwise the short one. Each helper does exactly one thing, and its name says what. The repeated
auth()->user() calls are gone as a side effect, because the extracted method gave the value a
natural place to live.
Why this pays off
Names are documentation that cannot go stale. A comment saying "check if verified admin" can drift
away from the code below it. A method called isVerifiedAdmin() cannot.
Changes stay local. When the rule for who counts as an admin changes, you edit
isVerifiedAdmin() and nothing else. The formatting code is not even on screen.
Debugging gets cheaper. A stack trace pointing at formatShortName() tells you more than one
pointing at line 14 of a 40-line method.
Reuse appears naturally. Once isVerifiedAdmin() exists, you will notice two other places that
need it. Inline conditions never get reused, they get copy-pasted.
Where splitting stops helping
Extracting methods is not free. Every jump to another method is a small context switch for the
reader. If a helper is one line long, is used once and its name says nothing the code did not already
say, it is noise. private function addSpace($a, $b) makes code harder to read, not easier.
A useful rule of thumb:
- Extract when the piece has a meaningful name that is shorter than the code it replaces.
- Extract when you need a comment to explain what a block does. The comment is the method name.
- Do not extract a single obvious expression just to make a method shorter.
Also, one level of abstraction per method. getFullNameAttribute() above only calls other methods; it
does not mix high-level decisions with low-level string work. That consistency is what makes it
readable at a glance.
The practical test
Read a method out loud and describe what it does. If your description contains "and then", or you have to scroll to finish it, there is a second method hiding inside. Pull out the part you had to explain in the most words, give it the name you just used to explain it, and read the method again.