Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: PHP 8.0 constructor promotion #6924

Closed

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Nov 29, 2022

Needs #6923

Description
See #6921

Use constructor promotion.
This may contain breaking changes.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the 4.3 label Nov 29, 2022
@kenjis kenjis marked this pull request as draft November 29, 2022 07:37
@kenjis kenjis added the refactor Pull requests that refactor code label Nov 29, 2022
@kenjis
Copy link
Member Author

kenjis commented Nov 29, 2022

This is a breaking chage:
https://3v4l.org/BrHEP

@samsonasik
Copy link
Member

Yes, that seems need to be skipped

$this->autoloader = $autoloader;
public function __construct(
protected Autoloader $autoloader
) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if a dev extends FileLocator and it has protected $autoloader;,
this change is a breaking change.
https://3v4l.org/NhqDb

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are possible options:

  • make a note about property re-definition possible breaking change without add type
  • wait to push to 4.4 only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way;: make Rector extension to help user migrating to new definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing type in the constructor makes no errors (I don't know why),
https://3v4l.org/2A85L
but I don't want to remove already declared types in constructors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better way: make a patch to rector to:

  • skip non-typed property for protected/public property, except define INLINE_PUBLIC config that allow bc break on non-final class, same like TypedPropertyRector way

That's just quick guessing, probably there is a better way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kenjis here possibly the solution, I create PR to make it configurable INLINE_PUBLIC default false:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems the best approach to me. Glad your patch was already accepted!

@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Nov 29, 2022
@samsonasik
Copy link
Member

@kenjis some rules like StrEndsWithRector, StrStartsWithRector, StrContainsRector seems easy merge 👍 , define small PRs and iterate to next rules when possible.

@kenjis
Copy link
Member Author

kenjis commented Nov 29, 2022

If we drop PHP 7.4 in v4.4, I would like to type missing public/protected properties with constructor promotion.
These will be breaking changes, though.

@samsonasik
Copy link
Member

Yes, I agree 👍

@kenjis kenjis deleted the branch codeigniter4:4.3 January 10, 2023 06:36
@kenjis kenjis closed this Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 breaking change Pull requests that may break existing functionalities refactor Pull requests that refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants