Skip to content

Commit 407a7fe

Browse files
author
LDA
committed
Try to fix build
1 parent 622eea1 commit 407a7fe

File tree

6 files changed

+62
-39
lines changed

6 files changed

+62
-39
lines changed

.github/workflows/platform-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- php-version: "8.3"
3838
update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3
3939
- php-version: "8.4"
40-
update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3
40+
update-packages: doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 symfony/cache:^6.4 symfony/clock:^6.4 symfony/doctrine-bridge:^7.3 symfony/validator:^6.4
4141

4242
steps:
4343
- name: "Checkout"

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
"phpstan/phpstan-strict-rules": "^2.0",
3737
"phpunit/phpunit": "^9.6.20",
3838
"ramsey/uuid": "^4.2",
39-
"symfony/cache": "^6.4",
40-
"symfony/clock": "^6.4",
41-
"symfony/doctrine-bridge": "^7.3",
42-
"symfony/validator": "^6.4"
39+
"symfony/cache": "^5.4"
4340
},
4441
"config": {
4542
"sort-packages": true,

src/Type/Doctrine/Descriptors/Symfony/DatePointType.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@
1111
class DatePointType implements DoctrineTypeDescriptor
1212
{
1313

14+
private const DATE_POINT_TYPE_CLASS = 'Symfony\Bridge\Doctrine\Types\DatePointType';
15+
private const DATE_POINT_CLASS = 'Symfony\Component\Clock\DatePoint';
16+
1417
public function getType(): string
1518
{
16-
return \Symfony\Bridge\Doctrine\Types\DatePointType::class;
19+
/** @var class-string<\Doctrine\DBAL\Types\Type> */
20+
return self::DATE_POINT_TYPE_CLASS;
1721
}
1822

1923
public function getWritableToPropertyType(): Type
2024
{
21-
return new ObjectType(DatePoint::class);
25+
return new ObjectType(self::DATE_POINT_CLASS);
2226
}
2327

2428
public function getWritableToDatabaseType(): Type
2529
{
26-
return new ObjectType(DatePoint::class);
30+
return new ObjectType(self::DATE_POINT_CLASS);
2731
}
2832

2933
public function getDatabaseInternalType(): Type

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use PHPStan\Type\Doctrine\Descriptors\StringType;
2727
use PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointType;
2828
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
29-
use Symfony\Component\Clock\DatePoint;
3029
use function array_unshift;
3130
use function strpos;
3231
use const PHP_VERSION_ID;
@@ -61,7 +60,7 @@ protected function getRule(): Rule
6160
if (!Type::hasType('array')) {
6261
Type::addType('array', \Doctrine\DBAL\Types\ArrayType::class);
6362
}
64-
if (!Type::hasType('date_point')) {
63+
if (!Type::hasType('date_point') && class_exists(\Symfony\Bridge\Doctrine\Types\DatePointType::class)) {
6564
Type::addType('date_point', \Symfony\Bridge\Doctrine\Types\DatePointType::class);
6665
}
6766

@@ -172,14 +171,6 @@ public function testRule(?string $objectManagerLoader): void
172171
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
173172
162,
174173
],
175-
[
176-
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.',
177-
175,
178-
],
179-
[
180-
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.',
181-
175,
182-
],
183174
];
184175

185176
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');
@@ -194,6 +185,34 @@ public function testRule(?string $objectManagerLoader): void
194185
$this->analyse([__DIR__ . '/data/MyBrokenEntity.php'], $errors);
195186
}
196187

188+
189+
/**
190+
* @dataProvider dataObjectManagerLoader
191+
*/
192+
public function testRuleSymfony(?string $objectManagerLoader): void
193+
{
194+
if (!InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
195+
$this->markTestSkipped('symfony/doctrine-bridge');
196+
}
197+
198+
$this->allowNullablePropertyForRequiredField = false;
199+
$this->objectManagerLoader = $objectManagerLoader;
200+
201+
202+
$errors = [
203+
[
204+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.',
205+
175,
206+
],
207+
[
208+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.',
209+
175,
210+
]
211+
];
212+
213+
$this->analyse([__DIR__ . '/data/MySymfonyBrokenEntity.php'], $errors);
214+
}
215+
197216
/**
198217
* @dataProvider dataObjectManagerLoader
199218
*/
@@ -251,14 +270,6 @@ public function testRuleWithAllowedNullableProperty(?string $objectManagerLoader
251270
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
252271
162,
253272
],
254-
[
255-
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.',
256-
175,
257-
],
258-
[
259-
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.',
260-
175,
261-
],
262273
];
263274

264275
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');

tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,4 @@ class MyBrokenEntity extends MyBrokenSuperclass
167167
*/
168168
private $validSimpleArray;
169169

170-
171-
/**
172-
* @ORM\Column(type="date_point")
173-
* @var \DateTime
174-
*/
175-
private $invalidDatePoint;
176-
177-
/**
178-
* @ORM\Column(type="date_point")
179-
* @var \Symfony\Component\Clock\DatePoint
180-
*/
181-
private $validDatePoint;
182-
183170
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Doctrine\ORM;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Entity()
9+
*/
10+
class MyBrokenEntity
11+
{
12+
/**
13+
* @ORM\Column(type="date_point")
14+
* @var \DateTime
15+
*/
16+
private $invalidDatePoint;
17+
18+
/**
19+
* @ORM\Column(type="date_point")
20+
* @var \Symfony\Component\Clock\DatePoint
21+
*/
22+
private $validDatePoint;
23+
24+
}

0 commit comments

Comments
 (0)