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

Move getter from TaggedAdminInterface to AdminInterface #6713

Merged
merged 6 commits into from
Jan 1, 2021

Conversation

VincentLanglet
Copy link
Member

@VincentLanglet VincentLanglet commented Dec 16, 2020

Subject

I am targeting this branch, because BC. Because the TaggedAdminInterface is not released.
After the merge, I will edit the previous changelog.

Moving getListModes to AbstractTaggedAdmin is consistent with others changes and allow to restrict the visibility of the listModes property to private in nextMajor.

I also

  • Update the 3.x comments since I'm fixing conflicts
  • Fix some issues I find during the merge from 3.x into master

Changelog

### Added
- Added `AbstractTaggedAdmin::getListModes()`.
- Added `TaggedAdminInterface::getListModes()`.

@VincentLanglet VincentLanglet requested review from a team and franmomu December 16, 2020 22:18
@VincentLanglet VincentLanglet mentioned this pull request Dec 16, 2020
@VincentLanglet VincentLanglet force-pushed the listMode branch 2 times, most recently from ce73390 to d407edb Compare December 16, 2020 23:26
/**
* @return array<string, array<string, mixed>>
*/
public function getListModes();
Copy link
Member

@franmomu franmomu Dec 17, 2020

Choose a reason for hiding this comment

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

why this method should be in this interface? listModes does not sound like should be in the tagged part.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's tricky but it's related to the method showMosaicButton().

showMosaicButton is kinda the setter of the property listModes , and getListModes the getter.

@VincentLanglet
Copy link
Member Author

Please review @sonata-project/contributors. I'd like to merge 3.x into master after this.

Is it ok for you @franmomu ?

/**
* @return array<string, array<string, mixed>>
*/
public function getListModes();
Copy link
Member

Choose a reason for hiding this comment

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

Keep in mind, that this is a BC break.

The new interface is not released, so this is okay for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I take advantage of the fact it's not released :)

core23
core23 previously approved these changes Dec 18, 2020
@VincentLanglet VincentLanglet requested a review from a team December 18, 2020 22:05
@franmomu
Copy link
Member

Is it ok for you @franmomu ?

To be honest, I'm not sure, it feels like mixing things here.

Reading #6614, if the idea of this interface is to add setters for what is configurable with sonata.admin tag, I guess getters should not go in the interface.

In this particular case I guess that showMosaicButton should maybe just store a boolean flag to see if it should show the mosaic button or not and maybe getListModes rely on that flag.

@VincentLanglet
Copy link
Member Author

Is it ok for you @franmomu ?

To be honest, I'm not sure, it feels like mixing things here.

Reading #6614, if the idea of this interface is to add setters for what is configurable with sonata.admin tag, I guess getters should not go in the interface.

I added a commit. WDYT about it now ?

  • Setters are in AdminTaggedInterface
  • Getters are in AdminInterface
  • Both are in AbstractAdminTagged since it's easier this way and this allow to use private property.

In the next major we could work on removing the fact that the AdminInterface extends the AdminTaggedInterface.

@VincentLanglet
Copy link
Member Author

VincentLanglet commented Dec 19, 2020

The psalm error is weird:

  • It's working on 3.x but not my branch
  • I can fix it by commenting
public function getNewInstance()
    {
        $object = $this->getModelManager()->getModelInstance($this->getClass());

        // $this->appendParentObject($object);

        foreach ($this->getExtensions() as $extension) {
            $extension->alterNewInstance($this, $object);
        }

        return $object;
    }
  • I also can fix it by changing
final protected function appendParentObject(object $object): void

to

final protected function appendParentObject($object): void

@VincentLanglet
Copy link
Member Author

I didn't solve this weird psalm issue, so I added psalm-suppress. This is ready @sonata-project/contributors

@VincentLanglet VincentLanglet changed the title Move getListModes into TaggedAdminInterface Move getter from TaggedAdminInterface to AdminInterface Dec 20, 2020
@VincentLanglet
Copy link
Member Author

I finally find out how to solve my issue @sonata-project/contributors cc @franmomu

@franmomu
Copy link
Member

I added a commit. WDYT about it now ?

  • Setters are in AdminTaggedInterface
  • Getters are in AdminInterface
  • Both are in AbstractAdminTagged since it's easier this way and this allow to use private property.

In the next major we could work on removing the fact that the AdminInterface extends the AdminTaggedInterface.

I don't think getters should be in AbstractAdminTagged, if they are in AdminInterface, AbstractAdmin is the one implementing that interface not AbstractAdminTagged.

@VincentLanglet
Copy link
Member Author

I don't think getters should be in AbstractAdminTagged, if they are in AdminInterface, AbstractAdmin is the one implementing that interface not AbstractAdminTagged.

That's why I first put the getters in the TaggedAdminInterface.

I dont se any interest putting getters in AbstractAdmin and setters in AbstractTaggedAdmin.

Having both in AbstractTaggedAdmin allows to restrict the visibility of the class property to private.

It's true that to use the admin tag, only the setter are needed, so the interface should only have the setters. But our implementation can be provided with the getters too ; that's not forbidden.

@VincentLanglet VincentLanglet added this to the 4.0 milestone Dec 23, 2020
@VincentLanglet
Copy link
Member Author

VincentLanglet commented Dec 28, 2020

Can we finish this @franmomu (cc @sonata-project/contributors)

