Visual Studio Code: Difference between revisions

From Joomla! Documentation

Created page with "Place holder for Visual Studio Code (VSCode) page"
 
A few personal notes about VSCode, just to start on the right foot
Line 1: Line 1:
Place holder for Visual Studio Code (VSCode) page
 
[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.
 
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.
 
In 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.
* '''PHP Intelephense''' [https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client bmewburn.vscode-intelephense-client]. PHP code intelligence for Visual Studio Code.
* '''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.
* '''PHP Phan (Analyzer)''' [https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan tysonandre.php-phan]. Phan - static analyzer for PHP, minimizing false positives.
* '''phpcs''' [https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs ikappas.phpcs]. PHP CodeSniffer for Visual Studio Code.
* '''phpmd''' [https://marketplace.visualstudio.com/items?itemName=linyang95.phpmd linyang95.phpmd]. VS Code extension for php, using phpmd.
* '''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.
 
== Configuration of PHP Debug ==
 
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
 
As a sample configuration for VSCode debugging, this is a common launch.json:
 
<source lang="javascript">
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
 
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
 
            // Server Remote XDebug Port
            "port": 9099,
 
            // 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
            "port": 9099
        }
    ]
}
</source>
 
== Configuration of phpcs ==
 
To configure the extension, visit the official documentation here: https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs
 
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'''.
 
<source lang="javascript">
    "phpcs.standard": "PSR2",
</source>
 
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
 
Once the '''Joomla! Coding Standards''' is installed, configure the User Settings following this sample configuration:
 
<source lang="javascript">
    "phpcs.standard": "/home/YOUR-USER/.../Joomla",
</source>
 
== Configuration of PHP Intelephense ==
 
To configure the extension, visit the official documentation here: https://github.com/bmewburn/vscode-intelephense#quick-start
 
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:
 
<source lang="javascript">
    "php.suggest.basic": false,
</source>
 
== Configuration of PHPUnit ==
 
To configure the extension, visit the official documentation here: https://github.com/elonmallin/vscode-phpunit#setup
 
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.
 
This is a sample configuration of the extension:
 
<source lang="javascript">
    "phpunit.preferRunClassTestOverQuickPickWindow": true,
    "phpunit.driverPriority": [
        "Path",
        "Command",
        "Composer",
        "Phar",
        "Ssh",
        "GlobalPhpUnit"
    ],
</source>
 
== Configuration of php cs fixer (Only PSR2) ==
 
To configure the extension, visit the official documentation here: https://github.com/junstyle/vscode-php-cs-fixer#installation
 
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.
 
To automatically, apply PHP-CS-Fixer to PHP files, configure the user settings in this way:
 
<source lang="javascript">
    "[php]": {
        "editor.defaultFormatter": "junstyle.php-cs-fixer",
    },
    "php-cs-fixer.onsave": true,
</source>
 
== Configuration of PHP Phan (Analyzer) ==
 
To configure the extension, visit the official documentation here: https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan
 
This is a sample configuration of the extension:
 
<source lang="javascript">
    "phan.phpExecutablePath": "/usr/bin/php",
    "phan.analyzedFileExtensions": [
        "php"
    ],
</source>
 
== Configuration of phpmd ==
 
To configure the extension, visit the official documentation here: https://github.com/felixfbecker/vscode-php-debug#installation
 
The extension does not require additional configuration.
 
This is a sample configuration of the extension:
 
<source lang="javascript">
    "phpmd.command": "php /home/YOUR-USER/.../phpmd/phpmd.phar",
    "phpmd.rules": "/home/YOUR-USER/.../phpmd-rulesets/phpmd_config.xml",
</source>

Revision as of 19:28, 10 April 2020

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.

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.

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

Configuration of PHP Debug

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 here: https://github.com/felixfbecker/vscode-php-debug#installation

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://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

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

            // Server Remote XDebug Port
            "port": 9099,

            // 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
            "port": 9099
        }
    ]
}

Configuration of phpcs

To configure the extension, visit the official documentation here: https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs

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: https://developer.joomla.org/coding-standards/html.html

Once the 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 here: https://github.com/bmewburn/vscode-intelephense#quick-start

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:

    "php.suggest.basic": false,

Configuration of PHPUnit

To configure the extension, visit the official documentation here: https://github.com/elonmallin/vscode-phpunit#setup

The extension integrates 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.

This is a sample configuration of the extension:

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

Configuration of php cs fixer (Only PSR2)

To configure the extension, visit the official documentation here: https://github.com/junstyle/vscode-php-cs-fixer#installation

The extension integrates 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.

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,

Configuration of PHP Phan (Analyzer)

To configure the extension, visit the official documentation here: https://marketplace.visualstudio.com/items?itemName=TysonAndre.php-phan

This is a sample configuration of the extension:

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

Configuration of phpmd

To configure the extension, visit the official documentation here: https://github.com/felixfbecker/vscode-php-debug#installation

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",