php-cs-fixer - php-cs-fixer 包括供应商命名空间,但不包括 src/ 中的包
问题描述
从 symfony 3.4 捆绑包 AppBundle 中的一个简单实体类开始,php-cs-fixer 似乎去除了文档字符串使用的导入,但仅在引用 AppBundle/ 时 - vendor/ 中的命名空间似乎是安全的
从以下简单的实体类开始
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\EntityManager;
use AppBundle\Entity\AclObjectIdentities; // will be removed
use AppBundle\Entity\AclSecurityIdentities; // will be removed
class AclEntries
{
/** @var AclObjectIdentities Object identity */
private $objectIdentity;
/** @var EntityManager Doctrine entity manager */
private $em;
}
我使用一些合理的默认值运行 php-cs-fixer 命令
php-cs-fixer fix src/AppBundle/Entity/AclEntriesDEBUG.php --rules=@PSR2,@Symfony
该文件得到了很好的清理,但是所有到 AppBundle 的 phpdoc 导入都被删除为未使用
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\EntityManager;
class AclEntries
{
/** @var AclObjectIdentities Object identity */
private $objectIdentity;
/** @var EntityManager Doctrine entity manager */
private $em;
}
对我来说,预期的行为应该是“所有导入都是平等的”并且“使用 AppBundle ...”不会被剥夺。
解决方案
从您当前所在的同一命名空间导入无效,因为 PHP 会自动导入它。这就是 PHP CS Fixer 删除它们的原因。如果即使不需要它们也想保留它们,no_unused_imports
请从配置中删除规则,例如:
php-cs-fixer fix src/AppBundle/Entity/AclEntriesDEBUG.php --rules=@PSR2,@Symfony,-no_unused_imports
推荐阅读
- python - Numpy 挤压 - 'list' 对象没有属性 'squeeze'
- google-apps-script - 仅从单独的 Google 表格复制格式
- pandas - Pandas:将两个数据框列组合在一个排序列中
- java - 如何在 JTable 中用不同颜色绘制特定列?
- postgresql - Split column into two columns in a migration
- html - 我无法让所有元素保持在同一条线上
- google-maps - 是否可以在 Google Maps API 中注册 URL 或域?
- java - 如何将信息从活动传递到自定义警报对话框中的编辑文本
- r - genRandomClust 似乎没有生成随机簇
- python - 在 Windows 上使用 C 扩展 Python - ImportError:DLL 加载失败:%1 不是有效的 Win32 应用程序