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

DevKit updates for 3.x branch #598

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
Expand All @@ -41,7 +40,6 @@
$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
$rectorConfig->skip([
CountOnNullRector::class,
ExceptionHandlerTypehintRector::class,
AddSeeTestAnnotationRector::class,
PreferPHPUnitThisCallRector::class,
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/SonataIntlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private function configureLocale(ContainerBuilder $container, array $config): vo
* @param array<string> $timezones
*
* @throws \RuntimeException If one of the locales is invalid
*
* @phpstan-param array<non-empty-string> $timezones
*/
private function validateTimezones(array $timezones): void
{
Expand Down
8 changes: 7 additions & 1 deletion src/Helper/DateTimeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Helper/DateTimeFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions src/Twig/DateTimeRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down