Skip to content

Commit 6bc479d

Browse files
committed
add array check
1 parent 0a038fa commit 6bc479d

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterDatePointTypePass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function process(ContainerBuilder $container): void
3030

3131
$typeDefinition = $container->getParameter('doctrine.dbal.connection_factory.types');
3232

33-
if (!isset($typeDefinition['date_point'])) {
33+
if (is_array($typeDefinition) && !isset($typeDefinition['date_point'])) {
3434
$typeDefinition['date_point'] = ['class' => DatePointType::class];
3535
}
3636

src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/CompilerPass/RegisterDatePointTypePassTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterDatePointTypePass;
1616
use Symfony\Bridge\Doctrine\Types\DatePointType;
17+
use Symfony\Component\Clock\DatePoint;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819

1920
class RegisterDatePointTypePassTest extends TestCase
2021
{
22+
protected function setUp(): void
23+
{
24+
if (!class_exists(DatePoint::class)) {
25+
self::markTestSkipped('The DatePoint class is not available.');
26+
}
27+
}
28+
2129
public function testRegistered()
2230
{
2331
$container = new ContainerBuilder();
@@ -30,12 +38,4 @@ public function testRegistered()
3038
];
3139
$this->assertSame($expected, $container->getParameter('doctrine.dbal.connection_factory.types'));
3240
}
33-
34-
public function testRegisteredDontFail()
35-
{
36-
$container = new ContainerBuilder();
37-
(new RegisterDatePointTypePass())->process($container);
38-
39-
$this->expectNotToPerformAssertions();
40-
}
4141
}

src/Symfony/Bridge/Doctrine/Tests/Types/DatePointTypeTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use DateTimeImmutable;
1515
use Doctrine\DBAL\Platforms\AbstractPlatform;
1616
use Doctrine\DBAL\Platforms\MariaDBPlatform;
17-
use Doctrine\DBAL\Platforms\MySQLPlatform;
1817
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1918
use Doctrine\DBAL\Platforms\SqlitePlatform;
2019
use Doctrine\DBAL\Types\ConversionException;
@@ -39,10 +38,10 @@ public static function setUpBeforeClass(): void
3938

4039
protected function setUp(): void
4140
{
42-
$this->type = Type::getType(DatePointType::NAME);
4341
if (!class_exists(DatePoint::class)) {
4442
self::markTestSkipped('The DatePoint class is not available.');
4543
}
44+
$this->type = Type::getType(DatePointType::NAME);
4645
}
4746

4847
public function testDatePointConvertsToDatabaseValue()
@@ -57,7 +56,6 @@ public function testDatePointConvertsToDatabaseValue()
5756

5857
public function testDatePointConvertsToPHPValue()
5958
{
60-
6159
$datePoint = new DatePoint();
6260
$actual = $this->type->convertToPHPValue($datePoint, new SqlitePlatform());
6361

src/Symfony/Bridge/Doctrine/Types/DatePointType.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,29 @@
1313

1414
use DateTimeInterface;
1515
use Doctrine\DBAL\Platforms\AbstractPlatform;
16-
use Doctrine\DBAL\Types\ConversionException;
1716
use Doctrine\DBAL\Types\DateTimeImmutableType;
1817
use Symfony\Component\Clock\DatePoint;
1918

2019
final class DatePointType extends DateTimeImmutableType
2120
{
2221
public const NAME = 'date_point';
2322

23+
/**
24+
* @param T $value
25+
*
26+
* @return (T is null ? null : DatePoint)
27+
*
28+
* @template T
29+
*/
2430
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DatePoint
2531
{
2632
if (null === $value || $value instanceof DatePoint) {
2733
return $value;
2834
}
2935

3036
$value = parent::convertToPHPValue($value, $platform);
31-
if ($value instanceof DateTimeInterface) {
32-
return DatePoint::createFromInterface($value);
33-
}
3437

35-
throw new ConversionException();
38+
return DatePoint::createFromInterface($value);
3639
}
3740

3841
public function getName(): string

0 commit comments

Comments
 (0)