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

Inconsistent Indentation

style Beginner

Also Known As

mixed tabs spaces indentation tab width

TL;DR

Mixing tabs and spaces, or using varying numbers of spaces for indentation — causes visual misalignment across editors and makes diffs noisy.

Explanation

PSR-1/PSR-12 mandates 4 spaces per indent level, no tabs. Inconsistent indentation typically enters codebases when developers with different editor settings commit without formatting, or when code is pasted from an external source. .editorconfig and PHP-CS-Fixer enforce consistent indentation automatically. Mixed tabs and spaces are the worst offender — the visual appearance depends entirely on the editor's tab-width setting.

Common Misconception

Tabs are better than spaces because they are configurable — configurability is the problem: code with tabs looks different in every editor, breaking visual alignment of code reviewed by a team.

Why It Matters

Mixed indentation turns every line of a reformatted file into a diff change, obscuring the actual logic changes in code review — automated enforcement eliminates this entirely.

Common Mistakes

  • Pasting code from Stack Overflow or documentation that uses 2-space or tab indentation.
  • Editor auto-indent set to tabs in a spaces project.
  • Using 2 spaces for nested closures 'to save horizontal space'.
  • Not having .editorconfig in the repository to enforce consistent settings across all editors.

Code Examples

✗ Vulnerable
<?php
function calculate(int $x): int
{
	$result = 0;        // Tab
    if ($x > 0) {     // 4 spaces
      $result = $x;   // 2 spaces — 3 different styles in 4 lines
    }
    return $result;
}
✓ Fixed
// .editorconfig in project root:
[*.php]
indent_style = space
indent_size = 4

// .php-cs-fixer.dist.php:
'indentation_type' => true,  // Enforces 4-space indentation

<?php
function calculate(int $x): int
{
    $result = 0;
    if ($x > 0) {
        $result = $x;
    }
    return $result;
}

Added 16 Mar 2026
Edited 22 Mar 2026
Views 34
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 2 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 14 Perplexity 8 Google 3 Ahrefs 2 Unknown AI 2 Majestic 1
crawler 30
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Standardise on 4 spaces (PSR-12) and enforce with php-cs-fixer and .editorconfig — mixed indentation is invisible in some editors and breaks diffs
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Mix of tabs and spaces in PHP files; 2-space and 4-space mixed in same project; git diff showing whitespace-only changes
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