Features Releases

Working with composer.json in PhpStorm

ComposerWhat makes PHP great is the community that is building frameworks, libraries and nice tools. And more. This awesome community brought us Composer, a dependency manager for PHP which lets us install and update packages from Packagist.org and makes it easy to package up our own projects and make them available to the world.

That awesome community just extended PhpStorm’s support for Composer. Next to the UI for managing dependencies and completion for Composer’s command line tool that comes with our IDE, Piotr Śliwa‘s Composer.json plugin for PhpStorm adds completion and inspections for working with the composer.json file directly. Let’s see!

Installing the plugin

First things first, of course. We’ll have to install the Composer.json plugin for PhpStorm. Open the settings (Ctrl+Alt+S or CMD+, on Mac OS X) and click Plugins. In the pane that opens, click Browse repositories… and search for PHP composer.json support. The green Install plugin button will download and install the plugin into our IDE.

Install Composer.json plugin for PhpStorm

A quick restart of the IDE, and we’re good to go!

Composer.json completion

Let’s add a composer.json file to our project. When we start adding properties, the plugin provides completion (Ctrl+Space / CMD+Space) for all property names known in the composer.json schema, including a description of the property.

Composer.json property auto complete in PhpStorm

Not only properties are completed. For every property, the plugin knows what the possible values are and provides the necessary suggestions.

Composer.json completion for property values in PhpStorm IDE

There’s also completion for dependencies and their versions, which are queried against Packagist.org. Start typing and press Tab to have the plugin complete the package name and jump into the version specification.

Code completion for Composer package names

Inspections and quick-fixes for composer.json files

Many other nice little gems are available when working on the composer.json file. For example when adding a property that is not allowed according to the specs, the plugin will tell us and provide a quick-fix (Alt+Enter) to remove the erroneous entry.

Inspect composer.json schema

The plugin also checks if referenced files exist and if not, provides a quick-fix to create it for us. This comes in very handy when working on the bin or autoload properties in composer.json.

Create file inspection

Give Piotr‘s Composer.json plugin for PhpStorm a try. If you don’t have PhpStorm installed yet, we have a 30-day trial for PhpStorm available.

Feel free to post feature requests for the plugin on GitHub. And of course all your comments and suggestions for PhpStorm are welcome through the issue tracker, in the comments below, or on our forums!

Develop with pleasure!
– JetBrains PhpStorm Team

image description