Skip to content

Commit

Permalink
Merge pull request #775 from doctrine/use-date-time-immutable
Browse files Browse the repository at this point in the history
Use DateTimeImmutable instead of DateTime.
  • Loading branch information
jwage authored Jan 3, 2019
2 parents 67c8807 + a36de5a commit 8bb3422
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/Doctrine/Migrations/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\Migrations\Configuration;

use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Doctrine\Common\EventArgs;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 '';
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/Migrations/FileQueryWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\Migrations;

use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Migrations\Generator\FileBuilder;
use function file_put_contents;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8bb3422

Please sign in to comment.