[英]How can I find all php class files without strict_types declaration (RegExp / PhpStorm)
I'm trying to add the strict type declaration declare(strict_types=1);
我正在尝试添加严格类型声明
declare(strict_types=1);
to all PHP class and trait files under a specific directory. 到特定目录下的所有PHP类和特征文件。
How can I get a list of files without that declaration using Linux terminal? 如何使用Linux终端获取没有声明的文件列表?
How can I add missing declarations using PhpStorm (inspection, replace in path + regexp)? 如何使用PhpStorm添加缺失的声明(检查,路径+ regexp中的替换)?
Example /src/Foobar.php without declaration: 示例/src/Foobar.php没有声明:
<?php
/**
* class file
*/
namespace Foo\Bar;
use Other\Foo\Bar;
class Foobar {
// ..
}
Example /src/Foobar.php with declaration: 带声明的示例/src/Foobar.php:
<?php
/**
* class file
*/
declare(strict_types = 1);
namespace Foo\Bar;
use Other\Foo\Bar;
class Foobar {
// ..
}
Comments and imports ("use") are optional within a class file. 注释和导入(“use”)在类文件中是可选的。
What I've done: 我做了什么:
You do not need regex for this - just use built-in "quick fix" for that. 你不需要正则表达式 - 只需使用内置的“快速修复”。
Code | Run Inspection by Name...
Missing strict type declaration
inspection there (eg type strict
and select it from narrowed list) and run it Missing strict type declaration
检查(例如,键入strict
并从缩小列表中选择它)并运行它 Finding inspection to run: 寻找运行检查:
Applying the fix (NOTE: I've run this inspection on single file only that has your sample code as content): 应用此修复程序(注意:我只对包含示例代码作为内容的单个文件运行此检查):
Alternatively -- just enable appropriate inspection (which is disabled by default) and you will be able to add such code via usual Alt + Enter (on Windows using Default keymap; or via "light bulb" icon) directly in the code: 或者 - 只需启用适当的检查(默认情况下禁用),您就可以通过常规的Alt + Enter (在Windows上使用默认键盘映射;或通过“灯泡”图标)直接在代码中添加此类代码:
Settings/Preferences | 设置/首选项| Editor |
编辑| Inspections |
检查| PHP |
PHP | Type Compatibility |
类型兼容性| Missing strict type declaration
缺少严格的类型声明
Quick fix menu ( Alt+Enter
) 快速修复菜单(
Alt+Enter
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.