标签: php-cs-fixer

在PHP-CS-Fixer中使用选项卡进行缩进

如何配置PHP-CS-Fixer以使用制表符进行缩进?

我可以看到indentation_type修复工具

* indentation_type [@PSR2, @Symfony]
  | Code MUST use configured indentation type.
Run Code Online (Sandbox Code Playgroud)

但是如何配置缩进类型?如果我尝试设置'indentation_type' => 'tab',,我收到错误

[indentation_type] Is not configurable.
Run Code Online (Sandbox Code Playgroud)

php php-cs-fixer

8
推荐指数
1
解决办法
2058
查看次数

php-cs-fixer : 保持大括号在函数声明的同一行

Php cs fixer 正在做:

function foobar()
{
....
}
Run Code Online (Sandbox Code Playgroud)

而且我要:

function foobar() {
....
}
Run Code Online (Sandbox Code Playgroud)

我看不到在我的配置.php_cs文件或https://github.com/FriendsOfPHP/PHP-CS-Fixer上将大括号保持在同一行的配置是什么。我正在使用 php-cs-fixerV2。

我的配置文件:https : //pastebin.com/v03v9Lb5

php php-cs-fixer

7
推荐指数
2
解决办法
3911
查看次数

php cs fixer,如何运行有风险的规则?

PHP-CS-FIXER

嗨,我第一次使用php-cs-fixer.我知道我们必须设置一个.php_cs.dist文件

这是我从php-cs-fixer的git存储库获取的示例文件.

$finder = PhpCsFixer\Finder::create()
    ->exclude('somedir')
    ->in(__DIR__);

return PhpCsFixer\Config::create()
    ->setRules(array(
        '@Symfony' => true,
        'full_opening_tag' => false,
    ))
    ->setFinder($finder);
Run Code Online (Sandbox Code Playgroud)

当我在CLI上运行此命令时

php-cs-fixer fix --config = .php_cs.dist --allow-risky

这是说我需要给出 - 允许风险的选项,但在文档中没有提及如何设置允许风险的选项帮助我的人.越快越好.

我的问题 如何运行有风险的规则?因为没有提到如何在php-cs-fixer中使用允许冒险的规则.

php configuration command-line-interface php-cs-fixer

6
推荐指数
2
解决办法
1984
查看次数

如何为php-cs-fixer创建自定义规则集?

如何创建要由fix带选项的命令运行的自定义规则集--rules=@custom

@PSR1@PSR2@Symfony@PHP56Migration@PHP70Migration@PHP71Migration制成。

php-cs-fixer版本:2.2.3

仅通过插入供应商代码- vendor/friendsofphp/php-cs-fixer/src/RuleSet.php

private $setDefinitions = array(
        '@custom' => [
        'some_custom_fixer` => true,
        ]
)
Run Code Online (Sandbox Code Playgroud)

符合我的预期,但RuleSet确实如此final classsetDefinitions使用自定义配置时,有没有方法可以覆盖或扩展.php_cs

php php-cs-fixer

6
推荐指数
1
解决办法
1533
查看次数

PHP7在所有标准php函数中添加斜杠php-cs-fixer规则

继承了PHP7项目。以前的开发人员甚至为\ true都对所有标准PHP函数添加了斜线。有什么理由吗?

一些例子:

\array_push($tags, 'master');

if ($result === \true) {}

$year = \date('Y');
Run Code Online (Sandbox Code Playgroud)

切换此选项的php-cs-fixer规则是什么?

php php-7 php-cs-fixer

6
推荐指数
2
解决办法
363
查看次数

Symfony Finder 用 glob 排除

我正在尝试运行 PHP CS Fixer,我认为它基于 Symfony(我不熟悉),并且在排除某些路径时遇到问题。

我的设置如下:

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude('lib/adodb')
    ->exclude('lib/bbcode')
    ->exclude('lib/joomla')
    ->exclude('lib/JSON')
    ->exclude('lib/pear')
    ->exclude('lib/phpass')
    ->exclude('lib/smarty')
    ->exclude('lib/smtp')
    ->exclude('modules/*/lib')  
    ->name('*.class')
    ->name('*.inc')
    ->name('*.php')
;
Run Code Online (Sandbox Code Playgroud)

基本上,我想排除:

modules/ANYNAME/lib/ANYFILE
modules/ANYNAME/lib/ANYSUBDIR/ANYFILE
Run Code Online (Sandbox Code Playgroud)

