Last active
May 7, 2024 07:25
-
-
Save hankz1108/bffd1971e3b1f428b0c7b4cdfcff3e55 to your computer and use it in GitHub Desktop.
My Laravel PHP CS Fixer Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$rules = [ | |
// 繼承Symfony的規則 | |
'@Symfony' => true, | |
// 確保陣列中的逗號後只有一個空格 | |
'whitespace_after_comma_in_array' => ['ensure_single_space' => true], | |
// 強制轉型運算子的右側沒有空格 | |
// 'cast_spaces' => ['space' => 'none'], | |
// 對 classes/interfaces/traits/enums 進行排序 | |
'ordered_class_elements' => true, | |
// list() 函數的語法強制改為[$a, $b] = $array; | |
'list_syntax' => true, | |
// 移除空回傳語句(ex: return;) | |
// 'no_useless_return' => true, | |
// 將雙引號中隱式變數轉換改為明確變數(ex: "My name is $name !" => "My name is {$name} !") | |
'explicit_string_variable' => true, | |
// 是否強制使用Yoda Style | |
'yoda_style' => false, | |
'no_useless_else' => true, | |
'global_namespace_import' => true, | |
'combine_consecutive_unsets' => true, | |
'declare_equal_normalize' => ['space' => 'single'], | |
'concat_space' => ['spacing' => 'one'], | |
'ternary_to_null_coalescing' => true, | |
'multiline_whitespace_before_semicolons' => true, | |
'array_indentation' => true, | |
'blank_line_before_statement' => true, | |
'method_chaining_indentation' => true, | |
'phpdoc_to_comment' => false, | |
'phpdoc_var_annotation_correct_order' => true, | |
]; | |
$finder = PhpCsFixer\Finder::create(); | |
// ignore laravel blade file | |
$finder->exclude(['vendor']) | |
->notName('*.blade.php'); | |
return (new PhpCsFixer\Config()) | |
->setRules($rules) | |
->setIndent(' ') | |
->setLineEnding("\n") | |
->setFinder($finder); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment