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

Long Parameter List

quality Beginner

Also Known As

too many parameters parameter list smell excessive parameters

TL;DR

A function or method with too many parameters — typically 4+ — making calls hard to read and easy to get wrong.

Explanation

Long parameter lists are fragile: callers must remember the order of arguments, optional parameters with defaults spread throughout are easy to mis-specify, and adding a new parameter breaks every call site. The common refactoring is to introduce a Parameter Object — a simple class or readonly struct that groups related parameters — so the method signature becomes function process(OrderData $order) instead of function process($id, $name, $qty, $price, $discount, $tax).

Common Misconception

Adding a parameter object just moves the problem. A parameter object does more than group fields — it gives the grouping a name, a place for related validation, and a stable API surface that can evolve without changing every call site.

Why It Matters

Functions with many parameters are hard to call correctly, impossible to extend without breaking callers, and signal that the function has too many responsibilities.

Common Mistakes

  • Adding a new optional parameter every time behaviour needs to vary — use a parameter object or strategy instead.
  • Boolean flag parameters that control internal branching — split into two separate functions.
  • Not using constructor promotion for objects that are just bundles of related parameters.
  • Accepting an array of 'options' instead of a typed parameter object — loses type safety and discoverability.

Code Examples

✗ Vulnerable
function createUser(
    string $name, string $email, string $role,
    bool $active, ?string $avatar, int $orgId
): User {}
✓ Fixed
// Introduce a parameter object
class CreateUserRequest {
    public function __construct(
        public readonly string  $name,
        public readonly string  $email,
        public readonly string  $role   = 'member',
        public readonly bool    $active = true,
        public readonly ?string $avatar = null,
        public readonly int     $orgId  = 0,
    ) {}
}

function createUser(CreateUserRequest $req): User {}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 42
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 2 pings M 2 pings T 0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 2 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Ahrefs 10 Amazonbot 9 Perplexity 9 Unknown AI 2 Majestic 1 Google 1 SEMrush 1
crawler 33
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Medium
⚡ Quick Fix
Group related parameters into a Parameter Object — function createUser(string $name, string $email, string $country, string $timezone) becomes createUser(UserRegistration $data)
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Function with 5+ parameters; many optional parameters; caller code hard to read because of many positional arguments
Auto-detectable: ✓ Yes phpmd phpcs phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✗ Manual fix Fix: Medium Context: Function Tests: Update

✓ schema.org compliant