skip to Main Content

Output of phpcs is telling me to put 8 spaces inside the if

class bla
{
  private function wop()
  {
    if (true) {
      $something = 'yes'; // 6 spaces indent is what I want!
    }
  }
}

indented at least once; expected at least 8 spaces, but found 6
(PSR12.ControlStructures.ControlStructureSpacing.LineIndent) Each line in a
multi-line control structure must be

How do I tell phpcs that I prefer 6 spaces?

2

Answers


  1. Indentation size is part of PSR-12 so it isn’t possible to fine-tune it if you want to comply with that coding style:

    2.4 Indenting

    Code MUST use an indent of 4 spaces for each indent level, and MUST
    NOT use tabs for indenting.

    Login or Signup to reply.
  2. How do I tell phpcs that I prefer 6 spaces?

    Look into the default rules that ship with phpcs itself. There is an easy system where you can pick and play with every single rule and their parameters.

    IIRC there is one folder with many standard whitespace rules, it should be re-using the existing rule for the indent and setting your preference of six spaces via parameters (these are XML Documents).

    Btw. the whitespace handling is pretty superior in phpcs/phpcbf, I’ve not seen any other tooling that came close.

    Let me know if this information was already helpful, otherwise ask in comments for clarifiations.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search