简体   繁体   English

内缩进

[英]Indentation inside of <?php tag with PHP Code Sniffer

Within our PHP project, our internal standard is to have all code inside of PHP indented by two spaces. 在我们的PHP项目中,我们的内部标准是将PHP内部的所有代码缩进两个空格。 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. 我对如何配置它感到困惑,因为我总是收到错误消息,该文件的缩进为“ 2个空格,预期为0”。 How do I appropriately configure that? 如何正确配置?

You might use PhpCsFixer\\Fixer\\PhpTag\\BlankLineAfterOpeningTagFixer class from PHP-CS-Fixer . 您可以使用 PHP-CS-Fixer中的 PhpCsFixer\\Fixer\\PhpTag\\BlankLineAfterOpeningTagFixer

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: 如果您是该工具的新手,并且想使其真正易于启动,则最好将其与EasyCodingStandard一起使用,如下所示:

# 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. 我很高兴尽可能地改进此工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM