From a36de5a9693db6efc4a35f030c27ca45b0090620 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Thu, 3 Jan 2019 01:16:16 +0000 Subject: [PATCH] Use DateTimeImmutable instead of DateTime. --- lib/Doctrine/Migrations/Configuration/Configuration.php | 8 ++++---- lib/Doctrine/Migrations/FileQueryWriter.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/Migrations/Configuration/Configuration.php b/lib/Doctrine/Migrations/Configuration/Configuration.php index e6555b4de5..f3d8efae0c 100644 --- a/lib/Doctrine/Migrations/Configuration/Configuration.php +++ b/lib/Doctrine/Migrations/Configuration/Configuration.php @@ -4,7 +4,7 @@ namespace Doctrine\Migrations\Configuration; -use DateTime; +use DateTimeImmutable; use DateTimeInterface; use DateTimeZone; use Doctrine\Common\EventArgs; @@ -97,7 +97,7 @@ public function __construct( $this->migrationFinder = $migrationFinder; $this->queryWriter = $queryWriter; $this->dependencyFactory = $dependencyFactory; - $this->migrationsColumnLength = strlen((new DateTime())->format(self::VERSION_FORMAT)); + $this->migrationsColumnLength = strlen((new DateTimeImmutable())->format(self::VERSION_FORMAT)); } public function setName(string $name) : void @@ -320,7 +320,7 @@ public function createMigrationTable() : bool public function getDateTime(string $version) : string { $datetime = str_replace('Version', '', $version); - $datetime = DateTime::createFromFormat(self::VERSION_FORMAT, $datetime); + $datetime = DateTimeImmutable::createFromFormat(self::VERSION_FORMAT, $datetime); if ($datetime === false) { return ''; @@ -331,7 +331,7 @@ public function getDateTime(string $version) : string public function generateVersionNumber(?DateTimeInterface $now = null) : string { - $now = $now ?: new DateTime('now', new DateTimeZone('UTC')); + $now = $now ?: new DateTimeImmutable('now', new DateTimeZone('UTC')); return $now->format(self::VERSION_FORMAT); } diff --git a/lib/Doctrine/Migrations/FileQueryWriter.php b/lib/Doctrine/Migrations/FileQueryWriter.php index 9bb74144d8..8a2b47205e 100644 --- a/lib/Doctrine/Migrations/FileQueryWriter.php +++ b/lib/Doctrine/Migrations/FileQueryWriter.php @@ -4,7 +4,7 @@ namespace Doctrine\Migrations; -use DateTime; +use DateTimeImmutable; use DateTimeInterface; use Doctrine\Migrations\Generator\FileBuilder; use function file_put_contents; @@ -41,7 +41,7 @@ public function write( array $queriesByVersion, ?DateTimeInterface $now = null ) : bool { - $now = $now ?? new DateTime(); + $now = $now ?? new DateTimeImmutable(); $string = $this->migrationFileBuilder ->buildMigrationFile($queriesByVersion, $direction, $now);