Use DatetimeImmutable instead of DateTime wherever possible

This commit is contained in:
Jan Böhmer 2024-06-22 17:36:54 +02:00
parent eebc373734
commit 235d572f8c
39 changed files with 222 additions and 112 deletions

View file

@ -81,7 +81,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
return 'anonymous';
}
$now = new DateTime();
$now = new \DateTimeImmutable();
if ('[[DATETIME]]' === $placeholder) {
$formatter = IntlDateFormatter::create(

View file

@ -42,7 +42,6 @@ declare(strict_types=1);
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\TimeStampableInterface;
use DateTime;
use IntlDateFormatter;
use Locale;
@ -57,11 +56,11 @@ final class TimestampableElementProvider implements PlaceholderProviderInterface
$formatter = new IntlDateFormatter(Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
if ('[[LAST_MODIFIED]]' === $placeholder) {
return $formatter->format($label_target->getLastModified() ?? new DateTime());
return $formatter->format($label_target->getLastModified() ?? new \DateTimeImmutable());
}
if ('[[CREATION_DATE]]' === $placeholder) {
return $formatter->format($label_target->getAddedDate() ?? new DateTime());
return $formatter->format($label_target->getAddedDate() ?? new \DateTimeImmutable());
}
}