但我发现这->exclude('modules/*/lib')条线没有抓住这些。例如,modules/somemodule/lib/somefile.inc仍在处理中。

我原以为这是因为我有过,->name('*.inc')但无论有没有那条线,它似乎都会发生。

另一个排除工作正常,除了->exclude('modules/*/lib')一个。

任何指针?

** 更正/更新 **

似乎问题出在名称选择器上。似乎不允许选择*.incusingname例如,然后尝试排除在modules/xyz/lib.

克服这将解决我的问题

php symfony symfony-finder php-cs-fixer

5
推荐指数
1
解决办法
1172
查看次数

使用php-cs-fixer修复PHP代码文件的缩进

我有数百个包含混合制表符和空格的可怕缩进PHP文件(我想还包括混合的行尾),我想用php-cs-fixer v2 + 修复它们。

我已经根据需要配置了php-cs-fixer,并且相应地清理了代码-除了缩进。我尝试了一种最小化的配置,如下面所示,以解决问题。但是我无法直接使用缩进修复程序:

return PhpCsFixer\Config::create()
    ->setRules([
        '@PSR2' => true,
        'indentation_type' => true,
        'braces' => ['position_after_functions_and_oop_constructs' => 'same'],
    ])
    ->setIndent("\t")
    ->setLineEnding("\r\n")
Run Code Online (Sandbox Code Playgroud)

当前,我使用以下命令在Windows框上运行此命令(此处为单个文件):

php-cs-fixer.bat fix new_user.php --config /full/windowspath/to/php_cs.dist
Run Code Online (Sandbox Code Playgroud)

以防万一,生成的php_cs.cache(包含JSON中实际应用的规则)文件如下所示:

{
    "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": …
Run Code Online (Sandbox Code Playgroud)

php code-formatting php-cs-fixer

5
推荐指数
1
解决办法
3740
查看次数

如何将 PHP 代码的花括号自动格式化为 VS Code 中的新行

我目前正在使用 VS Code 的最新版本 1.41.1(在撰写本文时)。

我已经安装了 PHP CS Fixer 来自动格式化我的代码。然而,有一种我不喜欢的行为。它总是像这样格式化代码:

if (condition) {
    // code...
} else {
    // code
}
Run Code Online (Sandbox Code Playgroud)

但这并没有给我很好的可读性。

我想实现这一目标:

if (condition)
{
    // code...
}
else
{
    // code
}
Run Code Online (Sandbox Code Playgroud)

在 VS Code 中是否有任何扩展支持 PHP 的这种代码格式?或者 PHP CS Fixer 中是否有任何选项可以跳过这些大括号的格式?还有其他选择吗?

php visual-studio-code php-cs-fixer

4
推荐指数
1
解决办法
948
查看次数

PHP CS Fixer File Watcher 导致 PHPStorm 中的文件缓存冲突

我使用定义为这样的文件观察器

在此输入图像描述

这是我的watchers.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<TaskOptions>
  <TaskOptions>
    <option name="arguments" value="fix $FileDir$/$FileName$ --verbose " />
    <option name="checkSyntaxErrors" value="false" />
    <option name="description" />
    <option name="exitCodeBehavior" value="ERROR" />
    <option name="fileExtension" value="php" />
    <option name="immediateSync" value="true" />
    <option name="name" value="PHP CS Fixer" />
    <option name="output" value="" />
    <option name="outputFilters">
      <array />
    </option>
    <option name="outputFromStdout" value="false" />
    <option name="program" value="/usr/local/bin/php-cs-fixer" />
    <option name="scopeName" value="Project Files" />
    <option name="trackOnlyRoot" value="false" />
    <option name="workingDir" value="$ProjectFileDir$" />
    <envs />
  </TaskOptions>
</TaskOptions>
Run Code Online (Sandbox Code Playgroud)

执行自动保存时,有时我会收到一条有关内存和磁盘更改之间冲突的错误消息。

在此输入图像描述

我该如何解决这个问题?

php phpstorm file-watcher php-cs-fixer

3
推荐指数
1
解决办法
1723
查看次数

选项“align_double_arrow”、“align_equals”不存在。定义的选项有:“默认”、“运算符”

在我的 php-cs-fixer.php 中我有这一行:

'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => true],
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:

The options "align_double_arrow", "align_equals" do not exist. Defined options are: "default", "operators". 
Run Code Online (Sandbox Code Playgroud)

你能帮助我们operators and default实现同样的目标吗?

php php-cs-fixer

3
推荐指数
1
解决办法
1131
查看次数