Can I configure PhpStorm to add use statements automatically for copy and paste code blocks?

StackOverflow https://stackoverflow.com/questions/23086861

سؤال

When I write code within phpstorm, it will add use statements when I select a class from autocompletion.

So writing $pagerfanta = new Pagerfanta(new DoctrineORMAdapter($query)); will add both use statements:

use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\DoctrineORMAdapter;

Yet when I copy-paste or extract the block containing $pagerfanta = new Pagerfanta(new DoctrineORMAdapter($query)); into a new class, the use statements will not get added. PhpStorm shows them as missing by adding a different background color.

Nontheless, I often forget to add the use statements then, and hence am wondering, if I can configure PhpStorm to add those use statements for me when copy-pasting.

هل كانت مفيدة؟

المحلول

If you select a class in your code you want to generate a use statements for, then type Alt-Enter-Enter you will get a menu "Import Class" where you can select the class to include in the use statement.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top