Skip to content

Commit 067fa82

Browse files
Fix for support on different Doctrine ORM versions (#414)
* Add conflict to doctrine/persistence below 1.4 and use correct persistence classes * Resolve more issue with static analysis in doctrine implementations. Add doctrine/orm as dev dependency to avoid baseline entries. * Fix phpstan-baseline for php7.4 * Add backwards compatible class_alias for doctrine/persistence * Update psalm baseline
1 parent fbc273b commit 067fa82

File tree

9 files changed

+53
-198
lines changed

9 files changed

+53
-198
lines changed

Diff for: CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# CHANGELOG
22

33
## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.18.0..main)
4+
- Fixed usage of `Doctrine\Persistence` dependency
5+
- Added conflict with `doctrine/persistence` below version `1.4`
46

57
## [2022-01-23, v1.18.0](https://github.com/FakerPHP/Faker/compare/v1.17.0..v1.18.0)
68

@@ -13,7 +15,7 @@
1315
- Person->name was missing string return type (#424)
1416
- Generate a valid BE TAX number (#415)
1517
- Added the UUID extension to Core (#427)
16-
-
18+
1719
## [2021-12-05, v1.17.0](https://github.com/FakerPHP/Faker/compare/v1.16.0..v1.17.0)
1820

1921
- Partial PHP 8.1 compatibility (#373)

Diff for: composer.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
"require-dev": {
2222
"ext-intl": "*",
2323
"bamarni/composer-bin-plugin": "^1.4.1",
24+
"doctrine/persistence": "^1.3 || ^2.0",
2425
"symfony/phpunit-bridge": "^4.4 || ^5.2"
2526
},
2627
"autoload": {
2728
"psr-4": {
2829
"Faker\\": "src/Faker/"
29-
}
30+
},
31+
"files": [
32+
"src/Faker/ORM/Doctrine/backward-compatibility.php"
33+
]
3034
},
3135
"autoload-dev": {
3236
"psr-4": {
@@ -41,11 +45,13 @@
4145
"ext-curl": "Required by Faker\\Provider\\Image to download images.",
4246
"ext-dom": "Required by Faker\\Provider\\HtmlLorem for generating random HTML.",
4347
"ext-iconv": "Required by Faker\\Provider\\ru_RU\\Text::realText() for generating real Russian text.",
44-
"ext-mbstring": "Required for multibyte Unicode string functionality."
48+
"ext-mbstring": "Required for multibyte Unicode string functionality.",
49+
"doctrine/orm": "Required to use Faker\\ORM\\Doctrine"
4550
},
4651
"config": {
4752
"allow-plugins": {
48-
"bamarni/composer-bin-plugin": true
53+
"bamarni/composer-bin-plugin": true,
54+
"composer/package-versions-deprecated": true
4955
},
5056
"sort-packages": true
5157
},

Diff for: phpstan-baseline.neon

+8-138
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ parameters:
6666
path: src/Faker/ORM/CakePHP/Populator.php
6767

6868
-
69-
message: "#^Access to property \\$fieldMappings on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
69+
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$fieldMappings\\.$#"
7070
count: 2
7171
path: src/Faker/ORM/Doctrine/ColumnTypeGuesser.php
7272

7373
-
74-
message: "#^Call to method getTypeOfField\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
74+
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$fieldMappings\\.$#"
7575
count: 1
76-
path: src/Faker/ORM/Doctrine/ColumnTypeGuesser.php
76+
path: src/Faker/ORM/Doctrine/EntityPopulator.php
7777

7878
-
79-
message: "#^Parameter \\$class of method Faker\\\\ORM\\\\Doctrine\\\\ColumnTypeGuesser\\:\\:guessFormat\\(\\) has invalid typehint type Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
80-
count: 1
81-
path: src/Faker/ORM/Doctrine/ColumnTypeGuesser.php
79+
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$reflFields\\.$#"
80+
count: 2
81+
path: src/Faker/ORM/Doctrine/EntityPopulator.php
8282

8383
-
8484
message: "#^Access to constant ONE on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\.$#"
@@ -95,33 +95,18 @@ parameters:
9595
count: 1
9696
path: src/Faker/ORM/Doctrine/EntityPopulator.php
9797

98-
-
99-
message: "#^Access to property \\$associationMappings on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
100-
count: 1
101-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
102-
10398
-
10499
message: "#^Access to property \\$associationMappings on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\.$#"
105100
count: 1
106101
path: src/Faker/ORM/Doctrine/EntityPopulator.php
107102

108103
-
109-
message: "#^Access to property \\$fieldMappings on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
110-
count: 1
111-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
112-
113-
-
114-
message: "#^Access to property \\$reflFields on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
115-
count: 2
116-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
117-
118-
-
119-
message: "#^Call to method createQueryBuilder\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectRepository\\.$#"
104+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:newInstance\\(\\)\\.$#"
120105
count: 1
121106
path: src/Faker/ORM/Doctrine/EntityPopulator.php
122107

123108
-
124-
message: "#^Call to method getAssociationMappings\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
109+
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectRepository\\<object\\>\\:\\:createQueryBuilder\\(\\)\\.$#"
125110
count: 1
126111
path: src/Faker/ORM/Doctrine/EntityPopulator.php
127112

@@ -130,61 +115,6 @@ parameters:
130115
count: 1
131116
path: src/Faker/ORM/Doctrine/EntityPopulator.php
132117

133-
-
134-
message: "#^Call to method getAssociationNames\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
135-
count: 1
136-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
137-
138-
-
139-
message: "#^Call to method getAssociationTargetClass\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
140-
count: 1
141-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
142-
143-
-
144-
message: "#^Call to method getFieldNames\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
145-
count: 1
146-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
147-
148-
-
149-
message: "#^Call to method getIdentifier\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
150-
count: 1
151-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
152-
153-
-
154-
message: "#^Call to method getName\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
155-
count: 1
156-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
157-
158-
-
159-
message: "#^Call to method getRepository\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
160-
count: 1
161-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
162-
163-
-
164-
message: "#^Call to method hasField\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
165-
count: 1
166-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
167-
168-
-
169-
message: "#^Call to method isCollectionValuedAssociation\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
170-
count: 1
171-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
172-
173-
-
174-
message: "#^Call to method isIdentifier\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
175-
count: 1
176-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
177-
178-
-
179-
message: "#^Call to method newInstance\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
180-
count: 1
181-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
182-
183-
-
184-
message: "#^Call to method persist\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
185-
count: 1
186-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
187-
188118
-
189119
message: "#^Class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata not found\\.$#"
190120
count: 1
@@ -195,66 +125,6 @@ parameters:
195125
count: 1
196126
path: src/Faker/ORM/Doctrine/EntityPopulator.php
197127

198-
-
199-
message: "#^Method Faker\\\\ORM\\\\Doctrine\\\\EntityPopulator\\:\\:generateId\\(\\) never returns null so it can be removed from the return typehint\\.$#"
200-
count: 1
201-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
202-
203-
-
204-
message: "#^PHPDoc tag @var for variable \\$repository contains unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectRepository\\.$#"
205-
count: 1
206-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
207-
208-
-
209-
message: "#^Parameter \\$class of method Faker\\\\ORM\\\\Doctrine\\\\EntityPopulator\\:\\:__construct\\(\\) has invalid typehint type Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata\\.$#"
210-
count: 1
211-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
212-
213-
-
214-
message: "#^Parameter \\$manager of method Faker\\\\ORM\\\\Doctrine\\\\EntityPopulator\\:\\:execute\\(\\) has invalid typehint type Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
215-
count: 1
216-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
217-
218-
-
219-
message: "#^Parameter \\$manager of method Faker\\\\ORM\\\\Doctrine\\\\EntityPopulator\\:\\:generateId\\(\\) has invalid typehint type Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
220-
count: 1
221-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
222-
223-
-
224-
message: "#^Property Faker\\\\ORM\\\\Doctrine\\\\EntityPopulator\\:\\:\\$class has unknown class Doctrine\\\\Common\\\\Persistence\\\\Mapping\\\\ClassMetadata as its type\\.$#"
225-
count: 1
226-
path: src/Faker/ORM/Doctrine/EntityPopulator.php
227-
228-
-
229-
message: "#^Call to method flush\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
230-
count: 2
231-
path: src/Faker/ORM/Doctrine/Populator.php
232-
233-
-
234-
message: "#^Call to method flush\\(\\) on an unknown class Faker\\\\ORM\\\\Doctrine\\\\EntityManager\\.$#"
235-
count: 2
236-
path: src/Faker/ORM/Doctrine/Populator.php
237-
238-
-
239-
message: "#^Call to method getClassMetadata\\(\\) on an unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
240-
count: 1
241-
path: src/Faker/ORM/Doctrine/Populator.php
242-
243-
-
244-
message: "#^Parameter \\$entityManager of method Faker\\\\ORM\\\\Doctrine\\\\Populator\\:\\:execute\\(\\) has invalid typehint type Faker\\\\ORM\\\\Doctrine\\\\EntityManager\\.$#"
245-
count: 1
246-
path: src/Faker/ORM/Doctrine/Populator.php
247-
248-
-
249-
message: "#^Parameter \\$manager of method Faker\\\\ORM\\\\Doctrine\\\\Populator\\:\\:__construct\\(\\) has invalid typehint type Doctrine\\\\Common\\\\Persistence\\\\ObjectManager\\.$#"
250-
count: 1
251-
path: src/Faker/ORM/Doctrine/Populator.php
252-
253-
-
254-
message: "#^Property Faker\\\\ORM\\\\Doctrine\\\\Populator\\:\\:\\$manager has unknown class Doctrine\\\\Common\\\\Persistence\\\\ObjectManager as its type\\.$#"
255-
count: 1
256-
path: src/Faker/ORM/Doctrine/Populator.php
257-
258128
-
259129
message: "#^Call to method create\\(\\) on an unknown class Mandango\\\\Mandango\\.$#"
260130
count: 1

Diff for: psalm.baseline.xml

+12-49
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,26 @@
1919
<code>self</code>
2020
<code>self</code>
2121
</InvalidReturnType>
22-
</file>
22+
</file>
2323
<file src="src/Faker/ORM/CakePHP/EntityPopulator.php">
2424
<UndefinedClass occurrences="1">
2525
<code>TableRegistry</code>
2626
</UndefinedClass>
2727
</file>
28-
<file src="src/Faker/ORM/Doctrine/ColumnTypeGuesser.php">
29-
<UndefinedClass occurrences="1">
30-
<code>ClassMetadata</code>
31-
</UndefinedClass>
32-
</file>
3328
<file src="src/Faker/ORM/Doctrine/EntityPopulator.php">
34-
<UndefinedClass occurrences="13">
35-
<code>$this-&gt;class</code>
36-
<code>$this-&gt;class</code>
29+
<UndefinedClass occurrences="6">
3730
<code>$this-&gt;class</code>
38-
<code>$this-&gt;class-&gt;associationMappings</code>
39-
<code>$this-&gt;class-&gt;fieldMappings</code>
40-
<code>ClassMetadata</code>
41-
<code>ObjectManager</code>
42-
<code>ObjectManager</code>
4331
<code>\Doctrine\ODM\MongoDB\Mapping\ClassMetadata</code>
4432
<code>\Doctrine\ODM\MongoDB\Mapping\ClassMetadata</code>
4533
<code>\Doctrine\ODM\MongoDB\Mapping\ClassMetadata</code>
4634
<code>\Doctrine\ORM\Mapping\ClassMetadata</code>
4735
<code>\Doctrine\ORM\Mapping\ClassMetadata</code>
4836
</UndefinedClass>
49-
<UndefinedDocblockClass occurrences="7">
50-
<code>$this-&gt;class</code>
51-
<code>$this-&gt;class</code>
52-
<code>$this-&gt;class</code>
53-
<code>$this-&gt;class</code>
54-
<code>$this-&gt;class</code>
55-
<code>$this-&gt;class-&gt;reflFields</code>
56-
<code>ClassMetadata</code>
57-
</UndefinedDocblockClass>
58-
</file>
59-
<file src="src/Faker/ORM/Doctrine/Populator.php">
60-
<UndefinedClass occurrences="1"/>
61-
<UndefinedDocblockClass occurrences="3">
62-
<code>$this-&gt;manager</code>
63-
<code>ObjectManager|null</code>
64-
</UndefinedDocblockClass>
37+
<UndefinedInterfaceMethod occurrences="3">
38+
<code>createQueryBuilder</code>
39+
<code>getAssociationMappings</code>
40+
<code>newInstance</code>
41+
</UndefinedInterfaceMethod>
6542
</file>
6643
<file src="src/Faker/ORM/Mandango/EntityPopulator.php">
6744
<UndefinedClass occurrences="2">
@@ -76,7 +53,9 @@
7653
</UndefinedClass>
7754
</file>
7855
<file src="src/Faker/ORM/Propel/ColumnTypeGuesser.php">
79-
<UndefinedClass occurrences="1"/>
56+
<UndefinedClass occurrences="1">
57+
<code>\ColumnMap</code>
58+
</UndefinedClass>
8059
</file>
8160
<file src="src/Faker/ORM/Propel/EntityPopulator.php">
8261
<UndefinedClass occurrences="9">
@@ -88,6 +67,7 @@
8867
<code>$columnMap</code>
8968
<code>$columnMap</code>
9069
<code>$columnMap</code>
70+
<code>\ColumnMap</code>
9171
</UndefinedClass>
9272
</file>
9373
<file src="src/Faker/ORM/Propel/Populator.php">
@@ -152,6 +132,7 @@
152132
<file src="src/Faker/ORM/Spot/Populator.php">
153133
<UndefinedClass occurrences="2">
154134
<code>$this-&gt;locator</code>
135+
<code>Locator</code>
155136
</UndefinedClass>
156137
<UndefinedDocblockClass occurrences="1">
157138
<code>Locator</code>
@@ -191,34 +172,16 @@
191172
<code>$checksumArr[$checksum % 11]</code>
192173
</InvalidArrayOffset>
193174
</file>
194-
<file src="src/Faker/Provider/is_IS/Address.php">
195-
<InvalidPropertyAssignmentValue occurrences="1"/>
196-
<UndefinedDocblockClass occurrences="2">
197-
<code>Icelandic</code>
198-
</UndefinedDocblockClass>
199-
</file>
200175
<file src="src/Faker/Provider/is_IS/Person.php">
201-
<InvalidArgument occurrences="1">
202-
<code>static::$middleName</code>
203-
</InvalidArgument>
204176
<InvalidArrayOffset occurrences="1">
205177
<code>$ref[$i]</code>
206178
</InvalidArrayOffset>
207-
<InvalidPropertyAssignmentValue occurrences="3"/>
208179
</file>
209180
<file src="src/Faker/Provider/ja_JP/Text.php">
210181
<UndefinedMethod occurrences="1">
211182
<code>static::split($text)</code>
212183
</UndefinedMethod>
213184
</file>
214-
<file src="src/Faker/Provider/pl_PL/Company.php">
215-
<InvalidReturnStatement occurrences="1">
216-
<code>implode('', $result)</code>
217-
</InvalidReturnStatement>
218-
<InvalidReturnType occurrences="1">
219-
<code>14</code>
220-
</InvalidReturnType>
221-
</file>
222185
<file src="src/Faker/Provider/pl_PL/Person.php">
223186
<UndefinedDocblockClass occurrences="1">
224187
<code>DateTime</code>

Diff for: src/Faker/ORM/Doctrine/EntityPopulator.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,17 @@ private function callMethods($obj, $insertedEntities)
226226
}
227227

228228
/**
229-
* @return int|null
229+
* @return int
230230
*/
231231
private function generateId($obj, $column, ObjectManager $manager)
232232
{
233-
/** @var \Doctrine\Common\Persistence\ObjectRepository $repository */
234233
$repository = $manager->getRepository(get_class($obj));
235234
$result = $repository->createQueryBuilder('e')
236235
->select(sprintf('e.%s', $column))
237236
->getQuery()
238237
->execute();
239238
$ids = array_map('current', $result->toArray());
240239

241-
$id = null;
242-
243240
do {
244241
$id = mt_rand();
245242
} while (in_array($id, $ids, false));

Diff for: src/Faker/ORM/Doctrine/Populator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function addEntity($entity, $number, $customColumnFormatters = [], $custo
8686
* Please note that large amounts of data will result in more memory usage since the the Populator will return
8787
* all newly created primary keys after executing.
8888
*
89-
* @param EntityManager|null $entityManager A Doctrine connection object
89+
* @param ObjectManager|null $entityManager A Doctrine connection object
9090
*
9191
* @return array A list of the inserted PKs
9292
*/

0 commit comments

Comments
 (0)