Umgebung
PhpStormcomposer global require friendsofphp/php-cs-fixer
Erstellen Sie im Projektstammpfad eine neue Datei: .php-cs-fixer.php mit folgendem Inhalt:
<?phpuse PhpCsFixer\Config;use PhpCsFixer\Finder;$rules = [ '@PHP80Migration' => true, 'ordered_imports' => [ 'sort_algorithm' => 'alpha', ], 'class_attributes_separation' => [ 'elements' => [ 'const' => 'one', 'method' => 'one', 'property' => 'one', ], ],];$finder = Finder::create() ->in([ __DIR__.'/app', __DIR__.'/config', __DIR__.'/database', __DIR__.'/resources', __DIR__.'/routes', __DIR__.'/tests', ]) ->name('*.php') ->notName('*.blade.php') ->ignoreDotFiles(true) ->ignoreVCS(true);return (new Config()) ->setFinder($finder) ->setRules($rules) ->setRiskyAllowed(true) ->setUsingCache(true);
Dann richten Sie
in PhpStorm ein: php-cs-fixer (self Like it)
Dateityp: PHP
Programm: php-cs-fixer/Users/dogeow/.composer/vendor/bin/php-cs-fixer fix /Users/dogeow/PhpstormProjects/antic-api/routes/console.php -vvv --diff Cannot load Xdebug - it was already loaded PHP CS Fixer 3.3.2 Trinacria by Fabien Potencier and Dariusz Ruminski Runtime: PHP 8.0.8 Loaded config default from "/Users/dogeow/PhpstormProjects/antic-api/.php-cs-fixer.php". Using cache file ".php-cs-fixer.cache". Paths from configuration file have been overridden by paths provided as command arguments. F 1 / 1 (100%) Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error 1) routes/console.php (assign_null_coalescing_to_coalesce_equal) ---------- begin diff ---------- --- /Users/dogeow/PhpstormProjects/antic-api/routes/console.php +++ /Users/dogeow/PhpstormProjects/antic-api/routes/console.php @@ -90,5 +90,5 @@ }); Artisan::command('test', function () { - $taskTag['name'] = $taskTag['name'] ?? 'url'; + $taskTag['name'] ??= 'url'; }); ----------- end diff ----------- Fixed all files in 0.024 seconds, 14.000 MB memory used 进程已结束,退出代码为 0
Empfohlenes Lernen: „PHP-Video-Tutorial
“Das obige ist der detaillierte Inhalt vonPHP-CS-Fixer ist sehr nützlich! Kann den Codestil automatisch korrigieren~. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!