Smart-type completion feature for the Pimple container in the PhpStorm

Docler
Byborg Engineering
Published in
2 min readJul 20, 2020

by Alexander Lisachenko

As you might know, PHP has different types of code completion and there are real gems like Postfix Completion and least known, but powerful Smart-Type Completion feature.

In this article I will show you how to benefit from Smart Type completion feature for filling values in ServiceProviders like a pro:

To enable this cool feature, you first need to define a Live Template for container autocompletion feature.

Open Settings → Live Template:

Then use small “+” button on the right to add a new Live Template and define it as following:

  • Abbreviation: c
  • Description: Pimple container autocomplete
  • Template text: $container[$SERVICE_NAME$::class],$END$

After that we need to define $SERVICE_NAME$ variable to be smart-completed by IDE, select “Edit variables” button to open a dialog-box and for this variable choose “completeSmart()” function:

After that we need only to define our context to be PHP but pressing “Define” link near “No applicable contexts” label at the bottom and selecting PHP in the list of contexts.

Usage in projects

Inside any ServiceProvider codebase you can now press “c”, then “Tab” button to trigger smart-type completion of your type. It should work now, if it doesn’t work like described, then put a file with the name: .phpstorm.meta.php and following content to teach PhpStorm.

--

--

Docler
Byborg Engineering

Curious about the technologies powering the 30th most visited website in the world, with 45 million users, 2,000 servers, 4 data centers?