Skip to content

Formatting#

PHP Tools for Visual Studio includes a code formatter that helps keep your PHP code readable and consistent. You can configure when formatting is applied automatically and choose from predefined code styles (such as PSR-12, PSR-2, Laravel, WordPress, and others) or customize individual formatting rules.

To configure formatting, open the Formatting options page: choose Tools | Options from the menu bar, then navigate to Text Editor | PHP | Formatting.

Formatting (General) page#

These settings allow you to configure when formatting is applied automatically or preconfigure code style.

Automatic formatting#

Automatic formatting options help you format your code as you type, rather than explicitly formatting the whole document later. By enabling automatic formatting, PHP Tools for Visual Studio can save you time and effort while also ensuring that your code is properly formatted and easy to read.

Label Description
Format completed statement on ; Formats statements according to the selected formatting options when you complete them with a semicolon.
Format completed statement on : Formats statements according to the selected formatting options when you complete them with a colon.
Format completed block on } Formats code blocks according to the selected formatting options when you complete them with a closing curly brace.
Format on paste Formats pasted code according to the selected formatting options immediately upon pasting.
Format moved lines.

Preconfigured Code Styles#

PHP Tools for Visual Studio includes a set of preconfigured code styles that you can choose from. These code styles are based on popular PHP coding standards.

These code styles are supported:

  • Allman
  • Drupal
  • K&R
  • Laravel
  • PSR-2
  • PSR-12
  • WordPress

Formatting options#

The formatting options in PHP Tools for Visual Studio include spacing options, wrapping options, new lines or indent options. Each of these options can be configured individually, or you can choose from a set of preconfigured code styles.