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

Mixed Indentation

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 term's detection_hints.tools list includes php-cs-fixer, phpcs, and editorconfig — all standard, commonly configured tools in PHP projects that catch mixed indentation automatically. It doesn't require a specialist tool; any baseline linter setup catches it.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix explicitly states running php-cs-fixer with the indentation_type fixer converts everything in one shot, plus adding .editorconfig to prevent recurrence. This is a single automated command, not a manual refactor.

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

Closest to 'localised tax' (b3). Mixed indentation imposes a persistent but contained tax: it creates diff noise and editor misalignment across the team, but it doesn't shape architecture or cross-cut business logic. The applies_to covers all contexts (web, cli, queue-worker), giving it slightly wider reach than a single-component issue, but the impact is purely presentational/tooling, not structural.

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

Closest to 'notable trap' (t5). The misconception field explicitly states that developers believe 'tabs vs spaces is purely a style debate with no technical consequence,' when it actually causes diff noise, editor misalignment, and parse errors in Python/YAML. This is a documented, well-known gotcha that many developers learn the hard way — a t5 notable trap rather than a catastrophic one since the consequences are usually visible once tools are configured.

About DEBT scoring →

Also Known As

tab vs space inconsistent indentation mixed tabs spaces

TL;DR

A file using both tabs and spaces for indentation — causes misalignment across editors and tools.

Explanation

Mixing tabs and spaces is the most common cause of "works on my machine" formatting bugs. Different editors and tools render tabs as different widths (2, 4, or 8 spaces), making mixed files appear correctly in one editor and badly indented in another. PHP-FIG PSR-12 mandates 4-space indentation with no tabs. Most editors can be configured to insert spaces on Tab keypress; php-cs-fixer and phpcs can auto-fix mixed indentation.

Common Misconception

Tabs vs spaces is purely a style debate with no technical consequence. Mixed indentation causes genuine diff noise, breaks alignment in editors configured differently, and causes parse errors in Python and YAML — automated formatters eliminate the debate entirely.

Why It Matters

Mixed tabs and spaces cause code to display differently across editors and tools — diffs show false changes, and some languages (Python) reject it outright.

Common Mistakes

  • Copying code from the web that uses different indentation than your project.
  • IDE auto-format that mixes tabs and spaces on different lines.
  • Not having .editorconfig or a linter enforcing consistent indentation.
  • Not converting all tabs to spaces (or vice versa) when inheriting legacy code.

Code Examples

✗ Vulnerable
function calculate($a, $b) {
    $result = $a + $b;    // spaces
	$result *= 2;          // tab — mixed!
    return $result;        // spaces again
    // Looks fine in one editor, broken in another
}
✓ Fixed
// PSR-12 mandates 4 spaces — never tabs, never mixed

// .editorconfig (applies to all editors in the project):
[*.php]
indent_style = space
indent_size  = 4

// Auto-fix mixed indentation:
$ vendor/bin/phpcbf --standard=PSR12 src/

// phpcs to detect:
$ vendor/bin/phpcs --standard=PSR12 src/

// Example — correct:
class OrderService {
    public function place(Order \$order): Invoice {
        \$total = \$order->calculateTotal();
        return new Invoice(\$total);
    }
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 25
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 1 ping S 0 pings S 1 ping 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 1 ping 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 7 Perplexity 4 Ahrefs 3 Unknown AI 2 ChatGPT 2 Google 1
crawler 18 crawler_json 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Run php-cs-fixer with the indentation_type fixer to convert everything to 4 spaces in one shot — then add an .editorconfig to prevent the problem recurring
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Git diff showing whitespace-only changes; mix of tabs and spaces in same PHP file; inconsistent 2-space and 4-space indentation
Auto-detectable: ✓ Yes php-cs-fixer phpcs editorconfig
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: File

✓ schema.org compliant