[Intl] Add format_list filter using PHP 8.5's IntlListFormatter#4852
Conversation
fabpot
left a comment
There was a problem hiding this comment.
It looks good to me.
Can you add a new doc/filters/format_list.rst file (see doc/filters/format_number.rst for an example), update doc/filters/index.rst to add format_list to the list and in extra/intl-extra/README.md?
Also, can you add an entry in CHANGELOG.md?
049faf5 to
79b2526
Compare
|
fc7e311 to
3fc0321
Compare
c6dc017 to
163f1b6
Compare
|
Thank you @BreyndotEchse. |
|
📋 PR Summary This PR adds a Changes
|
There was a problem hiding this comment.
📋 Upsun Dispatch Review: full · 8 files reviewed · 🔵 2 infos
Review details
Commit: Commit 163f1b6
Model: claude-opus-4-8
Panel: correctness · robustness · design
| throw new RuntimeError('The "format_list" filter requires the "IntlListFormatter" class, which is available since PHP 8.5.'); | ||
| } | ||
|
|
||
| return $this->createListFormatter($locale, $type, $width)->format($strings); |
There was a problem hiding this comment.
🔵 Info — Docblock may overpromise Stringable support the formatter does not accept.
The @param array<string|\Stringable> annotation on formatList advertises that \Stringable objects may be passed, but $strings is handed directly to \IntlListFormatter::format(). If the underlying formatter does not coerce \Stringable elements to strings, passing objects (which the annotation permits) raises a TypeError rather than formatting them. The test fixtures only cover plain strings, so this path is unverified.
| } | ||
|
|
||
| $types = [ | ||
| 'and' => \IntlListFormatter::TYPE_AND, |
There was a problem hiding this comment.
🔵 Info — Undocumented lazy pattern invites a refactor that breaks the extension on PHP < 8.5.
availableListTypes()/availableListWidths() reference the PHP 8.5-only constants \IntlListFormatter::TYPE_AND/WIDTH_WIDE etc., and are intentionally lazy methods (evaluated only after the class_exists guard in formatList) rather than const arrays like the sibling TIME_FORMATS/NUMBER_STYLES. Nothing documents that intent, so a maintainer harmonizing them into class constants would move constant evaluation to class-load time and break loading on PHP < 8.5.
Adds a new
format_listTwig filter to IntlExtension that formats arrays using using PHP 8.5's IntlListFormatterOn PHP < 8.5, using the filter throws a RuntimeError explaining the dependency on IntlListFormatter (Checks if
class_existsto allow polyfills).CI workflow only covered up to PHP 8.4, so I extended it to also run PHPUnit against 8.5.
phpstan's PHP version also bumped to 8.5.