{
    "slug": "inline_temp_refactor",
    "term": "Inline Temp Variable Refactoring",
    "category": "quality",
    "difficulty": "beginner",
    "short": "Inline Temp removes a temporary variable used only once when its name adds no clarity — replacing the variable reference with its expression directly.",
    "long": "A temporary variable assigned once and used once can often be inlined if the expression is already self-explanatory. Especially common in boolean checks: $isEligible = $user->age >= 18; return $isEligible; → return $user->age >= 18; But: keep the temp if it (1) clarifies a complex expression with a meaningful name, (2) is used more than once, (3) makes a slow operation happen once. Inline Temp is the inverse of Extract Variable. It reduces line count but should only be done when clarity is preserved or improved.",
    "aliases": [],
    "tags": [
        "quality",
        "refactoring",
        "readability",
        "clean-code"
    ],
    "misconception": "Inlining temp variables always improves code — only inline when the expression is already clear. Complex expressions benefit from a descriptive variable name.",
    "why_it_matters": "Unnecessary temp variables add cognitive overhead — each variable requires tracking. Removing them simplifies control flow.",
    "common_mistakes": [
        "Inlining complex expressions that need a name to be understandable.",
        "Inlining variables used in multiple places — creates duplication.",
        "Not inlining obvious single-use variables that add no information."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "cyclomatic_reduction",
        "boolean_flags_refactor"
    ],
    "prerequisites": [
        "extract_method"
    ],
    "refs": [
        "https://refactoring.guru/inline-temp"
    ],
    "bad_code": "$result = calculateTotal($items);\nreturn $result; // $result adds nothing",
    "good_code": "return calculateTotal($items); // Direct, no noise\n\n// But KEEP the temp when it adds meaning:\n$isEligibleForDiscount = $user->isPremium() && $order->total > 100;\nreturn $isEligibleForDiscount; // Name clarifies the condition",
    "quick_fix": "Remove temp variables used exactly once when the expression is self-explanatory. Keep temps that name complex conditions or prevent duplicate computation.",
    "severity": "info",
    "effort": "low",
    "created": "2026-03-23",
    "updated": "2026-03-23",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/inline_temp_refactor",
        "html_url": "https://codeclaritylab.com/glossary/inline_temp_refactor",
        "json_url": "https://codeclaritylab.com/glossary/inline_temp_refactor.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": "[Inline Temp Variable Refactoring](https://codeclaritylab.com/glossary/inline_temp_refactor) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/inline_temp_refactor"
            }
        }
    }
}