← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Fluent Naming for Boolean Methods

style Beginner
debt(d3/e1/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). The detection_hints list phpcs, phpmd, and phpstan as tools, and the automated flag is yes. phpcs/phpmd can flag boolean methods missing is/has/can prefixes and inconsistent verb prefixes as a common pattern, placing this squarely at the default linter level rather than requiring a specialist tool.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix confirms this: rename the method and update its call sites. For a boolean method rename like active() → isActive(), this is a straightforward find-and-replace or IDE rename refactor, typically a single mechanical operation per method.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope covers web, cli, and queue-worker contexts, which is broad, but naming conventions are a localised stylistic tax. They affect readability and onboarding effort within a codebase but don't create architectural gravity or constrain future choices in a structural way. Each violation is self-contained.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field reveals the core trap: developers believe method names just need to describe what the method does, missing that context and intent matter (e.g., process() vs processPayment()). The common_mistakes also include methods whose names lie about their behaviour (save() that sends email), which is a documented gotcha that most developers learn after encountering confusing bugs. This is a well-known pitfall but not one that contradicts analogous concepts in other ecosystems.

About DEBT scoring →

Also Known As

fluent method naming readable method names expressive naming

TL;DR

Prefix boolean-returning methods with is, has, can, should, or was so conditionals read as natural English sentences.

Explanation

Boolean method names should read naturally in conditionals: if ($user->isActive()), if ($order->hasDiscount()), if ($role->canPublish()). Established prefixes: is (current state — isVerified, isExpired), has (possession — hasPermission, hasBillingAddress), can (capability — canEdit, canDelete), should (recommendation — shouldRedirect), was (past state — wasDelivered, wasCancelled). Avoid negation in names (isNotActive, hasNoItems) — double negatives in conditions such as if (!$order->hasNoItems()) are cognitively taxing. PHPStan and Psalm can enforce bool return types on methods with these prefixes via custom rules.

Common Misconception

Method names just need to describe what the method does. Good names describe what the method does in context — a method called process() on an OrderService is meaningless; processPayment(), shipOrder(), or cancelOrder() communicate intent, constraints, and domain significance.

Why It Matters

Fluent naming — consistent verb prefixes, boolean is/has prefixes, and noun-based class names — makes code read like English and reduces the cognitive effort of understanding what a method does.

Common Mistakes

  • Inconsistent verb prefixes: fetchUser(), getOrder(), retrieveProduct() — pick one verb and stick to it.
  • Boolean methods without is/has/can prefix: $user->active() instead of $user->isActive().
  • Class names that are verbs: UserProcessor, DataHandler — classes should be nouns.
  • Method names that lie: save() that also sends an email — names must match behaviour.

Code Examples

✗ Vulnerable
// Inconsistent naming — team uses different conventions:
class UserManager {           // 'Manager' is vague
    function fetchUser() {}   // fetch
    function getOrder() {}    // get
    function loadProduct() {} // load — all mean the same thing
    function active() {}      // Should be isActive()
    function do() {}          // Meaningless
}
✓ Fixed
// Fluent interface — method chaining returns \$this
class QueryBuilder {
    public function select(string ...\$cols): static {
        \$this->columns = \$cols; return \$this;
    }
    public function from(string \$table): static {
        \$this->table = \$table; return \$this;
    }
    public function where(string \$cond): static {
        \$this->conditions[] = \$cond; return \$this;
    }
    public function limit(int \$n): static {
        \$this->limit = \$n; return \$this;
    }
    public function get(): array {
        return \$this->db->query(\$this->toSql());
    }
}

// Usage reads like English:
\$users = \$query
    ->select('id', 'name', 'email')
    ->from('users')
    ->where('active = 1')
    ->limit(20)
    ->get();

Added 15 Mar 2026
Edited 22 Mar 2026
Views 21
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 3 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Amazonbot 10 Unknown AI 3 Perplexity 2 ChatGPT 2 Google 1 Bing 1
crawler 17 crawler_json 1 pre-tracking 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Name boolean-returning methods with is/has/can/should prefix and make them read like English: $order->isReadyToShip() not $order->checkShipping(); $user->hasPermission('edit') not $user->permission('edit')
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Boolean methods without is/has/can prefix; method name that reads ambiguously: active() vs isActive(); PHP getters without consistent naming
Auto-detectable: ✓ Yes phpcs phpmd phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Low Context: File

✓ schema.org compliant