Lỗi there is no document formatter for php file năm 2024
After installing as an extension with Visual Studio Code, this extension automatically formats your PHP code, in accordance with PSR-0, PSR-1, PSR-2 or Symfony style conventions. Show Features
SetupRefer to our wiki for a quick and easy guide on how to install the extension and its dependencies. ConfigurationWant custom keybindings? Need specific levels and fixers? Check out the wiki TroubleshootingSet up the extension, but can't get it to work? Check the Troubleshooting section. ContributeWant to add a feature or fix an error? Follow the Contribute section on the wiki to get started. No but really, like me — you might be struggling to get PHP formatting working in a way you’re satisfied with; one extension formats HTML but doesn’t format whole documents, and with others I don’t get any formatting at all. Probably user error — true. But if you’re still struggling with getting PHP formatting working in VS Code here’s what I finally figured out. Install ExtensionInside VS Code, open up the extension side-panel and search for php-cs-fixer. You’ll see a few with the same name so make sure you install the extension by the Junstyle. Install The PHP Fixer FileIn any folder use CURL to download the php fixer file to your working directory: $ curl -L https://cs.symfony.com/download/php-cs-fixer-v2.phar -o php-cs-fixer If for some reason CURL isn’t getting the file for you, go to the file’s Github Repo and download it however you want. Make sure the file has the executable flag by running: $ sudo chmod a+x php-cs-fixer Make sure you can run it by running: $ ./php-cs-fixer You should get the program name and version number. Move the file to a system directory that’s in the PATH: $ sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer Create a Config FileIn your terminal — create and edit a config file in your user directory: $ sublime ~/.php_cs Use your favorite text editor. Paste this config code in the editor and save:
If you like your fat arrows aligned change this settings to true. Save and Exit. Point VS Code To Your Config FileOpen VS Code Preferences > Settings. Search for php-cs-fixer. About 4 options down you’ll see a field for the config file path. Enter the absolute path like so: Set Extension as Default FormatterOpen any .php file in VS Code right click in the editor and click on Format Document. If that formatted your code then great! If you have other formatters associated with PHP then click on Configurein the dialog in the bottom right and select php cs fixer from the dropdown. Success? If all went well you should see your PHP cleaned up a bit. You’ll probably wanna tweak that config file. The array syntax is set to short which bugs me and you’ll probably be bugged by a few things too. |