Skip to content

Commit ebbd631

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

File tree

6 files changed

+65
-43
lines changed

6 files changed

+65
-43
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 renamed to src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,27 @@
66
use PHPStan\Type\ObjectType;
77
use PHPStan\Type\StringType;
88
use PHPStan\Type\Type;
9-
use Symfony\Component\Clock\DatePoint;
109

11-
class DatePointType implements DoctrineTypeDescriptor
10+
class DatePointTypeDescriptor implements DoctrineTypeDescriptor
1211
{
1312

13+
private const DATE_POINT_TYPE_CLASS = 'Symfony\Bridge\Doctrine\Types\DatePointType';
14+
private const DATE_POINT_CLASS = 'Symfony\Component\Clock\DatePoint';
15+
1416
public function getType(): string
1517
{
16-
return \Symfony\Bridge\Doctrine\Types\DatePointType::class;
18+
/** @var class-string<\Doctrine\DBAL\Types\Type> */
19+
return self::DATE_POINT_TYPE_CLASS;
1720
}
1821

1922
public function getWritableToPropertyType(): Type
2023
{
21-
return new ObjectType(DatePoint::class);
24+
return new ObjectType(self::DATE_POINT_CLASS);
2225
}
2326

2427
public function getWritableToDatabaseType(): Type
2528
{
26-
return new ObjectType(DatePoint::class);
29+
return new ObjectType(self::DATE_POINT_CLASS);
2730
}
2831

2932
public function getDatabaseInternalType(): Type

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
use PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor;
2525
use PHPStan\Type\Doctrine\Descriptors\SimpleArrayType;
2626
use PHPStan\Type\Doctrine\Descriptors\StringType;
27-
use PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointType;
27+
use PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointTypeDescriptor;
2828
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
29-
use Symfony\Component\Clock\DatePoint;
3029
use function array_unshift;
30+
use function class_exists;
3131
use function strpos;
3232
use const PHP_VERSION_ID;
3333

@@ -61,7 +61,7 @@ protected function getRule(): Rule
6161
if (!Type::hasType('array')) {
6262
Type::addType('array', \Doctrine\DBAL\Types\ArrayType::class);
6363
}
64-
if (!Type::hasType('date_point')) {
64+
if (!Type::hasType('date_point') && class_exists(\Symfony\Bridge\Doctrine\Types\DatePointType::class)) {
6565
Type::addType('date_point', \Symfony\Bridge\Doctrine\Types\DatePointType::class);
6666
}
6767

@@ -84,7 +84,7 @@ protected function getRule(): Rule
8484
new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()),
8585
new ReflectionDescriptor(CustomType::class, $this->createReflectionProvider(), self::getContainer()),
8686
new ReflectionDescriptor(CustomNumericType::class, $this->createReflectionProvider(), self::getContainer()),
87-
new DatePointType(),
87+
new DatePointTypeDescriptor(),
8888
]),
8989
$this->createReflectionProvider(),
9090
true,
@@ -172,14 +172,6 @@ public function testRule(?string $objectManagerLoader): void
172172
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
173173
162,
174174
],
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-
],
183175
];
184176

185177
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');
@@ -194,6 +186,33 @@ public function testRule(?string $objectManagerLoader): void
194186
$this->analyse([__DIR__ . '/data/MyBrokenEntity.php'], $errors);
195187
}
196188

189+
190+
/**
191+
* @dataProvider dataObjectManagerLoader
192+
*/
193+
public function testRuleSymfony(?string $objectManagerLoader): void
194+
{
195+
if (!InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
196+
self::markTestSkipped('symfony/doctrine-bridge');
197+
}
198+
199+
$this->allowNullablePropertyForRequiredField = false;
200+
$this->objectManagerLoader = $objectManagerLoader;
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)