首页 > 解决方案 > Phpstorm Composer 类重命名

问题描述

在整个项目中,我们目前拥有:

use Twig_Environment;
// then later in the file:
Twig_Environment $twig

Twig 更新了他们的类命名空间,因此现在需要:

use Twig\Environment;
// then later in the file:
Environment $tw

Phpstorm 中是否有重构功能可以为我们处理这个问题?由于类型提示、注释等,查找/替换在这里并不理想。

标签: phpphpstorm

解决方案


您可以通过替换简单地为该类命名:

use Twig_Environment;

和:

use Twig\Environment as Twig_Environment;

这将允许您继续使用Twig_Environment文件中的其他任何地方。

为此,您可以使用 PHPStorm 的查找和替换功能(应该是安全的):

查找(启用正则表达式)

^\s*use\s+Twig_Environment\s*;

代替

use Twig\\Environment as Twig_Environment;

在任何情况下,特别是如果您不使用任何 VCS,您应该事先备份您的代码并确保它首先适用于几个单独的文件。


推荐阅读