Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Finder] Make Comparator immutable#42137

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:5.4fromderrabus:feature/immutable-comparator
Jul 18, 2021

Conversation

@derrabus
Copy link
Member

QA
Branch?5.4
Bug fix?no
New feature?yes
Deprecations?yes
TicketsN/A
LicenseMIT
Doc PRN/A

TheComparator class exposes setters for its properties$target and$operator. I'd consider this design to be flawed for the following reasons:

  • The$target property should be set before executing the main methodtest() on an instance of that class. However, we never make sure that this actually happens.
  • The two child classesDateComparator andNumberComparator set both properties via their constructors, after parsing them from a string. It's a bit odd to allow those properties to be overridden via the setters because all validation happens inside those constructors.

This PR proposes to remove those setters and introduce a constructor instead that allows to set both properties once.


$this->setTarget($target);
$this->setOperator($matches[1] ??'==');
parent::__construct($target,$matches[1] ?:'==');
Copy link
Contributor

Choose a reason for hiding this comment

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

did you change ?? to ?: on purpose?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yes.setOperator() accepted an empty string and I've made the constructor stricter in that regard.

@derrabusderrabusforce-pushed thefeature/immutable-comparator branch fromc937eec to4f0089bCompareJuly 15, 2021 21:21
}

$comparator =newComparator();
$comparator =newComparator('some target');
Copy link
Member

Choose a reason for hiding this comment

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

We have 2 tests in one here. Those should be split (which will also allow usingexpectException to test the exception) instead of this old way of writing tests that does not follow the best practices.

And the test about an invalid operator should also be added for the constructor.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

/**
* @dataProvider getTestData
*/
publicfunctiontestTest($operator,$target,$match,$noMatch)
Copy link
Member

Choose a reason for hiding this comment

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

The data provider for this test does not provide full coverage (it tests only one operator). Would it make sense to add other cases ?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

The tests for this class are indeed pretty sparse. I think the class is mainly tested by testing its subclasses.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

@derrabusderrabusforce-pushed thefeature/immutable-comparator branch from4f0089b to0ff3971CompareJuly 16, 2021 21:21
Tobion added a commit that referenced this pull requestJul 17, 2021
This PR was merged into the 4.4 branch.Discussion----------[Finder] Improve ComparatorTest| Q             | A| ------------- | ---| Branch?       | 4.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       |#42137 (comment),#42137 (comment)| License       | MIT| Doc PR        | not necessaryCommits-------4c44dce [Finder] Improve ComparatorTest
Signed-off-by: Alexander M. Turek <me@derrabus.de>
@fabpot
Copy link
Member

Thank you@derrabus.

@fabpotfabpotforce-pushed thefeature/immutable-comparator branch from0ff3971 tob83ead2CompareJuly 18, 2021 08:05
@fabpotfabpot merged commit15d76e1 intosymfony:5.4Jul 18, 2021
This was referencedNov 5, 2021
@derrabusderrabus deleted the feature/immutable-comparator branchNovember 21, 2021 12:58
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@TobionTobionTobion approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

5 participants

@derrabus@fabpot@stof@Tobion@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp