Visual Studio Code: Difference between revisions

From Joomla! Documentation

mNo edit summary
Cmb (talk | contribs)
Xdebug 2 is no longer supported.
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude><languages /></noinclude>
<translate>
<!--T:2-->
[https://code.visualstudio.com/ Visual Studio Code (VSCode)] is a source code editor developed by Microsoft for Windows, Linux and MacOS (including M1 Macs). It includes support for debugging, embedded Git control and GitHub, syntax highlighting, intelligent code completion, snippets, and code refactoring.


[https://code.visualstudio.com/ Visual Studio Code] is a source code editor developed by Microsoft for Windows, Linux and macOS. It includes support for debugging, embedded Git control and GitHub, syntax highlighting, intelligent code completion, snippets, and code refactoring.
<!--T:3-->
The main characteristic of the editor is that it is extensible and it has a huge collection of extensions maintained by users and by Microsoft itself. See details at the [https://marketplace.visualstudio.com/ VSCode Extensions for Visual Studio Code] website.


The main characteristic of the editor is that it is extensible and it has a huge collection of extensions maintained by users. The '''Extensions for the Visual Studio family of products''' can be found here: https://marketplace.visualstudio.com/VSCode.
<!--T:70-->
As a general introduction, this is a presentation about the topic [https://www.renekreijveld.nl/slides/juglondon/vscode.pdf Joomla Development with Visual Studio Code], by René Kreijveld, Joomla developer Destiny B.V. Joomla User Group London, 16th march 2021.


In this page, we detail a list of recommended extensions to configure VSCode to support PHP and Joomla:
<!--T:4-->
On this page, we detail a list of recommended extensions to configure VSCode to support PHP and Joomla.


* '''PHP Debug''' [https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug felixfbecker.php-debug]. Debug support for PHP with XDebug.
<!--T:5-->
This is a list of extensions to support PHP on VSCode:
 
<!--T:6-->
* '''PHP Debug''' [https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug felixfbecker.php-debug]. Debug support for PHP with Xdebug.
* '''phpcs''' [https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs ikappas.phpcs]. PHP CodeSniffer for Visual Studio Code.
* '''phpcs''' [https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs ikappas.phpcs]. PHP CodeSniffer for Visual Studio Code.
* '''PHP Intelephense''' [https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client bmewburn.vscode-intelephense-client]. PHP code intelligence for Visual Studio Code.
* '''PHP Intelephense''' [https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client bmewburn.vscode-intelephense-client]. PHP code intelligence for Visual Studio Code. Alternative: ''PHP IntelliSense'' [https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense felixfbecker.php-intellisense]
* '''PHPUnit''' [https://marketplace.visualstudio.com/items?itemName=emallin.phpunit emallin.phpunit]. Run PHPUnit tests from VSCode.
* '''PHPUnit''' [https://marketplace.visualstudio.com/items?itemName=emallin.phpunit emallin.phpunit]. Run PHPUnit tests from VSCode.
* '''php cs fixer''' [https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer junstyle.php-cs-fixer]: In case of opting for the [https://www.php-fig.org/psr/psr-2/ PSR-2: Coding Style Guide]). PHP CS Fixer extension for VS Code, php formatter, php code beautify tool, format html.
* '''phpfmt''' [https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt kokororin.vscode-phpfmt]. The missing phpfmt extension for Visual Studio Code. The phpfmt formatter can parse and format even a PHP file version 4 if needed.
* '''php cs fixer''' [https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer junstyle.php-cs-fixer]: In case of opting for the [https://www.php-fig.org/psr/psr-2/ PSR-2: Coding Style Guide]). PHP CS Fixer extension for VS Code, PHP formatter, PHP code beautify tool, format HTML.
* '''PHP Namespace Resolver''' [https://marketplace.visualstudio.com/items?itemName=MehediDracula.php-namespace-resolver MehediDracula.php-namespace-resolver]: PHP Namespace Resolver can import and expand your class. You can also sort your imported classes by line length or in alphabetical order.
* '''PHP Phan (Analyzer)''' [https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan tysonandre.php-phan]. Phan - static analyzer for PHP, minimizing false positives.
* '''PHP Phan (Analyzer)''' [https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan tysonandre.php-phan]. Phan - static analyzer for PHP, minimizing false positives.
* '''phpmd''' [https://marketplace.visualstudio.com/items?itemName=linyang95.phpmd linyang95.phpmd]. VS Code extension for php, using phpmd.
* '''phpmd''' [https://marketplace.visualstudio.com/items?itemName=linyang95.phpmd linyang95.phpmd]. VS Code extension for PHP, using PHPMD.
* '''EditorConfig for VS Code''' [https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig editorconfig.editorconfig] EditorConfig Support for Visual Studio Code
 
* '''Joomla Snippets''' [https://marketplace.visualstudio.com/items?itemName=AnibalSanchez.vs-code-joomla-snippets anibalsanchez.vs-code-joomla-snippets]. Snippets for Joomla. Including Joomla 3.x and Joomla 4 Snippets.
<!--T:68-->
The Git protocol is natively supported on VSCode. However, there are extensions to improve code and repository management. This is a list of featured extensions for this task:
 
<!--T:69-->
* '''Git History''' [https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory donjayamanne.githistory]: Git History, Search and More (including git log).
* '''GitHub''' [https://marketplace.visualstudio.com/items?itemName=KnisterPeter.vscode-github KnisterPeter.vscode-github]: This VSCode extension integrates with GitHubExtensions for Visual Studio Code
* '''GitHub Pull Requests and Issues''' [https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github GitHub.vscode-pull-request-github]: Review and manage your GitHub pull requests and issues directly in VS Code
* '''gitignore''' [https://marketplace.visualstudio.com/items?itemName=codezombiech.gitignore codezombiech.gitignore]: A extension for Visual Studio Code that assists you in working with ''.gitignore'' files.
* '''Visual Studio Code Commitizen Support''' [https://marketplace.visualstudio.com/items?itemName=KnisterPeter.vscode-commitizen KnisterPeter.vscode-commitizen]: This VSCode extension adds ''commitizen'' support.
 
<!--T:7-->
This is a list of extensions to support Joomla on VSCode:
 
<!--T:8-->
* '''Joomla Snippets''' [https://marketplace.visualstudio.com/items?itemName=AnibalSanchez.vs-code-joomla-snippets anibalsanchez.vs-code-joomla-snippets]. Snippets for Joomla including Joomla 3.x and Joomla 4 Snippets.
* '''PHP Getters & Setters''' [https://marketplace.visualstudio.com/items?itemName=phproberto.vscode-php-getters-setters phproberto.vscode-php-getters-setters]. Create PHP getters and setters from class properties.
* '''PHP Getters & Setters''' [https://marketplace.visualstudio.com/items?itemName=phproberto.vscode-php-getters-setters phproberto.vscode-php-getters-setters]. Create PHP getters and setters from class properties.


== PHP Debug Configuration ==
<!--T:9-->
This is a list of extensions to support remote SSH development:
 
<!--T:10-->
* '''Remote - SSH''' [https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh ms-vscode-remote.remote-ssh]: The Remote - SSH extension lets you use any remote machine with an SSH server as your development environment. This can greatly simplify development and troubleshooting in a wide variety of situations. For more information: [https://code.visualstudio.com/docs/remote/ssh-tutorial Remote development over SSH]
* '''Live Share''' [https://marketplace.visualstudio.com/items?itemName=MS-vsliveshare.vsliveshare MS-vsliveshare.vsliveshare]: Visual Studio Live Share enables you to collaboratively edit and debug with others in real-time, regardless of what programming languages you're using or app types you're building. It allows you to instantly (and securely) share your current project, and then as needed, share debugging sessions, terminal instances, localhost web apps, voice calls, and more!
 
<!--T:11-->
This is a list of handy extensions highly recommended to ease the development:
 
<!--T:12-->
* '''EditorConfig for VS Code''' [https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig editorconfig.editorconfig] EditorConfig Support for Visual Studio Code.
* '''change-case''' [https://marketplace.visualstudio.com/items?itemName=wmaurer.change-case wmaurer.change-case]: Quickly change the case (camelCase, CONSTANT_CASE, snake_case, etc) of the current selection or current word.
* '''Project Manager''' [https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager alefragnani.project-manager]: It helps you to easily access your projects, no matter where they are located. Don't miss those important projects anymore.
 
== PHP Debug Configuration == <!--T:13-->


The extension supports the most common configurations of PHP [https://xdebug.org/ XDebug]. It fully integrates all VSCode features to debug PHP scripts.
<!--T:14-->
The extension supports the most common configurations of PHP [https://xdebug.org/ Xdebug]. It fully integrates all VSCode features to debug PHP scripts.


To configure the extension, visit the official documentation here: https://github.com/felixfbecker/vscode-php-debug#installation
<!--T:15-->
To configure the extension, visit the [https://github.com/xdebug/vscode-php-debug#installation official documentation].


As a sample configuration for VSCode debugging, this is a common launch.json:
<!--T:16-->
As a sample configuration for VSCode debugging, this is a common ''launch.json'':


<source lang="javascript">
<!--T:17-->
<syntaxhighlight lang="javascript">
{
{
     // Use IntelliSense to learn about possible attributes.
     // Use IntelliSense to learn about possible attributes.
     // Hover to view descriptions of existing attributes.
     // Hover to view descriptions of existing attributes.
     // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
     // For more information, visit: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
     "version": "0.2.0",
     "version": "0.2.0",
     "configurations": [
     "configurations": [


         {
         <!--T:18-->
             "name": "Listen for XDebug",
{
             "name": "Listen for Xdebug",
             "type": "php",
             "type": "php",
             "request": "launch",
             "request": "launch",


             // Server Remote XDebug Port
             <!--T:19-->
             "port": 9099,
// Server Remote Xdebug Port - 9003 is the default Xdebug port
             "port": 9003,


             // Server Remote Path -> Local Project Path
             <!--T:20-->
// Server Remote Path -> Local Project Path
             "pathMappings": {
             "pathMappings": {
                 "/app/www": "${workspaceRoot}/www"
                 "/app/www": "${workspaceRoot}/www"
Line 53: Line 102:
             "cwd": "${fileDirname}",
             "cwd": "${fileDirname}",


             // Local XDebug Port
             <!--T:21-->
             "port": 9099
// Local Xdebug Port - 9003 is the default Xdebug port
             "port": 9003
         }
         }
     ]
     ]
}
}
</source>
</syntaxhighlight>


== phpcs Configuration ==
<!--T:71-->
Related to the ''launch.json'' configuration that ''felixfbecker/vscode-php-debug'' requires, it is the configuration of PHP Xdebug itself.


To configure the extension, visit the official documentation here: https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs
<!--T:72-->
Your development environment should have Xdebug 3. (Xdebug 2 is no longer supported.) To configure PHP Xdebug, these are the most common settings for ''php.ini'':


=== Xdebug 3 Configuration === <!--T:75-->
<!--T:76-->
<syntaxhighlight>
[Xdebug]
;;;;;;;;;;;;;;;;;;;
; xdebug-3.0.0
; https://xdebug.org/docs/upgrade_guide
;;;;;;;;;;;;;;;;;;;
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
; xdebug.client_port = 9003
</syntaxhighlight>
<!--T:77-->
To know more about how Xdebug works internally to connect to the Editor, check the [https://xdebug.org/docs/ Xdebug 3 — Documentation].
== ''phpcs'' Configuration == <!--T:22-->
<!--T:23-->
To configure the extension, visit the [https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs official documentation].
<!--T:24-->
The extension supports the most common configurations of [https://pear.php.net/package/PHP_CodeSniffer/ PHP_CodeSniffer].
The extension supports the most common configurations of [https://pear.php.net/package/PHP_CodeSniffer/ PHP_CodeSniffer].


By default, PHP_CodeSniffer comes with several coding standards. Once the extension is installed, it works with '''PSR2'''.
<!--T:25-->
By default, PHP_CodeSniffer comes with several coding standards. Once the extension is installed, it works with ''PSR2''.


<source lang="javascript">
<!--T:26-->
<syntaxhighlight lang="javascript">
     "phpcs.standard": "PSR2",
     "phpcs.standard": "PSR2",
</source>
</syntaxhighlight>


To configure the extension to apply the '''Joomla! Coding Standards''', install the rules following the official guide: https://developer.joomla.org/coding-standards/html.html
<!--T:27-->
To configure the extension to apply the '''Joomla! Coding Standards''', install the rules following the [https://developer.joomla.org/coding-standards/html.html official guide].


Once the '''Joomla! Coding Standards''' is installed, configure the User Settings following this sample configuration:
<!--T:28-->
Once '''Joomla! Coding Standards''' is installed, configure the User Settings following this sample configuration:


<source lang="javascript">
<!--T:29-->
<syntaxhighlight lang="javascript">
     "phpcs.standard": "/home/YOUR-USER/.../Joomla",
     "phpcs.standard": "/home/YOUR-USER/.../Joomla",
</source>
</syntaxhighlight>


== Configuration of PHP Intelephense ==
== Configuration of PHP Intelephense == <!--T:30-->


To configure the extension, visit the official documentation here: https://github.com/bmewburn/vscode-intelephense#quick-start
<!--T:31-->
To configure the extension, visit the [https://github.com/bmewburn/vscode-intelephense#quick-start official documentation].


<!--T:32-->
The extension does not require additional configuration.
The extension does not require additional configuration.


VSCode comes with basic support of the PHP language. So, it is probably a good idea to disable the default support to avoid conflicts:
<!--T:33-->
VSCode comes with basic support of the PHP language. It is a good idea to disable the default support to avoid conflicts:


<source lang="javascript">
<!--T:34-->
<syntaxhighlight lang="javascript">
     // Disable basic suggestions
     // Disable basic suggestions
     "php.suggest.basic": false,
     "php.suggest.basic": false,


     // To activate code suggestions in comments
     <!--T:35-->
// To activate code suggestions in comments
     "editor.quickSuggestions": { "comments": true },
     "editor.quickSuggestions": { "comments": true },
</source>
</syntaxhighlight>


As an alternative, it is also a very popular extension: '''PHP IntelliSense''' [https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense felixfbecker.php-intellisense] Advanced Autocompletion and Refactoring support for PHP.
<!--T:36-->
As an alternative, it is also a popular extension: '''PHP IntelliSense''' [https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense felixfbecker.php-intellisense] Advanced Autocompletion and Refactoring support for PHP.


== PHPUnit Configuration ==
== PHPUnit Configuration == <!--T:37-->


To configure the extension, visit the official documentation here: https://github.com/elonmallin/vscode-phpunit#setup
<!--T:38-->
To configure the extension, visit the [https://github.com/elonmallin/vscode-phpunit#setup official documentation].


The extension integrates [https://phpunit.de/ PHP Unit] with VSCode, so all features of PHP Unit are integrated with VSCode and can also be parametrized for further integration with the user interface.
<!--T:39-->
The extension integrates [https://phpunit.de/ PHP Unit] with VSCode, so all features of PHP Unit are integrated with VSCode and can also be parameterized for further integration with the user interface.


<!--T:40-->
This is a sample configuration of the extension:
This is a sample configuration of the extension:


<source lang="javascript">
<!--T:41-->
<syntaxhighlight lang="javascript">
     "phpunit.preferRunClassTestOverQuickPickWindow": true,
     "phpunit.preferRunClassTestOverQuickPickWindow": true,
     "phpunit.driverPriority": [
     "phpunit.driverPriority": [
Line 116: Line 207:
         "GlobalPhpUnit"
         "GlobalPhpUnit"
     ],
     ],
</source>
</syntaxhighlight>


== php cs fixer Configuration (Only for PSR2) ==
== PHP CS Fixer Configuration (Only for PSR2) == <!--T:42-->


To configure the extension, visit the official documentation here: https://github.com/junstyle/vscode-php-cs-fixer#installation
<!--T:43-->
To configure the extension, visit the [https://github.com/junstyle/vscode-php-cs-fixer#installation official documentation].


The extension integrates [https://github.com/FriendsOfPHP/PHP-CS-Fixer PHP-CS-Fixer] with VSCode, so all features of PHP-CS-Fixer are integrated with VSCode and can also be parametrized for further integration with the user interface.
<!--T:44-->
The extension integrates [https://github.com/PHP-CS-Fixer/PHP-CS-Fixer PHP CS Fixer] with VSCode, so all features of PHP CS Fixer are integrated with VSCode and can also be parameterized for further integration with the user interface.


To automatically, apply PHP-CS-Fixer to PHP files, configure the user settings in this way:
<!--T:45-->
To automatically apply PHP CS Fixer to PHP files, configure the user settings in this way:


<source lang="javascript">
<!--T:46-->
<syntaxhighlight lang="javascript">
     "[php]": {
     "[php]": {
         "editor.defaultFormatter": "junstyle.php-cs-fixer",
         "editor.defaultFormatter": "junstyle.php-cs-fixer",
     },
     },
     "php-cs-fixer.onsave": true,
     "php-cs-fixer.onsave": true,
</source>
</syntaxhighlight>


== PHP Phan (Analyzer) Configuration ==
== PHP Phan (Analyzer) Configuration == <!--T:47-->


To configure the extension, visit the official documentation here: https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan
<!--T:48-->
To configure the extension, visit the [https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan official documentation].


<!--T:49-->
This is a sample configuration of the extension:
This is a sample configuration of the extension:


<source lang="javascript">
<!--T:50-->
<syntaxhighlight lang="javascript">
     "phan.phpExecutablePath": "/usr/bin/php",
     "phan.phpExecutablePath": "/usr/bin/php",
     "phan.analyzedFileExtensions": [
     "phan.analyzedFileExtensions": [
         "php"
         "php"
     ],
     ],
</source>
</syntaxhighlight>


== phpmd Configuration ==
== ''phpmd'' Configuration == <!--T:51-->


To configure the extension, visit the official documentation here: https://github.com/felixfbecker/vscode-php-debug#installation
<!--T:52-->
To configure the extension, visit the [https://github.com/xdebug/vscode-php-debug#installation official documentation].


<!--T:53-->
The extension does not require additional configuration.
The extension does not require additional configuration.


<!--T:54-->
This is a sample configuration of the extension:
This is a sample configuration of the extension:


<source lang="javascript">
<!--T:55-->
<syntaxhighlight lang="javascript">
     "phpmd.command": "php /home/YOUR-USER/.../phpmd/phpmd.phar",
     "phpmd.command": "php /home/YOUR-USER/.../phpmd/phpmd.phar",
     "phpmd.rules": "/home/YOUR-USER/.../phpmd-rulesets/phpmd_config.xml",
     "phpmd.rules": "/home/YOUR-USER/.../phpmd-rulesets/phpmd_config.xml",
</source>
</syntaxhighlight>


== Configure EditorConfig for VS Code ==
== Configure EditorConfig for VS Code == <!--T:56-->


<!--T:57-->
EditorConfig is a file format and collection of text editor plugins for maintaining consistent coding styles between different editors and IDEs.
EditorConfig is a file format and collection of text editor plugins for maintaining consistent coding styles between different editors and IDEs.


To configure the editor according to your preferences, create a file .editorconfig:
<!--T:58-->
To configure the editor according to your preferences, create a file ''.editorconfig'':


<source lang="javascript">
<!--T:59-->
<syntaxhighlight lang="javascript">
; EditorConfig helps developers define and maintain consistent
; EditorConfig helps developers define and maintain consistent
; coding styles between different editors and IDEs.
; coding styles between different editors and IDEs.


; For more visit http://editorconfig.org.
<!--T:60-->
; For more visit https://editorconfig.org/
root = true
root = true


<!--T:61-->
; Choose between lf or rf on "end_of_line" property
; Choose between lf or rf on "end_of_line" property
[*]
[*]
Line 181: Line 288:
trim_trailing_whitespace = true
trim_trailing_whitespace = true


# editorconfig-tools is unable to ignore longs strings or urls
<!--T:62-->
# editorconfig-tools is unable to ignore longs strings or URLs
max_line_length = null
max_line_length = null


<!--T:63-->
[*.html]
[*.html]
indent_style = tab
indent_style = tab


<!--T:64-->
# PSR-2
# PSR-2
# [*.php]
# [*.php]
Line 192: Line 302:
# indent_style = space
# indent_style = space


<!--T:65-->
# Joomla! Coding Standards
# Joomla! Coding Standards
[*.php]
[*.php]
Line 197: Line 308:
indent_style = tab
indent_style = tab


<!--T:66-->
[*.md]
[*.md]
trim_trailing_whitespace = false
trim_trailing_whitespace = false


<!--T:67-->
[*.yml]
[*.yml]
indent_style = space
indent_style = space
indent_size = 2
indent_size = 2
</source>
</syntaxhighlight>
 
</translate>


<noinclude>
<noinclude>
<translate>
<translate>
<!--T:1-->
[[Category:Development{{#translation:}}]]
[[Category:Development{{#translation:}}]]
[[Category:Beginner_Development{{#translation:}}]]
[[Category:Beginner_Development{{#translation:}}]]

Latest revision as of 21:37, 1 July 2023

Visual Studio Code (VSCode) is a source code editor developed by Microsoft for Windows, Linux and MacOS (including M1 Macs). It includes support for debugging, embedded Git control and GitHub, syntax highlighting, intelligent code completion, snippets, and code refactoring.

The main characteristic of the editor is that it is extensible and it has a huge collection of extensions maintained by users and by Microsoft itself. See details at the VSCode Extensions for Visual Studio Code website.

As a general introduction, this is a presentation about the topic Joomla Development with Visual Studio Code, by René Kreijveld, Joomla developer Destiny B.V. Joomla User Group London, 16th march 2021.

On this page, we detail a list of recommended extensions to configure VSCode to support PHP and Joomla.

This is a list of extensions to support PHP on VSCode:

The Git protocol is natively supported on VSCode. However, there are extensions to improve code and repository management. This is a list of featured extensions for this task:

This is a list of extensions to support Joomla on VSCode:

This is a list of extensions to support remote SSH development:

  • Remote - SSH ms-vscode-remote.remote-ssh: The Remote - SSH extension lets you use any remote machine with an SSH server as your development environment. This can greatly simplify development and troubleshooting in a wide variety of situations. For more information: Remote development over SSH
  • Live Share MS-vsliveshare.vsliveshare: Visual Studio Live Share enables you to collaboratively edit and debug with others in real-time, regardless of what programming languages you're using or app types you're building. It allows you to instantly (and securely) share your current project, and then as needed, share debugging sessions, terminal instances, localhost web apps, voice calls, and more!

This is a list of handy extensions highly recommended to ease the development:

  • EditorConfig for VS Code editorconfig.editorconfig EditorConfig Support for Visual Studio Code.
  • change-case wmaurer.change-case: Quickly change the case (camelCase, CONSTANT_CASE, snake_case, etc) of the current selection or current word.
  • Project Manager alefragnani.project-manager: It helps you to easily access your projects, no matter where they are located. Don't miss those important projects anymore.

PHP Debug Configuration

The extension supports the most common configurations of PHP Xdebug. It fully integrates all VSCode features to debug PHP scripts.

To configure the extension, visit the official documentation.

As a sample configuration for VSCode debugging, this is a common launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",

            // Server Remote Xdebug Port - 9003 is the default Xdebug port
            "port": 9003,

            // Server Remote Path -> Local Project Path
            "pathMappings": {
                "/app/www": "${workspaceRoot}/www"
            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",

            // Local Xdebug Port - 9003 is the default Xdebug port
            "port": 9003
        }
    ]
}

Related to the launch.json configuration that felixfbecker/vscode-php-debug requires, it is the configuration of PHP Xdebug itself.

Your development environment should have Xdebug 3. (Xdebug 2 is no longer supported.) To configure PHP Xdebug, these are the most common settings for php.ini:

Xdebug 3 Configuration

[Xdebug]
;;;;;;;;;;;;;;;;;;;
; xdebug-3.0.0
; https://xdebug.org/docs/upgrade_guide
;;;;;;;;;;;;;;;;;;;
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
; xdebug.client_port = 9003

To know more about how Xdebug works internally to connect to the Editor, check the Xdebug 3 — Documentation.

phpcs Configuration

To configure the extension, visit the official documentation.

The extension supports the most common configurations of PHP_CodeSniffer.

By default, PHP_CodeSniffer comes with several coding standards. Once the extension is installed, it works with PSR2.

    "phpcs.standard": "PSR2",

To configure the extension to apply the Joomla! Coding Standards, install the rules following the official guide.

Once Joomla! Coding Standards is installed, configure the User Settings following this sample configuration:

    "phpcs.standard": "/home/YOUR-USER/.../Joomla",

Configuration of PHP Intelephense

To configure the extension, visit the official documentation.

The extension does not require additional configuration.

VSCode comes with basic support of the PHP language. It is a good idea to disable the default support to avoid conflicts:

    // Disable basic suggestions
    "php.suggest.basic": false,

    // To activate code suggestions in comments
    "editor.quickSuggestions": { "comments": true },

As an alternative, it is also a popular extension: PHP IntelliSense felixfbecker.php-intellisense Advanced Autocompletion and Refactoring support for PHP.

PHPUnit Configuration

To configure the extension, visit the official documentation.

The extension integrates PHP Unit with VSCode, so all features of PHP Unit are integrated with VSCode and can also be parameterized for further integration with the user interface.

This is a sample configuration of the extension:

    "phpunit.preferRunClassTestOverQuickPickWindow": true,
    "phpunit.driverPriority": [
        "Path",
        "Command",
        "Composer",
        "Phar",
        "Ssh",
        "GlobalPhpUnit"
    ],

PHP CS Fixer Configuration (Only for PSR2)

To configure the extension, visit the official documentation.

The extension integrates PHP CS Fixer with VSCode, so all features of PHP CS Fixer are integrated with VSCode and can also be parameterized for further integration with the user interface.

To automatically apply PHP CS Fixer to PHP files, configure the user settings in this way:

    "[php]": {
        "editor.defaultFormatter": "junstyle.php-cs-fixer",
    },
    "php-cs-fixer.onsave": true,

PHP Phan (Analyzer) Configuration

To configure the extension, visit the official documentation.

This is a sample configuration of the extension:

    "phan.phpExecutablePath": "/usr/bin/php",
    "phan.analyzedFileExtensions": [
        "php"
    ],

phpmd Configuration

To configure the extension, visit the official documentation.

The extension does not require additional configuration.

This is a sample configuration of the extension:

    "phpmd.command": "php /home/YOUR-USER/.../phpmd/phpmd.phar",
    "phpmd.rules": "/home/YOUR-USER/.../phpmd-rulesets/phpmd_config.xml",

Configure EditorConfig for VS Code

EditorConfig is a file format and collection of text editor plugins for maintaining consistent coding styles between different editors and IDEs.

To configure the editor according to your preferences, create a file .editorconfig:

; EditorConfig helps developers define and maintain consistent
; coding styles between different editors and IDEs.

; For more visit https://editorconfig.org/
root = true

; Choose between lf or rf on "end_of_line" property
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

# editorconfig-tools is unable to ignore longs strings or URLs
max_line_length = null

[*.html]
indent_style = tab

# PSR-2
# [*.php]
# indent_size = 4
# indent_style = space

# Joomla! Coding Standards
[*.php]
indent_size = 4
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2