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.

  1. how can list of files without declaration using linux terminal?

  2. 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.

  1. select files/folder(s) wish run such stuff in project view panel
  2. code | run inspection name...
  3. find missing strict type declaration inspection there (e.g. type strict , select narrowed list) , run it
  4. confirm scope (where run inspection on)
  5. 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:

enter image description here

applying fix (note: i've run inspection on single file has sample code content):

enter image description here


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

enter image description here

quick fix menu (alt+enter)

enter image description here


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -