Formatting

PHP Tools for Visual Studio provides powerful formatting options that help developers improve code readability and consistency. In this documentation, we will discuss the various formatting options available in PHP Tools for Visual Studio and how to configure them to meet your specific coding style requirements.

To configure formatting, use the Formatting Options page and its subpages (Indentation, New Lines, Spacing, and Wrapping) to set options for formatting code in the code editor.

To access this options page, choose Tools | Options from the menu bar. In the Options dialog box, choose 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.