regex - How can I find all php class files without strict_types declaration (RegExp / PhpStorm) -
i'm trying add strict type declaration declare(strict_types=1);
php class , trait files under specific directory.
how can list of files without declaration using linux terminal?
how can add missing declarations using phpstorm (inspection, replace in path + regexp)?
example /src/foobar.php without declaration:
<?php /** * class file */ namespace foo\bar; use other\foo\bar; class foobar { // .. }
example /src/foobar.php declaration:
<?php /** * class file */ declare(strict_types = 1); namespace foo\bar; use other\foo\bar; class foobar { // .. }
comments , imports ("use") optional within class file.
what i've done:
- trying find phpstorm inspection want
- trying regularexpressions didn't find statement searching lack of within multi-row context
you not need regex - use built-in "quick fix" that.
- select files/folder(s) wish run such stuff in project view panel
code | run inspection name...
- find
missing strict type declaration
inspection there (e.g. typestrict
, select narrowed list) , run it - confirm scope (where run inspection on)
- see results -- may apply quick fix (many ways -- @ least 3 shown on screen) -- can done on per file basis in 1 go
screenshots:
finding inspection run:
applying fix (note: i've run inspection on single file has sample code content):
alternatively -- enable appropriate inspection (which disabled default) , able add such code via usual alt + enter (on windows using default keymap; or via "light bulb" icon) directly in code:
settings/preferences | editor | inspections | php | type compatibility | missing strict type declaration
quick fix menu (alt+enter
)
Comments
Post a Comment