Skip to content

Commit c657b6b

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

File tree

11 files changed

+105
-42
lines changed

11 files changed

+105
-42
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ jobs:
164164
include:
165165
- php-version: "8.3"
166166
update-packages: "composer require --dev doctrine/orm:^3.0 doctrine/dbal:^4.0 carbonphp/carbon-doctrine-types:^3 gedmo/doctrine-extensions:^3 -W"
167+
- php-version: "8.4"
168+
update-packages: "composer require --dev 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 -W"
167169

168170
steps:
169171
- name: "Checkout"

.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"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types=1);
2+
3+
use Composer\InstalledVersions;
4+
5+
$includes = [];
6+
7+
if (!InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
8+
$includes[] = __DIR__ . '/../phpstan-baseline-without-symfony-bridge.neon';
9+
}
10+
11+
$config = [];
12+
$config['includes'] = $includes;
13+
14+
return $config;

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,

extension.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ services:
413413
arguments:
414414
uuidTypeName: Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeType
415415
-
416-
class: PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointType
416+
class: PHPStan\Type\Doctrine\Descriptors\Symfony\DatePointTypeDescriptor
417417
tags: [phpstan.doctrine.typeDescriptor]
418418

419419
# Doctrine Collection
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Class Symfony\\Bridge\\Doctrine\\Types\\DatePointType not found\.$#'
5+
identifier: class.notFound
6+
count: 1
7+
path: src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php
8+
9+
-
10+
message: '#^Class Symfony\\Component\\Clock\\DatePoint not found\.$#'
11+
identifier: class.notFound
12+
count: 2
13+
path: src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php
14+
15+
-
16+
message: '#^Method PHPStan\\Type\\Doctrine\\Descriptors\\Symfony\\DatePointTypeDescriptor\:\:getType\(\) should return class\-string\<Doctrine\\DBAL\\Types\\Type\> but returns string\.$#'
17+
identifier: return.type
18+
count: 1
19+
path: src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php
20+
21+
-
22+
message: '#^Parameter \#2 \$className of static method Doctrine\\DBAL\\Types\\Type\:\:addType\(\) expects class\-string\<Doctrine\\DBAL\\Types\\Type\>, string given\.$#'
23+
identifier: argument.type
24+
count: 1
25+
path: tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ includes:
55
- phpstan-baseline-deprecations.neon
66
- phpstan-baseline-dbal-3.neon
77
- compatibility/orm-3-baseline.php
8+
- compatibility/without-symfony-bridge-baseline.php
89
- vendor/phpstan/phpstan-strict-rules/rules.neon
910
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
1011
- vendor/phpstan/phpstan-phpunit/extension.neon

src/Type/Doctrine/Descriptors/Symfony/DatePointType.php renamed to src/Type/Doctrine/Descriptors/Symfony/DatePointTypeDescriptor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
use PHPStan\Type\ObjectType;
77
use PHPStan\Type\StringType;
88
use PHPStan\Type\Type;
9+
use Symfony\Bridge\Doctrine\Types\DatePointType;
910
use Symfony\Component\Clock\DatePoint;
1011

11-
class DatePointType implements DoctrineTypeDescriptor
12+
class DatePointTypeDescriptor implements DoctrineTypeDescriptor
1213
{
1314

1415
public function getType(): string
1516
{
16-
return \Symfony\Bridge\Doctrine\Types\DatePointType::class;
17+
return DatePointType::class;
1718
}
1819

1920
public function getWritableToPropertyType(): Type

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
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;
29+
use Symfony\Bridge\Doctrine\Types\DatePointType;
3030
use function array_unshift;
31+
use function class_exists;
3132
use function strpos;
3233
use const PHP_VERSION_ID;
3334

@@ -61,8 +62,8 @@ protected function getRule(): Rule
6162
if (!Type::hasType('array')) {
6263
Type::addType('array', \Doctrine\DBAL\Types\ArrayType::class);
6364
}
64-
if (!Type::hasType('date_point')) {
65-
Type::addType('date_point', \Symfony\Bridge\Doctrine\Types\DatePointType::class);
65+
if (!Type::hasType('date_point') && class_exists(DatePointType::class)) {
66+
Type::addType('date_point', DatePointType::class);
6667
}
6768

6869
return new EntityColumnRule(
@@ -84,7 +85,7 @@ protected function getRule(): Rule
8485
new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()),
8586
new ReflectionDescriptor(CustomType::class, $this->createReflectionProvider(), self::getContainer()),
8687
new ReflectionDescriptor(CustomNumericType::class, $this->createReflectionProvider(), self::getContainer()),
87-
new DatePointType(),
88+
new DatePointTypeDescriptor(),
8889
]),
8990
$this->createReflectionProvider(),
9091
true,
@@ -172,14 +173,6 @@ public function testRule(?string $objectManagerLoader): void
172173
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
173174
162,
174175
],
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-
],
183176
];
184177

185178
$dbalVersion = InstalledVersions::getVersion('doctrine/dbal');
@@ -194,6 +187,33 @@ public function testRule(?string $objectManagerLoader): void
194187
$this->analyse([__DIR__ . '/data/MyBrokenEntity.php'], $errors);
195188
}
196189

190+
191+
/**
192+
* @dataProvider dataObjectManagerLoader
193+
*/
194+
public function testRuleSymfony(?string $objectManagerLoader): void
195+
{
196+
if (!InstalledVersions::isInstalled('symfony/doctrine-bridge')) {
197+
self::markTestSkipped('symfony/doctrine-bridge');
198+
}
199+
200+
$this->allowNullablePropertyForRequiredField = false;
201+
$this->objectManagerLoader = $objectManagerLoader;
202+
203+
$errors = [
204+
[
205+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: database can contain Symfony\Component\Clock\DatePoint but property expects DateTime.',
206+
175,
207+
],
208+
[
209+
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidDatePoint type mapping mismatch: property can contain DateTime but database expects Symfony\Component\Clock\DatePoint.',
210+
175,
211+
],
212+
];
213+
214+
$this->analyse([__DIR__ . '/data/MySymfonyBrokenEntity.php'], $errors);
215+
}
216+
197217
/**
198218
* @dataProvider dataObjectManagerLoader
199219
*/
@@ -251,14 +271,6 @@ public function testRuleWithAllowedNullableProperty(?string $objectManagerLoader
251271
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidSimpleArray type mapping mismatch: property can contain array<int> but database expects array<string>.',
252272
162,
253273
],
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-
],
262274
];
263275

264276
$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)