Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Setting up PhpStorm: Difference between revisions

From MoodleDocs
No edit summary
(12 intermediate revisions by 6 users not shown)
Line 5: Line 5:
===OS X===
===OS X===


You can optionally install latest Java JDK 1.7.x from [http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html Oracle] (Java 1.6 from Apple is not maintained much). By default PhpStorm uses only older 1.6.x java, but you can hack PhpStorm 7 to be compatible with Java 1.7 by editing the "PhpStorm.app/Contents/Info.plist" file, set JVMOptions - JVMVersion = 1.7*
Do not install Java manually, download a PhpStorm package with bundled java instead.


==General settings==
==General settings==


* Disable missing @throws tag warning in "Preferences / Project Settings / Inspections / PHP / PHPDoc"
* Disable missing @throws tag warning in "Preferences / Project Settings / Inspections / PHP / PHPDoc"
* Strip trailing whitespace from "Modified Lines" in "Preferences / IDE Settings / Editor"
* Strip trailing whitespace from "Modified Lines" in "Preferences / IDE Settings / Editor/ General"
* Show line numbers in "Preferences / IDE Settings / Editor / Appearance"
* Show line numbers in "Preferences / IDE Settings / Editor / Appearance"
==Bug tracker integration==
* Add tracker linking in "Preferences / Version control / Issue Navigation"
* Set Issue ID to "MDL-\d+" and Issue link to "https://tracker.moodle.org/browse/$0" or just click on 'add Jira pattern' and paste "https://tracker.moodle.org"


==Code formatting==
==Code formatting==


* Setup coding style to use all rules from [[Coding style]] in "Preferences / Project Settings / Code Style / PHP" - this will allow you to use automatic code formatting and it does nice code formatting on copy/paste.
* Setup coding style to use all rules from [[Coding style]] in "Preferences / Project Settings / Code Style / PHP" (or simply import from https://github.com/enovation/moodle-utils/blob/master/phpstorm-config/Moodle.xml) - this will allow you to use automatic code formatting and it does nice code formatting on copy/paste.
* Set line separator to Unix in "Preferences / Project Settings / Code Style / General".
* Set line separator to "Unix and OS X (\n)" in "Preferences / Project Settings / Code Style / General".
* Set right margin to 132 or 180 in "Preferences / Project Settings / Code Style / General".
* Set right margin to 132 or 180 in "Preferences / Project Settings / Code Style / General".
==Tips & Tricks==
* Use <code php>/** @var admin_root $ADMIN */</code>  to autofill $ADMIN->...
* Remove SQL syntax inspection errors for Moodle tables surrounded by curly brackets (like: <code php>SELECT * FROM {user}</code>)  by adding <code php>\{(\w+)\}</code> to Tools > Databases > user parameters
(more info: https://blog.jetbrains.com/phpstorm/2014/11/database-language-injection-configuration/ , and a "feature request" to improve it: https://youtrack.jetbrains.com/issue/WI-4123 )


==Moodle code checker==
==Moodle code checker==
TODO
Follow the instructions in the [https://github.com/moodlehq/moodle-local_codechecker/blob/master/README.md#ide-integration README]


==PHPUnit integration==
==PHPUnit integration==
Line 34: Line 45:
# Click "+" in the top left and add "Database source" for your database
# Click "+" in the top left and add "Database source" for your database
# Note: click on the link to download the necessary drivers directly from IDE
# Note: click on the link to download the necessary drivers directly from IDE
==Useful plugins==
# Php Inspections ​(EA Extended) - https://plugins.jetbrains.com/plugin/7622-php-inspections-ea-extended-/
# SonarLint - https://plugins.jetbrains.com/plugin/7973-sonarlint/
# Diff / Patch File Support - https://plugins.jetbrains.com/plugin/11957-diff--patch-file-support/
# Handlebars/Mustache - https://plugins.jetbrains.com/plugin/6884-handlebars-mustache/
# Markdown Navigator - https://plugins.jetbrains.com/plugin/7896-markdown-navigator/
# PHP composer.json support - https://plugins.jetbrains.com/plugin/7631-php-composer-json-support/
# PHP Advanced AutoComplete - https://plugins.jetbrains.com/plugin/7276-php-advanced-autocomplete/
[[Category:Developer tools|PhpStorm]]

Revision as of 21:09, 3 March 2020

PhpStorm is a commercial IDE, it is arguably the best IDE for PHP developers with features such as code completion, code inspection, phpunit support, Behat support, database editor, debugger, etc.

Installation

OS X

Do not install Java manually, download a PhpStorm package with bundled java instead.

General settings

  •  Disable missing @throws tag warning in "Preferences / Project Settings / Inspections / PHP / PHPDoc"
  • Strip trailing whitespace from "Modified Lines" in "Preferences / IDE Settings / Editor/ General"
  • Show line numbers in "Preferences / IDE Settings / Editor / Appearance"

Bug tracker integration

Code formatting

  • Setup coding style to use all rules from Coding style in "Preferences / Project Settings / Code Style / PHP" (or simply import from https://github.com/enovation/moodle-utils/blob/master/phpstorm-config/Moodle.xml) - this will allow you to use automatic code formatting and it does nice code formatting on copy/paste.
  • Set line separator to "Unix and OS X (\n)" in "Preferences / Project Settings / Code Style / General".
  • Set right margin to 132 or 180 in "Preferences / Project Settings / Code Style / General".

Tips & Tricks

  • Use /** @var admin_root $ADMIN */ to autofill $ADMIN->...
  • Remove SQL syntax inspection errors for Moodle tables surrounded by curly brackets (like: SELECT * FROM {user}) by adding \{(\w+)\} to Tools > Databases > user parameters

(more info: https://blog.jetbrains.com/phpstorm/2014/11/database-language-injection-configuration/ , and a "feature request" to improve it: https://youtrack.jetbrains.com/issue/WI-4123 )

Moodle code checker

Follow the instructions in the README

PHPUnit integration

  1. Install PHPUnit via Composer
  2. Tell PHPStorm where is composer - go to "Preferences / PHP / Composer", fill in "Path to PHP executable", "Path to composer.phar", "Path to composer.json" and make sure the option "Add packages as libraries" is enabled.
  3. Go to "Run / Edit configurations"
  4. Add PHPUnit configuration by clicking on "+"
  5. Click "Use alternative configuration file" and select your phpunit.xml file
  6. Go to "Run / Run ..." and select your new PHPUnit configuration to run

Database editor

  1. Click on the "Database" tab to see the database window
  2. Click "+" in the top left and add "Database source" for your database
  3. Note: click on the link to download the necessary drivers directly from IDE

Useful plugins

  1. Php Inspections ​(EA Extended) - https://plugins.jetbrains.com/plugin/7622-php-inspections-ea-extended-/
  2. SonarLint - https://plugins.jetbrains.com/plugin/7973-sonarlint/
  3. Diff / Patch File Support - https://plugins.jetbrains.com/plugin/11957-diff--patch-file-support/
  4. Handlebars/Mustache - https://plugins.jetbrains.com/plugin/6884-handlebars-mustache/
  5. Markdown Navigator - https://plugins.jetbrains.com/plugin/7896-markdown-navigator/
  6. PHP composer.json support - https://plugins.jetbrains.com/plugin/7631-php-composer-json-support/
  7. PHP Advanced AutoComplete - https://plugins.jetbrains.com/plugin/7276-php-advanced-autocomplete/