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

Use constructor property promotion for ContactBundle classes #7435

Merged
merged 7 commits into from
Jun 19, 2024

Conversation

mamazu
Copy link
Contributor

@mamazu mamazu commented May 18, 2024

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets -
Related issues/PRs #7325
License MIT
Documentation PR -

What's in this PR?

Using constructor property promotion for the Contact Bundle.

Why?

Less code = Better

@mamazu mamazu added the DX Affecting the end developer label May 18, 2024
@mamazu mamazu force-pushed the cpp_contact branch 2 times, most recently from ff51a3a to 5c9bb57 Compare May 18, 2024 13:05
@@ -81,31 +66,22 @@ class ContactManager extends AbstractContactManager implements DataProviderRepos
*/
protected $userRepository;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly we can't promote protected properties as this would enforce the types on the properties (and be a bc break). I don't think they should have been protected in the first place though.

Copy link
Member

Choose a reason for hiding this comment

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

We could still promote them just with phpdoc instead of hardcoded type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would remove the typehint for the constructor but once all types and the doc comments are gone, this should be a good solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, I don't think this is a huge bc break. Because if you put any other classes into that property the class is going to crash anyways. So I think promoting that and keeping the typehint should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

We should keep a eye if everywhere the Interfaces if exists of the service was used. Else I think its not a problem as then service decoration and overwrite by inheritance works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do, it's probably not the last time that I'll go over classes. And specific types should be replaced with interfaces whereever possible anyways.

@mamazu mamazu changed the title Using constructor PropertyPromotion in ContactBundle [Contact] Using constructor property promotion Jun 15, 2024
$listBuilder->setIdField($fieldDescriptors['id']);
$listBuilder->where($fieldDescriptors['account'], $id);
$listBuilder->sort($fieldDescriptors['lastName'], $listBuilder::SORTORDER_ASC);
if ($listBuilder instanceof DoctrineListBuilder) {
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid such changes in this kind of refactors. Also in this case we should just assert that $listBuilder is DoctrineListBuilder so \assert($listBuilder instanceof DoctrineListBuilder); after $this->listBuilderFactory->create would be better. but also @var is in this case enough as the DoctrineListBuilderFactoryInterface always returns a DoctrineListBuilder and the controller should so not care and would require to fix it with generics in the list builder interfaces classes itself. But as said that kind of tasks should be in seperate pull request to keep things concentrated on one single refactors.

@alexander-schranz alexander-schranz changed the title [Contact] Using constructor property promotion Use constructor property promotion for ContactBundle classes Jun 19, 2024
@alexander-schranz alexander-schranz merged commit 77546fe into sulu:2.5 Jun 19, 2024
7 of 8 checks passed
@alexander-schranz
Copy link
Member

@mamazu Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants