phpstorm 配置php-cs-fixer

本文介绍如何使用php_cs.dist文件配置PHP代码风格,包括允许高风险规则、禁用缓存、遵循PSR2标准、注释对齐、去除尾随空格、禁用短echo标签、移除未使用的导入、空白行处理、数组语法、导入排序算法等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

php_cs.dist 文件

<?php
return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setUsingCache(false)
    ->setRules([
        '@PSR2'                                 => true,
        'align_multiline_comment'               => true,
        'no_trailing_whitespace'                => true,
        'no_short_echo_tag'                     => true,
        'no_unused_imports'                     => true,
        'blank_line_after_namespace'            => true,
        'no_blank_lines_after_class_opening'    => true,
        'no_blank_lines_before_namespace'       => true,
        'no_blank_lines_after_phpdoc'           => true,
        'array_syntax'                          => ['syntax' => 'short'],
        'ordered_imports'                       => ['sortAlgorithm' => 'length'],
        'no_trailing_comma_in_singleline_array' => true,
        'no_useless_else'                       => true,
        'no_whitespace_before_comma_in_array'   => true,
        'trailing_comma_in_multiline_array'     => true,
    ])->setFinder(
        PhpCsFixer\Finder::create()
            ->exclude('tests/')
            ->in(__DIR__)
    );

PHPSTORM 设置

phpstorm 设置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值