Mon*_*key 1 php regex regex-negation phpstorm
我试图将严格的类型声明添加declare(strict_types=1);到特定目录下的所有 PHP 类和特征文件。
如何使用 Linux 终端获取没有该声明的文件列表?
如何使用 PhpStorm 添加缺失的声明(检查、替换路径 + 正则表达式)?
不带声明的示例 /src/Foobar.php:
<?php
/**
* class file
*/
namespace Foo\Bar;
use Other\Foo\Bar;
class Foobar {
// ..
}
Run Code Online (Sandbox Code Playgroud)
带有声明的示例 /src/Foobar.php:
<?php
/**
* class file
*/
declare(strict_types = 1);
namespace Foo\Bar;
use Other\Foo\Bar;
class Foobar {
// ..
}
Run Code Online (Sandbox Code Playgroud)
注释和导入(“使用”)在类文件中是可选的。
我做了什么:
您不需要为此使用正则表达式 - 只需使用内置的“快速修复”即可。
Code | Run Inspection by Name...Missing strict type declaration检查(例如,键入strict并从缩小的列表中选择它)并运行它查找要运行的检查:
应用修复(注意:我仅对包含示例代码作为内容的单个文件运行此检查):
或者 - 只需启用适当的检查(默认情况下禁用),您将能够通过通常的方式Alt + Enter(在 Windows 上使用默认键盘映射;或通过“灯泡”图标)直接在代码中添加此类代码:
设置/首选项| 编辑| 检查 | PHP | 类型兼容性 | 缺少严格的类型声明
快速修复菜单 ( Alt+Enter)
| 归档时间: |
|
| 查看次数: |
1058 次 |
| 最近记录: |