简体   繁体   中英

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

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.

如果在代码中选择要为其生成use语句的类,则键入Alt-Enter-Enter,您将获得一个菜单“Import Class”,您可以在其中选择要包含在use语句中的类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM