1

Within our PHP project, our internal standard is to have all code inside of PHP indented by two spaces. Example:

<?php

   class Foo
   {
     ...

I must be confused on how to configure that, as I always receive an error that the the file has "2 spaces, expected 0" in the indent. How do I appropriately configure that?

Will Bonde
  • 560
  • 6
  • 19
  • You can configure how many spaces each indent level should be, but you can't configure PHPCS to force you to indent top-level code like that. It assumes that all code begins at the 0 column. – Greg Sherwood Aug 22 '17 at 01:17

1 Answers1

-1

You might use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer class from PHP-CS-Fixer.

If you are new to the tool and you want to make it really easy to start, the best is to use it with EasyCodingStandard like this:

# easy-coding-standard.neon
checkers:
    - PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer

Install it:

composer require --dev symplify\easy-coding-standard

Run it:

vendor/bin/ecs check src

Fix it:

vendor/bin/ecs check src --fix

Enjoy and let me know how it works for you.

If any troubles come up, just create an issue here. I'm happy to improve this tool as much as possible.

Tomas Votruba
  • 23,240
  • 9
  • 79
  • 115