久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網
      最全最豐富的資訊網站

      圖文詳解PHPStorm實現(xiàn)自動執(zhí)行代碼格式化

      在我們日常開發(fā)中,一定少不了 PHP CS Fixer 來幫我們統(tǒng)一代碼風格,但是PHP CS Fixer 不像 ESLint 一樣,可以在 PHPStorm 中在保存時自動執(zhí)行。

      圖文詳解PHPStorm實現(xiàn)自動執(zhí)行代碼格式化

      PHPStorm 并沒有為我們提供可執(zhí)行 PHP CS Fixer 的選項,「重新格式化代碼」大部分時都不能滿足我們的需求。


      為此我們需要在 PHPStorm 中添加一個 「File Watcher」來自動執(zhí)行代碼格式化。

      1.首先全局安裝 PHP CS Fixer

      composer global require friendsofphp/php-cs-fixer
      登錄后復制

      2.執(zhí)行

      php-cs-fixer
      登錄后復制

      圖文詳解PHPStorm實現(xiàn)自動執(zhí)行代碼格式化

      代表安裝成功了,如果提示命令未找到,那么你需要將全局 composer vendor 目錄添加到全局變量,我用的是 zsh,這里改成你自己的。

      echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc
      登錄后復制

      3.打開 PHPStorm,添加自定義文件

      圖文詳解PHPStorm實現(xiàn)自動執(zhí)行代碼格式化

      程序文件地址,命令行輸入,并填入

      which php-cs-fixer
      登錄后復制

      圖文詳解PHPStorm實現(xiàn)自動執(zhí)行代碼格式化

      參數(shù)欄:

      fix $FileDir$/$FileName$
      登錄后復制

      到這就搞定了,現(xiàn)在每當我們保存時就會自動執(zhí)行 php-cs-fixer,現(xiàn)在還有一個問題,是可能每個項目有不同的 .php-cs.dist 格式化配置文件,以上的配置是使用了全局 php-cs-fixer 配置文件,如果要使用單獨的配置文件,需要修改配置如下:

      fix --config=$ProjectFileDir$/.php-cs.dist $FileDir$/$FileName$
      登錄后復制

      .php-cs.dist 通常放在項目根目錄。

      最后附上 .php-cs.dist 配置文件

      <?php $header = <<<'EOF'EOF;$finder =  PhpCsFixerFinder::create()             ->exclude('tests/Fixtures')   //排除文件             ->in(__DIR__);return PhpCsFixerConfig::create()     ->setRiskyAllowed(true)     ->setRules([         '@PSR2'                                 => true,         '@Symfony:risky'                        => true,         'array_syntax'                          => ['syntax' => 'short'],         'combine_consecutive_unsets'            => true,   //多個unset,合并成一個         // one should use PHPUnit methods to set up expected exception instead of annotations         'general_phpdoc_annotation_remove'      => ['expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'], //phpdocs中應該省略已經配置的注釋         //'header_comment'                        => array('header' => $header), //添加,替換或者刪除 header 注釋。         'heredoc_to_nowdoc'                     => true,     //刪除配置中多余的空行和/或者空行。         'no_extra_consecutive_blank_lines'      => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],         'no_unreachable_default_argument_value' => false, //在函數(shù)參數(shù)中,不能有默認值在非缺省值之前的參數(shù)。有風險         'no_useless_else'                       => true,  //刪除無用的eles         'no_useless_return'                     => true,  //刪除函數(shù)末尾無用的return         'no_empty_phpdoc'                       => true,  // 刪除空注釋         'no_empty_statement'                    => true,  //刪除多余的分號         'no_leading_namespace_whitespace'       => true,  //刪除namespace聲明行包含前導空格         'no_spaces_inside_parenthesis'          => true,  //刪除括號后內兩端的空格         'no_trailing_whitespace'                => true,  //刪除非空白行末尾的空白         'no_unused_imports'                     => true,  //刪除未使用的use語句         'no_whitespace_before_comma_in_array'   => true,  //刪除數(shù)組聲明中,每個逗號前的空格         'no_whitespace_in_blank_line'           => true,  //刪除空白行末尾的空白         'ordered_class_elements'                => false, //class elements排序         'ordered_imports'                       => false, // use 排序         'phpdoc_add_missing_param_annotation'   => true,   //添加缺少的 Phpdoc @param參數(shù)         'phpdoc_trim'                           => true,         //   'phpdoc_trim_consecutive_blank_line_separation' => true, //刪除在摘要之后和PHPDoc中的描述之后,多余的空行。         'phpdoc_order'                          => true,         'psr4'                                  => true,         // 'strict_comparison'                     => true,   //嚴格比較,會修改代碼有風險         //'strict_param'                          => true,         'ternary_operator_spaces'               => true,  //標準化三元運算的格式         'ternary_to_null_coalescing'            => true,  //盡可能使用null合并運算符??。需要PHP> = 7.0。         'whitespace_after_comma_in_array'       => true, // 在數(shù)組聲明中,每個逗號后必須有一個空格         'trim_array_spaces'                     => true,  //刪除數(shù)組首或尾隨單行空格         'align_multiline_comment'               => [                   //每行多行 DocComments 必須有一個星號(PSR-5),并且必須與第一行對齊。             'comment_type' => 'phpdocs_only'         ],         'array_indentation'                 => true,  //數(shù)組的每個元素必須縮進一次     ])     ->setFinder($finder);
      登錄后復制

      推薦學習:《PHPstorm使用教程》

      贊(0)
      分享到: 更多 (0)
      網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號