Skip to content

Instantly share code, notes, and snippets.

@kanduvisla
Last active July 11, 2017 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanduvisla/7078b826f213d41dc439173c1db94901 to your computer and use it in GitHub Desktop.
Save kanduvisla/7078b826f213d41dc439173c1db94901 to your computer and use it in GitHub Desktop.
Various PHPStorm Find and replace regexes

Create Getters from Setters

Example:

public function setDescription(string $description): SomeInterface;

to:

public function getDescription(): string;

Regex:

find:       set(.*)\((.*) (.*)\):.*;
replace:    get$1(): $2;

Remove docblocks

find:       /\*.*\n.*\n.*(\n.*|)\*/
replace:

Convert Interface setters to implementations

...

to:

...

Regex:

find:       set(.*)\((.*) (\$.*)\): (.*);
replace:    set$1($2 $3): $4 { return \$this->setData(self::__KEY__, $3); }

Note: You need to replace __KEY__ yourself.

Convert Interface getters to implementations

...

to:

...

Regex:

find:       get(.*)\(\): (.*);
replace:    get$1(): $2 { return ($2) \$this->_get(self::__KEY__); }

Note: You need to replace __KEY__ yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment