title: Fix indentation of PHP code files with php-cs-fixer
body: <p>I have several hundreds of horribly indented PHP files with mixed tabs and spaces (and even mixed line endings, I suppose) I would like to fix them with <a href="http://cs.sensiolabs.org/" rel="noreferrer">php-cs-fixer</a> v2+.</p>
  
  <p>I have configured php-cs-fixer to my needs, and the code is scrubbed accordingly - except the indentation. I have tried a minimal configuration, like shown bellow, to pin down the problem. But I cannot get the indentation fixer straight:</p>
  
  <pre><code>return PhpCsFixer\Config::create()
      -&gt;setRules([
          '@PSR2' =&gt; true,
          'indentation_type' =&gt; true,
          'braces' =&gt; ['position_after_functions_and_oop_constructs' =&gt; 'same'],
      ])
      -&gt;setIndent("\t")
      -&gt;setLineEnding("\r\n")
  </code></pre>
  
  <p>Currently, I run this on my Windows box using the following command (here for a single file): </p>
  
  <pre><code>php-cs-fixer.bat fix new_user.php --config /full/windowspath/to/php_cs.dist
  </code></pre>
  
  <p>Just in case, the generated php_cs.cache (which contains the actually applied rules in JSON) file looks like this:</p>
  
  <pre><code>{
      "php": "5.6.31",
      "version": "2.6.0:v2.6.0#5642a36a60c11cdd01488d192541a89bb44a4abf",
      "rules": {
          "blank_line_after_namespace": true,
          "braces": {
              "position_after_functions_and_oop_constructs": "same"
          },
          "class_definition": true,
          "elseif": true,
          "function_declaration": true,
          "indentation_type": true,
          "line_ending": true,
          "lowercase_constants": true,
          "lowercase_keywords": true,
          "method_argument_space": {
              "ensure_fully_multiline": true
          },
          "no_break_comment": true,
          "no_closing_tag": true,
          "no_spaces_after_function_name": true,
          "no_spaces_inside_parenthesis": true,
          "no_trailing_whitespace": true,
          "no_trailing_whitespace_in_comment": true,
          "single_blank_line_at_eof": true,
          "single_class_element_per_statement": {
              "elements": ["property"]
          },
          "single_import_per_statement": true,
          "single_line_after_imports": true,
          "switch_case_semicolon_to_colon": true,
          "switch_case_space": true,
          "visibility_required": true,
          "encoding": true,
          "full_opening_tag": true
      },
      "hashes": {
          "new_students.org_.php": -151826318
      }
  }
  </code></pre>
  
  <p>And here is some badly indented sample file content.</p>
  
  <pre><code>&lt;?php
  session_start();
  
    include 'connect.php';
  include 'functions.php';    
  
  $test= "abc";
      $additional_studs = "";
      if (date('m') == 12 and $term='SP') {
          $yr_suffix = date('y') + 1;
      } else {
          $yr_suffix = date('y');
      }
  
  
      function dup_stud($id, $conn)
      {//...
  }
  
  $i = 0;
  </code></pre>
  
  <p>I am most annoyed be lines like <code>$test="abc";</code> &amp;  <code>include 'connect.php';</code> with one or more leading tabs/spaces that do not get properly indented.</p>
  
  <p>I am open to alternative approaches. Others must have faced formatting issues like this before.</p>
  
  <p>I have also tried NetBeans, which happens to format the source beautifully, but it is tedious to open each file manually and apply the source formatting via shortcut.</p>