Hướng dẫn phpstorm psr-2
PSR-2 đang dần là chuẩn Coding Convention phổ biển trong các dự án lập trình PHP, và đang được các PHP Framework nổi tiếng hỗ trợ như Laravel, Symfony 2… Nếu bạn đang sử dụng PHPStorm để lập trình, thì thủ thuật này sẽ giúp các bậu cấu hình format code PHP theo chuẩn PSR-2. Show
Cấu hình PSR-2 làm chuẩn code style mặc định cho PHPStormMở PHPStorm IDE lên. Vào [ File ] -> [ Setting ] -> [ Editor ] -> [ Code Style ] -> [ PHP ] – Scheme: Default IDE Chọn [ Predefined Style ] là: PSR1/PSR2 Hướng dẫn format code trong PHPStormChọn folder/file source code mà bạn muốn format, vào [ Code ] -> [ Reformat Code ]. Hoặc bấm tổ hợp phím Ctrl + Alt + L để format code. Nguồn: vinasupport.com Hướng dẫn format code theo chuẩn PSR-2 cho PHPStormPHPStorm IDE 13/05/2018 7,246 lượt xem 2 Bình luận PSR-2 đang dần là chuẩn Coding Convention phổ biển trong các dự án lập trình PHP, và đang được các PHP Framework nổi tiếng hỗ trợ như Laravel, Symfony 2… Nếu bạn đang sử dụng PHPStorm để lập trình, thì thủ thuật này sẽ giúp các bậu cấu hình format code PHP theo chuẩn PSR-2. […] PSR-2 đang dần trở thành chuẩn Coding Convention phổ biến trong các dự án lập trình PHP, và đang được hỗ trợ bởi các PHP Framework nổi tiếng như Laravel, Symfony 2… Nếu bạn đang sử dụng PHPStorm để lập trình thì thủ thuật này sẽ giúp ích cho bạn. Cấu hình định dạng mã PHP theo tiêu chuẩn PSR-2. Định cấu hình PSR-2 làm kiểu mã mặc định cho PHPStormMở PHPStorm IDE. Nhập [ File ] -> [ Setting ] -> [ Editor ] -> [ Code Style ] -> [ PHP ] – Cơ chế: IDE mặc định Lựa chọn [ Predefined Style ] được: PSR1 / PSR2 Hướng dẫn định dạng mã trong PHPStormChọn thư mục / File mã nguồn bạn muốn định dạng, đi tới [ Code ] -> [ Reformat Code ]. Hoặc nhấn Ctrl + Alt + L để định dạng mã. Nguồn: vinasupport.com PSR-2 đang dần là chuẩn Coding Convention phổ biển trong các dự án lập trình PHP, và đang được các PHP Framework nổi tiếng hỗ trợ như Laravel, Symfony 2… Nếu bạn đang sử dụng PHPStorm để lập trình, thì thủ thuật này sẽ giúp các bậu cấu hình format code PHP theo chuẩn PSR-2. Nội dung chính
Cấu hình PSR-2 làm chuẩn code style mặc định cho PHPStormMở PHPStorm IDE lên. Vào [ File ] -> [ Setting ] -> [ Editor ] -> [ Code Style ] -> [ PHP ] – Scheme: Default IDE Chọn [ Predefined Style ] là: PSR1/PSR2 Hướng dẫn format code trong PHPStormChọn folder/file source code mà bạn muốn format, vào [ Code ] -> [ Reformat Code ]. Hoặc bấm tổ hợp phím Ctrl + Alt + L để format code. Nguồn: vinasupport.com PhpStorm Laravel Code StyleThis is a code style based on PSR-2, as per Laravel's Contribution Guide InstallationConfiguration
folder : Drop the IDE Settings : Open your Settings ( NotesThis code style has been updated in line with Laravel 5.4, and matches Laravel's code styles as best as possible with PhpStorm's available configuration. Be mindful of the PHPDoc layout, which dictates Use this page to configure formatting options for PHP files. When you change these settings, the Preview pane shows how this will affect your code. Set from...Click this link to choose the base for the current language default code style from the list, that appears. The list contains two options:
This link appears in the upper-right corner of the language-specific code style page, when applicable. Click Reset to discard changes and return to the initial set of code style settings. Tabs and Indents
SpacesSelect or clear the checkboxes to have spaces inserted, not inserted, or removed in various PHP contexts. Before parentheses
Around operators
Before left brace
Before keywords
Within
In ternary operator (?:)
Other
Wrapping and BracesCommon options
Keep when reformattingUse these settings to configure exceptions that PhpStorm will make when reformatting the source code.
Braces placementIn this section, choose the position for opening braces in declarations of namespaces, classes, and functions, in loops, and in other constructs.
Extends/implements list
Extends/implements keywordIn this section, configure wrapping for the If you select Do not wrap, no wrapping will be applied; if you select Wrap if long or Wrap always, each keyword and each item in an abstract class Foo extends Class1 implements Class2, Class3 { } abstract class Foo extends Class1 implements Class2, Class3 { } Function declaration parameters
Function/constructor call arguments
Chained method calls
'if()' statement
for()/foreach() statements
'while()' statement
'do ... while()' statement
'switch' statement
'try' statement
Binary expressions
Assignment statement
Class property/constant groups
Ternary operation
Array initializer
Modifier list
Function return type
PHP opening tag
'match' expression
Group 'use'
Attributes
Attributes for parameters
Blank linesUse this tab to define where and how many blank lines you want PhpStorm to retain and insert in your code after reformatting. For each type of location, specify the number of blank lines to be inserted. The results are displayed in the preview pane.
PHPDocIn this tab, configure the code style to be applied inside PHPDoc comments. Learn more about documenting PHP code at PHPDoc comments.
Code ConversionIn this tab, configure the code style to be applied when performing automatic code conversion.
Code GenerationIn this tab, configure the code style to be applied when performing certain code generation and refactoring procedures.
ArrangementIn this tab, define a set of rules to rearrange your PHP code according to your preferences.
Last modified: 01 August 2022 |