Having both getter and setter in AbstractTaggedAdmin is easier in order to restrict the property visibility, which is something we want to do in the next Major. I think it's easier this way.

Then, I would say we can

  • Have getters in TaggedAdminInterface, because it's easier (what was currently done)
  • Have getters in AdminInterface, because it reflect more the reality (what is currently done in the PR, asked by @franmomu). But it doesn't forbid to have getter in the Abstract class.

For a longer explanation from slack:

There are multiple solutions. Recently I discovered that to use the admin tag, the admin class should have a specific constructor signature and some setters, which wasn’t in the AdminInterface.
So I created a TaggedAdminInterface and an AbstractTaggedAdmin with all of this, and move some existings setters and getters from the AdminInterface to the tagged one. But I forgot one !

In this PR, I wanted to move the last one, but then franmomu said that the TaggedAdminInterface should only have the setters and not the getters. This is theorically true, since the TaggedAdminInterface is only related to the admin tag. So I move back the getters from the TaggedAdminInterface to the AdminInterface ; but I still let the getters in the AbstractTaggedAdmin, which allow me to restrict the property to private.

I see 3 solutions:

  • Getters in AbstractAdmin and AdminInterface: Cannot restrict the visibility of property, but do not duplicate the phpdoc.
  • Getters in AbstractTaggedAdmin and AdminInterface: Both interface reflect the reality, the visibility of the AbstractTaggedAdmin can be private but the phpdoc have to be duplicated for getters (since AbstractTaggedAdmin only implements TaggedAdminInterface)
  • Getters in AbstractTaggedAdmin and TaggedAdminInterface: The visibility can be private, the phpdoc is not duplicated, the TaggedAdminInterface does not reflect the reality (since getters are not needed for the admin tag theorically) but is it important ? This interface is not really supposed to be implemented alone without the AdminInterface implementation.

I personnaly prefer the option 3, but I’m ok with the second one.

@VincentLanglet
Copy link
Member Author

Since @OskarStark agree with me on the option 3, I updated the PR.

This just need your +1 @sonata-project/contributors ;)

@franmomu
Copy link
Member

Having both getter and setter in AbstractTaggedAdmin is easier in order to restrict the property visibility, which is something we want to do in the next Major. I think it's easier this way.

Why do we want to restrict the property visibility of these properties in the abstract class? Having simple setters and getters for the property it's almost like if they were public.

@VincentLanglet
Copy link
Member Author

Why do we want to restrict the property visibility of these properties in the abstract class? Having simple setters and getters for the property it's almost like if they were public.

It's not the same.
Getter/Setter:

  • will be final
  • will have typehint

@franmomu
Copy link
Member

Why do we want to restrict the property visibility of these properties in the abstract class? Having simple setters and getters for the property it's almost like if they were public.

It's not the same.
Getter/Setter:

  • will be final
  • will have typehint

What's preventing having getters and setters with type declaration?

For the final modifier, to me AbstractTaggedAdmin looks more like a trait than an abstract class.

@VincentLanglet
Copy link
Member Author

Why do we want to restrict the property visibility of these properties in the abstract class? Having simple setters and getters for the property it's almost like if they were public.

It's not the same.
Getter/Setter:

  • will be final
  • will have typehint

What's preventing having getters and setters with type declaration?

  • Setting a property which does not respect the type declaration.
  • Accessing the null property without setting

For the final modifier, to me AbstractTaggedAdmin looks more like a trait than an abstract class.

There was already a discussion about this.
Fact is we currently rely on the constructor signature in the compiler pass and a trait cannot have a constructor.
The taggedAdmin was the shortest way to respect all the condition of the compiler pass, but it was planned to refactor this for 5.0:

  • Stop relying on the constructor
  • Changing the class to a trait.

@VincentLanglet
Copy link
Member Author

I created #6723 @franmomu

Copy link
Member

@wbloszyk wbloszyk left a comment

Choose a reason for hiding this comment

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

Looks good for me. IMO You should not add release version in this PR but do it in seperate dediated PR.

@VincentLanglet VincentLanglet merged commit 5f8d438 into sonata-project:3.x Jan 1, 2021
@VincentLanglet VincentLanglet deleted the listMode branch January 1, 2021 23:24
@franmomu
Copy link
Member

franmomu commented Jan 2, 2021

Fact is we currently rely on the constructor signature in the compiler pass and a trait cannot have a constructor.

Why not? https://3v4l.org/pJV5D

I'm not sure if these getters should be final, I was going to try to use a Service Locator to inject all these services and I have to override the getters in order to use the service locator.

@VincentLanglet
Copy link
Member Author

Fact is we currently rely on the constructor signature in the compiler pass and a trait cannot have a constructor.

Why not? https://3v4l.org/pJV5D

Didnt know it worked. The first time I used Trait, all I see on internet was that constructor in Trait should never be done because it was a bad practice. I think it's because Trait should be seen like helpers and should have nothing to do with the class instantiation ; and overriding a trait constructor is maybe difficult.

I'm not sure if these getters should be final, I was going to try to use a Service Locator to inject all these services and I have to override the getters in order to use the service locator.

Firstly, I was following the whole "close API" strategy.

Secondly, If the admin tag is provided, the setters will be called by the compiler pass, so properties will be set and I don't see why it would be needed to change the getters in this case. So final made sens to me.

Can you develop your idea with service locators ? Does it mean you won't use the "admin" tag ?

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

Successfully merging this pull request may close these issues.

5 participants