{
    "slug": "long_parameter_list",
    "term": "Long Parameter List",
    "category": "quality",
    "difficulty": "beginner",
    "short": "A function or method with too many parameters — typically 4+ — making calls hard to read and easy to get wrong.",
    "long": "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).",
    "aliases": [
        "too many parameters",
        "parameter list smell",
        "excessive parameters"
    ],
    "tags": [
        "code-smell",
        "refactoring",
        "oop"
    ],
    "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."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "god_class",
        "code_smell"
    ],
    "prerequisites": [
        "data_clump",
        "value_object",
        "single_responsibility"
    ],
    "refs": [
        "https://refactoring.guru/smells/long-parameter-list"
    ],
    "bad_code": "function createUser(\n    string $name, string $email, string $role,\n    bool $active, ?string $avatar, int $orgId\n): User {}",
    "good_code": "// Introduce a parameter object\nclass CreateUserRequest {\n    public function __construct(\n        public readonly string  $name,\n        public readonly string  $email,\n        public readonly string  $role   = 'member',\n        public readonly bool    $active = true,\n        public readonly ?string $avatar = null,\n        public readonly int     $orgId  = 0,\n    ) {}\n}\n\nfunction createUser(CreateUserRequest $req): User {}",
    "quick_fix": "Group related parameters into a Parameter Object — function createUser(string $name, string $email, string $country, string $timezone) becomes createUser(UserRegistration $data)",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/long_parameter_list",
        "html_url": "https://codeclaritylab.com/glossary/long_parameter_list",
        "json_url": "https://codeclaritylab.com/glossary/long_parameter_list.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Long Parameter List](https://codeclaritylab.com/glossary/long_parameter_list) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/long_parameter_list"
            }
        }
    }
}