Checking your code with PHP Code Sniffer in PhpStorm 4.0
PhpStorm 4.0 allows you to check your code on the fly with PHP Code Sniffer (phpcs) just by opening a PHP file. The check is triggered every time you change something in the file thus making it extremely easy to get rid of problems reported by PHP Code Sniffer.
Initial Software Requirements
First you need to set up PHP Code Sniffer. You can find more information on site. Make sure you can actually run PHP Code Sniffer from command line: if you type “
phpcs --version“, you should get something like this:
PHP_CodeSniffer version 1.3.3 (stable) by Squiz Pty Ltd. (http://www.squiz.net)
Setting Up PHP Code Sniffer Validation Inspection
- Open Settings and navigate to Inspections|PHP|PHP Code Sniffer validation and check the inspection box.
- Now select a Code Sniffer path like it is shown below, for example:
- Click “Validate”. This is necessary to ensure that phpcs can be launched from IDE and will report problems. PhpStorm performs the validation by attempting to run “
phpcs --version“. On success it displays obtained phpcs version message and updates a list of coding standards (“Coding standard” combo box):
- Choose a coding standard you want (passed as a value of “
--standard” option) and optionally set the flag “Ignore warnings” (equivalent to “-n” option).
- Click OK.
Obtaining Validation Results
Now open a PHP file. Once phpcs will be run, you will see a number of warning messages reported by PHP Code Sniffer. For example:
Note that each message is prefixed with “phpcs” to distinguish it from PhpStorm’s own inspections.
Note that validating the file takes some time, so you may not see all the results instantly but in some cases, especially if the file is big, in few seconds. That doesn’t prevent though from editing the file.
Let us know what you think and please submit your feedback (bug reports, improvement suggestions) in YouTrack. This will help us to make
phpcs tool integration even better.
Working with Windows Azure SQL Database in PhpStorm
PhpStorm provides us the possibility to connect to Windows Azure SQL Database right from within the IDE. In this post, we’ll explore several options that are available for working with Windows Azure SQL Database (or database systems like SQL Server, MySQL, PostgreSQL or Oracle, for that matter): …
Change signature refactoring in PhpStorm
A very powerful refactoring is the Change signature refactoring in PhpStorm. It enables us to modify a function signature in many ways: we can change the function name, change its visibility, add, remove and reorder parameters as well as rename parameters. (more…)…
Folding for imports in PhpStorm 6.0
In PhpStorm 6, we've introduced code folding for imports. Any list of imports will now be folded into a single line. This greatly reduced clutter in your editor when having a lot of imports! (more…)…
Drag & Drop Project Files to Remote Hosts in PhpStorm
The Remote Host pane allows us to work directly on a remote server through FTP, FTPS, SFTP or a local/network folder. A lot of people asked us to add drag & drop to the Remote Host pane in PhpStorm. Good news: PhpStorm 6 comes with drag & drop as well as copy & paste support from the pro…