diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9825f9fe..eb1ea74b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,13 +50,18 @@ jobs: - php-version: '8.2' dependencies: highest allowed-to-fail: false - symfony-require: 6.2.* - variant: symfony/symfony:"6.2.*" + symfony-require: 6.3.* + variant: symfony/symfony:"6.3.*" - php-version: '8.2' dependencies: highest allowed-to-fail: false - symfony-require: 6.3.* - variant: symfony/symfony:"6.3.*" + symfony-require: 6.4.* + variant: symfony/symfony:"6.4.*" + - php-version: '8.2' + dependencies: highest + allowed-to-fail: false + symfony-require: 7.0.* + variant: symfony/symfony:"7.0.*" steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index 33597078..d011dbc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [3.2.0](https://github.com/sonata-project/SonataIntlBundle/compare/3.1.0...3.2.0) - 2023-12-07 +### Added +- [[#595](https://github.com/sonata-project/SonataIntlBundle/pull/595)] Support for packages from `symfony/*` 7.x ([@phansys](https://github.com/phansys)) + +### Fixed +- [[#598](https://github.com/sonata-project/SonataIntlBundle/pull/598)] Passing an empty string as argument 1 to `\DateTimeZone` at `DateTimeFormatter::getDatetime()` ([@phansys](https://github.com/phansys)) + ## [3.1.0](https://github.com/sonata-project/SonataIntlBundle/compare/3.0.2...3.1.0) - 2023-04-25 ### Removed - [[#578](https://github.com/sonata-project/SonataIntlBundle/pull/578)] Drop support for Symfony 6.0 and 6.1. ([@jordisala1991](https://github.com/jordisala1991)) diff --git a/composer.json b/composer.json index 72d1e0f8..c1ef847a 100644 --- a/composer.json +++ b/composer.json @@ -23,18 +23,18 @@ "homepage": "https://docs.sonata-project.org/projects/SonataIntlBundle", "require": { "php": "^8.0", - "symfony/config": "^5.4 || ^6.2", - "symfony/dependency-injection": "^5.4 || ^6.2", - "symfony/http-foundation": "^5.4 || ^6.2", - "symfony/http-kernel": "^5.4 || ^6.2", - "symfony/intl": "^5.4 || ^6.2", + "symfony/config": "^5.4 || ^6.2 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.2 || ^7.0", + "symfony/http-foundation": "^5.4 || ^6.2 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.2 || ^7.0", + "symfony/intl": "^5.4 || ^6.2 || ^7.0", "symfony/translation-contracts": "^2.5 || ^3.0", "twig/twig": "^3.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.4", - "matthiasnoback/symfony-config-test": "^4.2", - "matthiasnoback/symfony-dependency-injection-test": "^4.0", + "matthiasnoback/symfony-config-test": "^4.2 || ^5.1", + "matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^1.0", "phpstan/phpstan-phpunit": "^1.0", @@ -45,7 +45,7 @@ "psalm/plugin-symfony": "^5.0", "rector/rector": "^0.18", "symfony/phpunit-bridge": "^6.2", - "symfony/security-core": "^5.4 || ^6.2", + "symfony/security-core": "^5.4 || ^6.2 || ^7.0", "vimeo/psalm": "^5.0" }, "conflict": { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 083ddb18..d19f871c 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -27,9 +27,7 @@ final class Configuration implements ConfigurationInterface { /** - * @psalm-suppress PossiblyNullReference, UndefinedInterfaceMethod - * - * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 + * @psalm-suppress UndefinedInterfaceMethod */ public function getConfigTreeBuilder(): TreeBuilder { diff --git a/src/DependencyInjection/SonataIntlExtension.php b/src/DependencyInjection/SonataIntlExtension.php index 9e63200f..3eba5294 100644 --- a/src/DependencyInjection/SonataIntlExtension.php +++ b/src/DependencyInjection/SonataIntlExtension.php @@ -105,6 +105,8 @@ private function configureLocale(ContainerBuilder $container, array $config): vo * @param array $timezones * * @throws \RuntimeException If one of the locales is invalid + * + * @phpstan-param array $timezones */ private function validateTimezones(array $timezones): void { diff --git a/src/Helper/DateTimeFormatter.php b/src/Helper/DateTimeFormatter.php index 0c65d913..fecf93f1 100644 --- a/src/Helper/DateTimeFormatter.php +++ b/src/Helper/DateTimeFormatter.php @@ -135,9 +135,15 @@ public function getDatetime( } } + $timezone ??= $this->timezoneDetector->getTimezone(); + + if (null === $timezone || '' === $timezone) { + throw new \InvalidArgumentException('Invalid timezone provided'); + } + $date = new \DateTime(); $date->setTimestamp($data); - $date->setTimezone(new \DateTimeZone($timezone ?? $this->timezoneDetector->getTimezone() ?? '')); + $date->setTimezone(new \DateTimeZone($timezone)); return $date; } diff --git a/src/Helper/DateTimeFormatterInterface.php b/src/Helper/DateTimeFormatterInterface.php index 84c5fbda..682ceb67 100644 --- a/src/Helper/DateTimeFormatterInterface.php +++ b/src/Helper/DateTimeFormatterInterface.php @@ -24,6 +24,8 @@ interface DateTimeFormatterInterface { /** * @param int|null $dateType See \IntlDateFormatter::getDateType + * + * @phpstan-param non-empty-string|null $timezone */ public function formatDate( \DateTimeInterface|string|int $date, @@ -35,6 +37,8 @@ public function formatDate( /** * @param int|null $dateType See \IntlDateFormatter::getDateType * @param int|null $timeType See \IntlDateFormatter::getTimeType + * + * @phpstan-param non-empty-string|null $timezone */ public function formatDateTime( \DateTimeInterface|string|int $datetime, @@ -46,6 +50,8 @@ public function formatDateTime( /** * @param int|null $timeType See \IntlDateFormatter::getTimeType + * + * @phpstan-param non-empty-string|null $timezone */ public function formatTime( \DateTimeInterface|string|int $time, @@ -54,6 +60,9 @@ public function formatTime( ?int $timeType = null ): string; + /** + * @phpstan-param non-empty-string|null $timezone + */ public function format( \DateTimeInterface|string|int $datetime, string $pattern, @@ -63,6 +72,8 @@ public function format( /** * Gets a date time instance by a given data and timezone. + * + * @phpstan-param non-empty-string|null $timezone */ public function getDatetime( \DateTimeInterface|string|int $data, diff --git a/src/Twig/DateTimeRuntime.php b/src/Twig/DateTimeRuntime.php index 2cd3ee76..159e8e29 100644 --- a/src/Twig/DateTimeRuntime.php +++ b/src/Twig/DateTimeRuntime.php @@ -22,6 +22,9 @@ public function __construct(private DateTimeFormatterInterface $helper) { } + /** + * @phpstan-param non-empty-string|null $timezone + */ public function formatDate( \DateTimeInterface|string|int $date, ?string $pattern = null, @@ -36,6 +39,9 @@ public function formatDate( return $this->helper->formatDate($date, $locale, $timezone, $dateType); } + /** + * @phpstan-param non-empty-string|null $timezone + */ public function formatTime( \DateTimeInterface|string|int $time, ?string $pattern = null, @@ -50,6 +56,9 @@ public function formatTime( return $this->helper->formatTime($time, $locale, $timezone, $timeType); } + /** + * @phpstan-param non-empty-string|null $timezone + */ public function formatDatetime( \DateTimeInterface|string|int $time, ?string $pattern = null,