How to add @deprecated to multiple classes/files

I would like to mark whole directories/namespaces  as deprecated.

Because of our saas-applications we have multiple versions which need to stay online, until nobody needs it anymore.

Our namespace/directories are like:

  • module\v100
  • module\v102
  • module\v201

etc.

Inside an 'older' directory all files have to be marked as deprecated. So we put  a `@deprecated` tag  (with timestamp and info) in the doc-block of the classes, traits, etc.

I have a regexp (from our netbeans time) for replace in directories to do this a bit automated.

([\r\n]\h*\*)(\/[\r\n]+(\h*(abstract|static))?\h*(class|trait|interface))

replace with:

$1 \@deprecated since 20210722 version v3$1$2


But I hope there is a nicer and quicker way.

nb. We are not on php8 yet :-(, so attributes is no option yet. 

Thanks in advance!
flexJoly

4 comments
Comment actions Permalink

I am afraid there is no option to do that automagically. However, you may want to use the SSR (Structural search and replace), for example, to search for classes. Just in case, a little bit more about it:

https://www.jetbrains.com/help/phpstorm/structural-search-and-replace.html

0
Comment actions Permalink

I did look to that, but can't get it to work.

Search:

/**
$doc$
*/
class $cl${}

filter for $doc$:

text=(.*)

replace with:

/**
$doc$
* @deprecated since 20210722 version v3
*/
class $cl${}

 

The search goes well.

/**
* Description of lightspeed_exception_empty
*
* @author xxx
*/
class EmptyData extends BaseException implements ExceptionInterface {

}


But replace gives:

/**
* Description of lightspeed_exception_empty
*
* @author xxx
*/

/**
* @deprecated since 20210722 version v3
*/
class EmptyData {

}

:-(

And this is only for a class.... but it should also find interfaces, traits etc.

I read the documentation over and over again. Also tried for replacement:

$docnw$

with script:

doc.getText()

 

Please help, thanks!

 

0
Comment actions Permalink

Tried to play around with SSR but with no luck either :( (got to try it again later)

Back to the original post, what seems to be a drawback from the Netbeans time regex replacement solution?

0
Comment actions Permalink

thanks for trying!!

The setback is that it is not saved like the SSR. 


And I hoped to find a nicer solution or maybe that phpStorm had a feature for this. I think I am not the only one, needing something like this.

 

0

Please sign in to leave a comment.