rector-downgrade-php icon indicating copy to clipboard operation
rector-downgrade-php copied to clipboard

[DowngradePhp80] Add `DowngradeStringableInterfaceRector`

Open osbre opened this issue 1 year ago • 1 comments

PHP 8 added the \Stringable interface.

Downgrade rule implementation would include:

  • Removal of implements \Stringable from classes.
  • Replacement of the expression $a instanceof \Stringable to something like method_exists($a, '__toString')

Refs:

  • https://www.php.net/manual/en/class.stringable.php
  • https://grep.app/search?q=instanceof%20Stringable
  • https://grep.app/search?q=implements%20Stringable

Perhaps a "feature" label can be added to this issue.

osbre avatar Apr 24 '24 19:04 osbre

For remove implements Stringable, it actually already applied by configurable RemoveInterfacesRector

https://github.com/rectorphp/rector-downgrade-php/blob/4228a7305efbd92687cf7f6cbf7b683a28412eb1/config/set/downgrade-php80.php#L44-L48

Ref https://getrector.com/demo/47d27225-1e6b-4855-91d5-9d6c4a1c4a14

The instanceof Stringable check is that what we need, as currently still not applied

Ref https://getrector.com/demo/d29a298b-8bbc-467c-ae35-9e2c91163b9d

samsonasik avatar May 11 '24 12:05 samsonasik