Skip to content

Commit 45d53e4

Browse files
committed
Modernize documentation code
- migrate to attributes; - add helpful phpdoc annotations; - use typed properties; - add type declarations.
1 parent f08b67f commit 45d53e4

22 files changed

+700
-836
lines changed

docs/en/cookbook/working-with-datetime.rst

+16-13
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ these comparisons are always made **BY REFERENCE**. That means the following cha
1515
.. code-block:: php
1616
1717
<?php
18-
/** @Entity */
18+
19+
use DateTime;
20+
21+
#[Entity]
1922
class Article
2023
{
21-
/** @Column(type="datetime") */
22-
private $updated;
24+
#[Column(type='datetime')]
25+
private DateTime $updated;
2326
24-
public function setUpdated()
27+
public function setUpdated(): void
2528
{
2629
// will NOT be saved in the database
2730
$this->updated->modify("now");
@@ -33,12 +36,14 @@ The way to go would be:
3336
.. code-block:: php
3437
3538
<?php
39+
use DateTime;
40+
3641
class Article
3742
{
38-
public function setUpdated()
43+
public function setUpdated(): DateTime
3944
{
4045
// WILL be saved in the database
41-
$this->updated = new \DateTime("now");
46+
$this->updated = new DateTime("now");
4247
}
4348
}
4449
@@ -84,16 +89,14 @@ the UTC time at the time of the booking and the timezone the event happened in.
8489
8590
namespace DoctrineExtensions\DBAL\Types;
8691
92+
use DateTimeZone;
8793
use Doctrine\DBAL\Platforms\AbstractPlatform;
8894
use Doctrine\DBAL\Types\ConversionException;
8995
use Doctrine\DBAL\Types\DateTimeType;
9096
9197
class UTCDateTimeType extends DateTimeType
9298
{
93-
/**
94-
* @var \DateTimeZone
95-
*/
96-
private static $utc;
99+
private static DateTimeZone $utc;
97100
98101
public function convertToDatabaseValue($value, AbstractPlatform $platform)
99102
{
@@ -126,10 +129,10 @@ the UTC time at the time of the booking and the timezone the event happened in.
126129
127130
return $converted;
128131
}
129-
130-
private static function getUtc(): \DateTimeZone
132+
133+
private static function getUtc(): DateTimeZone
131134
{
132-
return self::$utc ?: self::$utc = new \DateTimeZone('UTC');
135+
return self::$utc ?: self::$utc = new DateTimeZone('UTC');
133136
}
134137
}
135138

0 commit comments

Comments
 (0)