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

Fix assertions in tests #7831

Merged
merged 4 commits into from
May 24, 2022

Conversation

VincentLanglet
Copy link
Member

No description provided.

@VincentLanglet VincentLanglet marked this pull request as ready for review May 23, 2022 18:23
@VincentLanglet VincentLanglet requested review from a team and jordisala1991 May 23, 2022 18:42
@@ -13,9 +13,6 @@

namespace Sonata\AdminBundle\Filter\Model;

/**
* @psalm-immutable
Copy link
Member

Choose a reason for hiding this comment

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

Why you removed this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because currently it's not really immutable

52     @readonly property Sonata\AdminBundle\Filter\Model\FilterData::$type   
         is assigned outside of the constructor.                                
  56     @readonly property Sonata\AdminBundle\Filter\Model\FilterData::$value  
         is assigned outside of the constructor.                                
  57     @readonly property                                                     
         Sonata\AdminBundle\Filter\Model\FilterData::$hasValue is assigned      
         outside of the constructor.          

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is a bug in psalm, those properties are accessed in a named constructor, that doesn't make the class mutable

jordisala1991
jordisala1991 previously approved these changes May 23, 2022
Copy link
Member

@franmomu franmomu left a comment

Choose a reason for hiding this comment

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

I think we should ignore those false positives instead of removing the immutability

@VincentLanglet
Copy link
Member Author

I think we should ignore those false positives instead of removing the immutability

I don't consider this like a false positive.

The @readonly doc say

Used to annotate a property that can only be written to in its defining class's constructor.

We're not writting them in the class-constructor but in a custom method fromArray.
Psalm is not reporting an error for https://psalm.dev/r/aa6df26b17, but I consider this to be immutable since I changed the value multiples times.

I you want this class to be really immutable you should use the constructor ; it would be a BC PR since the constructor is private

@franmomu
Copy link
Member

franmomu commented May 24, 2022

We're not writting them in the class-constructor but in a custom method fromArray. Psalm is not reporting an error for https://psalm.dev/r/aa6df26b17, but I consider this to be immutable since I changed the value multiples times.

That's like if in the constructor you change the value multiple times, at the end is about getting a new object.

I you want this class to be really immutable you should use the constructor ; it would be a BC PR since the constructor is private

Being the constructor private is what prevents us from BC break, since we can change it and call it from fromArray with the three values.

@VincentLanglet VincentLanglet merged commit a439577 into sonata-project:4.x May 24, 2022
@VincentLanglet VincentLanglet deleted the fixTestsAssert branch May 24, 2022 09:29
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.

3 participants