Skip to content

Commit 2cb8075

Browse files
Remove unnecessary usages of DateTime
1 parent 0a49ff8 commit 2cb8075

File tree

40 files changed

+108
-131
lines changed

40 files changed

+108
-131
lines changed

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ public function updateToken(string $series, #[\SensitiveParameter] string $token
8989
$sql = 'UPDATE rememberme_token SET value=:value, lastUsed=:lastUsed WHERE series=:series';
9090
$paramValues = [
9191
'value' => $tokenValue,
92-
'lastUsed' => $lastUsed,
92+
'lastUsed' => \DateTimeImmutable::createFromInterface($lastUsed),
9393
'series' => $series,
9494
];
9595
$paramTypes = [
9696
'value' => ParameterType::STRING,
97-
'lastUsed' => Types::DATETIME_MUTABLE,
97+
'lastUsed' => Types::DATETIME_IMMUTABLE,
9898
'series' => ParameterType::STRING,
9999
];
100100
if (method_exists($this->conn, 'executeStatement')) {
@@ -118,14 +118,14 @@ public function createNewToken(PersistentTokenInterface $token)
118118
'username' => $token->getUserIdentifier(),
119119
'series' => $token->getSeries(),
120120
'value' => $token->getTokenValue(),
121-
'lastUsed' => $token->getLastUsed(),
121+
'lastUsed' => \DateTimeImmutable::createFromInterface($token->getLastUsed()),
122122
];
123123
$paramTypes = [
124124
'class' => ParameterType::STRING,
125125
'username' => ParameterType::STRING,
126126
'series' => ParameterType::STRING,
127127
'value' => ParameterType::STRING,
128-
'lastUsed' => Types::DATETIME_MUTABLE,
128+
'lastUsed' => Types::DATETIME_IMMUTABLE,
129129
];
130130
if (method_exists($this->conn, 'executeStatement')) {
131131
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
@@ -220,7 +220,7 @@ private function addTableToSchema(Schema $schema): void
220220
$table = $schema->createTable('rememberme_token');
221221
$table->addColumn('series', Types::STRING, ['length' => 88]);
222222
$table->addColumn('value', Types::STRING, ['length' => 88]);
223-
$table->addColumn('lastUsed', Types::DATETIME_MUTABLE);
223+
$table->addColumn('lastUsed', Types::DATETIME_IMMUTABLE);
224224
$table->addColumn('class', Types::STRING, ['length' => 100]);
225225
$table->addColumn('username', Types::STRING, ['length' => 200]);
226226
$table->setPrimaryKey(['series']);

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorWithDebugStackTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public static function paramProvider(): array
115115
[true, [], true, true],
116116
[null, [], null, true],
117117
[new \DateTime('2011-09-11'), ['date'], '2011-09-11', true],
118+
[new \DateTimeImmutable('2011-09-11'), ['date_immutable'], '2011-09-11', true],
118119
[fopen(__FILE__, 'r'), [], '/* Resource(stream) */', false, false],
119120
[
120121
new \stdClass(),

src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testWithValueBound(callable $executeMethod)
126126
$stmt->bindValue(3, 5, ParameterType::INTEGER);
127127
$stmt->bindValue(4, $res = $this->getResourceFromString('mydata'), ParameterType::BINARY);
128128
$stmt->bindValue(5, ['foo', 'bar'], Types::SIMPLE_ARRAY);
129-
$stmt->bindValue(6, new \DateTime('2022-06-12 11:00:00'), Types::DATETIME_MUTABLE);
129+
$stmt->bindValue(6, new \DateTimeImmutable('2022-06-12 11:00:00'), Types::DATETIME_IMMUTABLE);
130130

131131
$executeMethod($stmt);
132132

src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testVerifyOutdatedTokenAfterParallelRequest()
7777
$provider->createNewToken($token);
7878

7979
// new request comes in requiring remember-me auth, which updates the token
80-
$provider->updateExistingToken($token, $newValue, new \DateTime('-5 seconds'));
80+
$provider->updateExistingToken($token, $newValue, new \DateTimeImmutable('-5 seconds'));
8181
$provider->updateToken($series, $newValue, new \DateTime('-5 seconds'));
8282

8383
// parallel request comes in with the old remember-me cookie and session, which also requires reauth
@@ -102,7 +102,7 @@ public function testVerifyOutdatedTokenAfterParallelRequestFailsAfter60Seconds()
102102
$provider->createNewToken($token);
103103

104104
// new request comes in requiring remember-me auth, which updates the token
105-
$provider->updateExistingToken($token, $newValue, new \DateTime('-61 seconds'));
105+
$provider->updateExistingToken($token, $newValue, new \DateTimeImmutable('-61 seconds'));
106106
$provider->updateToken($series, $newValue, new \DateTime('-5 seconds'));
107107

108108
// parallel request comes in with the old remember-me cookie and session, which also requires reauth

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8080
['Version', \PHP_VERSION],
8181
['Architecture', (\PHP_INT_SIZE * 8).' bits'],
8282
['Intl locale', class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a'],
83-
['Timezone', date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'],
83+
['Timezone', date_default_timezone_get().' (<comment>'.(new \DateTimeImmutable())->format(\DateTimeInterface::W3C).'</>)'],
8484
['OPcache', \extension_loaded('Zend OPcache') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) ? 'true' : 'false'],
8585
['APCu', \extension_loaded('apcu') && filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOL) ? 'true' : 'false'],
8686
['Xdebug', \extension_loaded('xdebug') ? 'true' : 'false'],

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
%}
376376
<tr class="log-status-{{ css_class }}" data-type="{{ log.type }}" data-priority="{{ log.priority }}" data-channel="{{ log.channel }}" style="{{ 'event' == log.channel or 'DEBUG' == log.priorityName ? 'display: none' }}">
377377
<td class="log-timestamp">
378-
<time class="newline" title="{{ log.timestamp|date('r') }}" datetime="{{ log.timestamp|date(constant('\DateTime::RFC3339_EXTENDED')) }}" data-convert-to-user-timezone data-render-as-time data-render-with-millisecond-precision>
378+
<time class="newline" title="{{ log.timestamp|date('r') }}" datetime="{{ log.timestamp|date(constant('DateTimeInterface::RFC3339_EXTENDED')) }}" data-convert-to-user-timezone data-render-as-time data-render-with-millisecond-precision>
379379
{{ log.timestamp|date('H:i:s.v') }}
380380
</time>
381381

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ public function transform(mixed $dateTime): array
6767
}
6868

6969
if ($this->inputTimezone !== $this->outputTimezone) {
70-
if (!$dateTime instanceof \DateTimeImmutable) {
71-
$dateTime = clone $dateTime;
72-
}
73-
70+
$dateTime = \DateTimeImmutable::createFromInterface($dateTime);
7471
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
7572
}
7673

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ public function transform(mixed $dateTime): string
5353
}
5454

5555
if ($this->inputTimezone !== $this->outputTimezone) {
56-
if (!$dateTime instanceof \DateTimeImmutable) {
57-
$dateTime = clone $dateTime;
58-
}
59-
56+
$dateTime = \DateTimeImmutable::createFromInterface($dateTime);
6057
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
6158
}
6259

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public function transform(mixed $dateTime): string
3838
}
3939

4040
if ($this->inputTimezone !== $this->outputTimezone) {
41-
if (!$dateTime instanceof \DateTimeImmutable) {
42-
$dateTime = clone $dateTime;
43-
}
44-
41+
$dateTime = \DateTimeImmutable::createFromInterface($dateTime);
4542
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
4643
}
4744

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@ public function transform(mixed $dateTime): string
8585
throw new TransformationFailedException('Expected a \DateTimeInterface.');
8686
}
8787

88-
if (!$dateTime instanceof \DateTimeImmutable) {
89-
$dateTime = clone $dateTime;
90-
}
91-
88+
$dateTime = \DateTimeImmutable::createFromInterface($dateTime);
9289
$dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
9390

9491
return $dateTime->format($this->generateFormat);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy