Skip to content

Commit

Permalink
minor #4328 Improve formatDate methods phpdoc (VincentLanglet)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Improve formatDate methods phpdoc

`convertDate`
- Supports null https://github.com/twigphp/Twig/blob/3.x/src/Extension/CoreExtension.php#L539
- Supports timestamp passed as integer https://github.com/twigphp/Twig/blob/3.x/src/Extension/CoreExtension.php#L549

So the phpdoc should not be
`\DateTimeInterface|string|null` but `\DateTimeInterface|string|int|null`

And all the date methods using `convertDate` should also accepts int and null.

This is important since some tools are developing static analysis on twig.

Commits
-------

3be417d Improve date methods phpdoc
  • Loading branch information
fabpot committed Sep 21, 2024
2 parents 3f03d2b + 3be417d commit 49b699b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,9 @@ public static function random(string $charset, $values = null, $max = null)
*
* {{ post.published_at|date("m/d/Y") }}
*
* @param \DateTimeInterface|\DateInterval|string $date A date
* @param string|null $format The target format, null to use the default
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
* @param \DateTimeInterface|\DateInterval|string|int|null $date A date, a timestamp or null to use the current time
* @param string|null $format The target format, null to use the default
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
*/
public function formatDate($date, $format = null, $timezone = null): string
{
Expand All @@ -466,8 +466,8 @@ public function formatDate($date, $format = null, $timezone = null): string
*
* {{ post.published_at|date_modify("-1day")|date("m/d/Y") }}
*
* @param \DateTimeInterface|string $date A date
* @param string $modifier A modifier string
* @param \DateTimeInterface|string|int|null $date A date, a timestamp or null to use the current time
* @param string $modifier A modifier string
*
* @return \DateTime|\DateTimeImmutable
*
Expand Down Expand Up @@ -506,8 +506,8 @@ public static function dateConverter(Environment $env, $date, $format = null, $t
* {# do something #}
* {% endif %}
*
* @param \DateTimeInterface|string|null $date A date or null to use the current time
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
* @param \DateTimeInterface|string|int|null $date A date, a timestamp or null to use the current time
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged
*
* @return \DateTime|\DateTimeImmutable
*/
Expand Down

0 comments on commit 49b699b

Please sign in to comment.