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 MonthSelect removing inheritance and improving tests #200

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

ramchale
Copy link
Contributor

@ramchale ramchale commented Nov 18, 2024

Q A
Documentation yes
Bugfix no
BC Break yes
New Feature no
RFC yes
QA no

Description

Draft pull request to discuss desired behavior of MonthSelect in v3. Some of this will also be relevant to other classes extending AbstractDateDropdown.

  • Currently this throws a RuntimeException if an array is passed to the filter with the incorrect number of date parts. Should just pass through unprocessed for consistency with other filters?
  • How do you want this to handle months that are outside of a valid date range?
  • How do you want to handle values for month that are not numerical (strings, bools, null, etc)? (I'm guessing the original value should be returned unprocessed, but better not to assume)

@gsteel
Copy link
Member

gsteel commented Nov 18, 2024

Looks to me like expected input is, like you say, an associative array of varying lengths depending on the descendant class that should produce a formatted string. The filter requires that array members be specificly year, month etc, so it's already very restrictive - I really don't see the point of this filter at all - I mean, on the frontend, why not just use an <input type="date|datetime-local"> - this filter pre-dates HTML5, so I'm wondering if we should just deprecate all of it and remove it completely.

cc @froschdesign

@ramchale
Copy link
Contributor Author

Cool. Does that apply to the other two that inherit from AbstractDateDropdown (DateSelect and DateTimeSelect), as they share a lot of the same behavior at the moment?

@gsteel
Copy link
Member

gsteel commented Nov 18, 2024

I'd say all 4 classes, MonthSelect, Abstract, DateSelect & DateTimeSelect - Let's wait for @froschdesign to give us an opinion too 👍

@froschdesign
Copy link
Member

I'd say all 4 classes, MonthSelect, Abstract, DateSelect & DateTimeSelect…

Unfortunately, that won't work, because laminas-form uses these filters:

@ramchale
Copy link
Contributor Author

I'd say all 4 classes, MonthSelect, Abstract, DateSelect & DateTimeSelect…

Unfortunately, that won't work, because laminas-form uses these filters:

* `Laminas\Form\Element\DateSelect`: https://github.com/laminas/laminas-form/blob/653c869d10c361027ae6c660c991ec3e3f38ed65/src/Element/DateSelect.php#L175-L193

* `Laminas\Form\Element\DateTimeSelect`: https://github.com/laminas/laminas-form/blob/653c869d10c361027ae6c660c991ec3e3f38ed65/src/Element/DateTimeSelect.php#L335-L353

* `Laminas\Form\Element\MonthSelect`: https://github.com/laminas/laminas-form/blob/653c869d10c361027ae6c660c991ec3e3f38ed65/src/Element/MonthSelect.php#L325-L343

Thanks both. Does that bring us back to the questions about behavior in v3 or is there more to consider?

@gsteel
Copy link
Member

gsteel commented Nov 20, 2024

OK, so I think that in all erroneous cases, the filter(s) should return the unprocessed input that will hopefully then fail subsequent validation - so, out of range, incorrect array shapes etc should not throw exceptions, but just silently pass through unchanged.

I think we have to work on the premise that we're working with data that hasn't been validated. In typical usage with input-filter, throwing an exception for malformed input prevents validators from doing their job and reporting to the user that the input was rejected.

@froschdesign
Copy link
Member

OK, so I think that in all erroneous cases, the filter(s) should return the unprocessed input that will hopefully then fail subsequent validation - so, out of range, incorrect array shapes etc should not throw exceptions, but just silently pass through unchanged.

Based on the form elements from above: The validators Date and Regex can handle the unprocessed input arrays so that the validators can fulfil their jobs in all cases and produce the related error messages.

@ramchale ramchale force-pushed the MonthSelect branch 2 times, most recently from 6a43fa1 to f9f1f77 Compare December 7, 2024 10:39
@ramchale
Copy link
Contributor Author

ramchale commented Dec 7, 2024

I think this covers the desired behaviour. Let me know if there's anything not quite right, or any other test cases that would be useful. Once we've got the code doing what it should I'll look at adding some docs.

Also, psalm isn't loving returning $value after $month = $value['month'] ?? null;. While I don't want to restructure just to appease static analysis, if you've got any suggestions to avoid the error suppression that'd be useful.

src/MonthSelect.php Outdated Show resolved Hide resolved
src/MonthSelect.php Outdated Show resolved Hide resolved
src/MonthSelect.php Outdated Show resolved Hide resolved
src/MonthSelect.php Outdated Show resolved Hide resolved
src/MonthSelect.php Show resolved Hide resolved
src/MonthSelect.php Outdated Show resolved Hide resolved
test/MonthSelectTest.php Show resolved Hide resolved
test/MonthSelectTest.php Outdated Show resolved Hide resolved
@ramchale
Copy link
Contributor Author

ramchale commented Dec 9, 2024

Thanks. Still needs the suppression for the return statement, but the rest is looking a lot healthier

Copy link
Member

@gsteel gsteel left a comment

Choose a reason for hiding this comment

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

Thanks @ramchale - I figured out the reason for the InvalidReturnStatement - Sorry to be pedantic 😬

src/MonthSelect.php Show resolved Hide resolved
src/MonthSelect.php Outdated Show resolved Hide resolved
src/MonthSelect.php Outdated Show resolved Hide resolved
@ramchale
Copy link
Contributor Author

ramchale commented Dec 9, 2024

Thanks @ramchale - I figured out the reason for the InvalidReturnStatement - Sorry to be pedantic 😬

No. Really appreciate the feedback and help. Thanks

Copy link
Member

@gsteel gsteel left a comment

Choose a reason for hiding this comment

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

Thanks @ramchale 👍

@gsteel gsteel self-assigned this Dec 9, 2024
@gsteel gsteel added this to the 3.0.0 milestone Dec 9, 2024
@gsteel
Copy link
Member

gsteel commented Dec 9, 2024

Is there anything else needed here or can I merge it?

@gsteel gsteel changed the title WIP - Add more tests and start refactoring MonthSelect Refactor MonthSelect removing inheritance and improving tests Dec 9, 2024
@gsteel gsteel mentioned this pull request Dec 9, 2024
54 tasks
@ramchale
Copy link
Contributor Author

ramchale commented Dec 9, 2024

Is there anything else needed here or can I merge it?

I've got some accompanying documentation I can tidy up and add to the v2_to_v3.md and standard-filters.md this afternoon. So might want to hold off for that?

@gsteel
Copy link
Member

gsteel commented Dec 9, 2024

I've got some accompanying documentation I can tidy up and add to the v2_to_v3.md and standard-filters.md this afternoon. So might want to hold off for that?

Cool - I'll wait for the docs so they go in together 👍

@ramchale ramchale marked this pull request as ready for review December 9, 2024 14:17
Signed-off-by: ramchale <[email protected]>
Copy link
Member

@gsteel gsteel left a comment

Choose a reason for hiding this comment

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

Thanks again @ramchale 👌

@gsteel gsteel merged commit f7c2743 into laminas:3.0.x Dec 9, 2024
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants