Skip to content

Commit 9b1f397

Browse files
committed
Merge branch '2.15.x' into 3.0.x
* 2.15.x: Use more precise types for class strings (doctrine#10381) PHPStan 1.9.8, Psalm 5.4.0 (doctrine#10382) fix typo for missing a comma (doctrine#10377) Docs: Removing `type: 'integer'` from mappings (doctrine#10368) Docs: Moving *attributes* mapping to first position (doctrine#10364) Docs: Deleting duplicate mapping example (doctrine#10363)
2 parents 07937b5 + 29b8b0b commit 9b1f397

File tree

5 files changed

+54
-61
lines changed

5 files changed

+54
-61
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
"require-dev": {
3939
"doctrine/coding-standard": "^11.0",
4040
"phpbench/phpbench": "^1.0 || dev-master",
41-
"phpstan/phpstan": "1.9.5",
41+
"phpstan/phpstan": "1.9.8",
4242
"phpunit/phpunit": "^9.5.28@dev",
4343
"psr/log": "^1 || ^2 || ^3",
4444
"squizlabs/php_codesniffer": "3.7.1",
4545
"symfony/cache": "^5.4 || ^6.0",
4646
"symfony/var-exporter": "^5.4 || ^6.2",
47-
"vimeo/psalm": "5.3.0"
47+
"vimeo/psalm": "5.4.0"
4848
},
4949
"suggest": {
5050
"ext-dom": "Provides support for XSD validation for XML mapping files",

docs/en/tutorials/composite-primary-keys.rst

+48-48
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ and year of production as primary keys:
3232
class Car
3333
{
3434
public function __construct(
35-
#[Id, Column(type: 'string')]
35+
#[Id, Column]
3636
private string $name,
37-
#[Id, Column(type: 'integer')]
37+
#[Id, Column]
3838
private int $year,
3939
) {
4040
}
@@ -89,7 +89,7 @@ And for querying you can use arrays to both DQL and EntityRepositories:
8989
9090
$dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.id = ?1";
9191
$audi = $em->createQuery($dql)
92-
->setParameter(1, array("name" => "Audi A8", "year" => 2010))
92+
->setParameter(1, ["name" => "Audi A8", "year" => 2010])
9393
->getSingleResult();
9494
9595
You can also use this entity in associations. Doctrine will then generate two foreign keys one for ``name``
@@ -126,95 +126,95 @@ We keep up the example of an Article with arbitrary attributes, the mapping look
126126

127127
.. configuration-block::
128128

129-
.. code-block:: php
129+
.. code-block:: attribute
130130
131131
<?php
132132
namespace Application\Model;
133133
134134
use Doctrine\Common\Collections\ArrayCollection;
135135
136-
/**
137-
* @Entity
138-
*/
136+
#[Entity]
139137
class Article
140138
{
141-
/** @Id @Column(type="integer") @GeneratedValue */
139+
#[Id, Column, GeneratedValue]
142140
private int|null $id = null;
143-
/** @Column(type="string") */
141+
#[Column]
144142
private string $title;
145143
146-
/**
147-
* @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
148-
* @var Collection<int, ArticleAttribute>
149-
*/
144+
/** @var ArrayCollection<string, ArticleAttribute> */
145+
#[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
150146
private Collection $attributes;
151147
152-
public function addAttribute($name, $value): void
148+
public function addAttribute(string $name, ArticleAttribute $value): void
153149
{
154150
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
155151
}
156152
}
157153
158-
/**
159-
* @Entity
160-
*/
154+
#[Entity]
161155
class ArticleAttribute
162156
{
163-
/** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */
164-
private Article|null $article;
157+
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
158+
private Article $article;
165159
166-
/** @Id @Column(type="string") */
160+
#[Id, Column]
167161
private string $attribute;
168162
169-
/** @Column(type="string") */
163+
#[Column]
170164
private string $value;
171165
172-
public function __construct($name, $value, $article)
166+
public function __construct(string $name, string $value, Article $article)
173167
{
174168
$this->attribute = $name;
175169
$this->value = $value;
176170
$this->article = $article;
177171
}
178172
}
179173
180-
.. code-block:: attribute
174+
.. code-block:: annotation
181175
182176
<?php
183177
namespace Application\Model;
184178
185179
use Doctrine\Common\Collections\ArrayCollection;
186180
187-
#[Entity]
181+
/**
182+
* @Entity
183+
*/
188184
class Article
189185
{
190-
#[Id, Column(type: 'integer'), GeneratedValue]
186+
/** @Id @Column(type="integer") @GeneratedValue */
191187
private int|null $id = null;
192-
#[Column(type: 'string')]
188+
/** @Column(type="string") */
193189
private string $title;
194190
195-
/** @var ArrayCollection<string, ArticleAttribute> */
196-
#[OneToMany(targetEntity: ArticleAttribute::class, mappedBy: 'article', cascade: ['ALL'], indexBy: 'attribute')]
191+
/**
192+
* @OneToMany(targetEntity="ArticleAttribute", mappedBy="article", cascade={"ALL"}, indexBy="attribute")
193+
* @var Collection<int, ArticleAttribute>
194+
*/
197195
private Collection $attributes;
198196
199-
public function addAttribute(string $name, ArticleAttribute $value): void
197+
public function addAttribute($name, $value): void
200198
{
201199
$this->attributes[$name] = new ArticleAttribute($name, $value, $this);
202200
}
203201
}
204202
205-
#[Entity]
203+
/**
204+
* @Entity
205+
*/
206206
class ArticleAttribute
207207
{
208-
#[Id, ManyToOne(targetEntity: Article::class, inversedBy: 'attributes')]
209-
private Article $article;
208+
/** @Id @ManyToOne(targetEntity="Article", inversedBy="attributes") */
209+
private Article|null $article;
210210
211-
#[Id, Column(type: 'string')]
211+
/** @Id @Column(type="string") */
212212
private string $attribute;
213213
214-
#[Column(type: 'string')]
214+
/** @Column(type="string") */
215215
private string $value;
216216
217-
public function __construct(string $name, string $value, Article $article)
217+
public function __construct($name, $value, $article)
218218
{
219219
$this->attribute = $name;
220220
$this->value = $value;
@@ -256,7 +256,7 @@ One good example for this is a user-address relationship:
256256
#[Entity]
257257
class User
258258
{
259-
#[Id, Column(type: 'integer'), GeneratedValue]
259+
#[Id, Column, GeneratedValue]
260260
private int|null $id = null;
261261
}
262262
@@ -284,18 +284,18 @@ of products purchased and maybe even the current price.
284284
#[Entity]
285285
class Order
286286
{
287-
#[Id, Column(type: 'integer'), GeneratedValue]
287+
#[Id, Column, GeneratedValue]
288288
private int|null $id = null;
289289
290290
/** @var ArrayCollection<int, OrderItem> */
291291
#[OneToMany(targetEntity: OrderItem::class, mappedBy: 'order')]
292292
private Collection $items;
293293
294-
#[Column(type: 'boolean')]
294+
#[Column]
295295
private bool $paid = false;
296-
#[Column(type: 'boolean')]
296+
#[Column]
297297
private bool $shipped = false;
298-
#[Column(type: 'datetime')]
298+
#[Column]
299299
private DateTime $created;
300300
301301
public function __construct(
@@ -310,16 +310,16 @@ of products purchased and maybe even the current price.
310310
#[Entity]
311311
class Product
312312
{
313-
#[Id, Column(type: 'integer'), GeneratedValue]
313+
#[Id, Column, GeneratedValue]
314314
private int|null $id = null;
315315
316-
#[Column(type: 'string')]
316+
#[Column]
317317
private string $name;
318318
319-
#[Column(type: 'decimal')]
320-
private float $currentPrice;
319+
#[Column]
320+
private int $currentPrice;
321321
322-
public function getCurrentPrice(): float
322+
public function getCurrentPrice(): int
323323
{
324324
return $this->currentPrice;
325325
}
@@ -334,11 +334,11 @@ of products purchased and maybe even the current price.
334334
#[Id, ManyToOne(targetEntity: Product::class)]
335335
private Product|null $product = null;
336336
337-
#[Column(type: 'integer')]
337+
#[Column]
338338
private int $amount = 1;
339339
340-
#[Column(type: 'decimal')]
341-
private float $offeredPrice;
340+
#[Column]
341+
private int $offeredPrice;
342342
343343
public function __construct(Order $order, Product $product, int $amount = 1)
344344
{

lib/Doctrine/ORM/Events.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function __construct()
7373
* has been applied to it.
7474
*
7575
* Note that the postLoad event occurs for an entity before any associations have been
76-
* initialized. Therefore it is not safe to access associations in a postLoad callback
76+
* initialized. Therefore, it is not safe to access associations in a postLoad callback
7777
* or event handler.
7878
*
7979
* This is an entity lifecycle event.

lib/Doctrine/ORM/Mapping/MappingException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class MappingException extends Exception implements ORMException
2828
{
2929
/**
30-
* @param string $entityName
30+
* @param class-string $entityName
3131
*
3232
* @return MappingException
3333
*/
@@ -330,7 +330,7 @@ public static function joinColumnMustPointToMappedField($className, $joinColumn)
330330
}
331331

332332
/**
333-
* @param string $className
333+
* @param class-string $className
334334
*
335335
* @return MappingException
336336
*/

psalm-baseline.xml

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.3.0@b6faa3e96b8eb50ec71384c53799b8a107236bb6">
2+
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
33
<file src="lib/Doctrine/ORM/AbstractQuery.php">
44
<FalsableReturnStatement occurrences="1">
55
<code>! $filteredParameters-&gt;isEmpty() ? $filteredParameters-&gt;first() : null</code>
@@ -624,10 +624,6 @@
624624
</TypeDoesNotContainType>
625625
</file>
626626
<file src="lib/Doctrine/ORM/Mapping/MappingException.php">
627-
<ArgumentTypeCoercion occurrences="2">
628-
<code>$className</code>
629-
<code>$entityName</code>
630-
</ArgumentTypeCoercion>
631627
<MissingParamType occurrences="4">
632628
<code>$className</code>
633629
<code>$className</code>
@@ -1622,9 +1618,6 @@
16221618
<code>$collectionToDelete</code>
16231619
<code>$collectionToUpdate</code>
16241620
</InvalidArgument>
1625-
<InvalidArrayOffset occurrences="1">
1626-
<code>$commitOrder[$i]</code>
1627-
</InvalidArrayOffset>
16281621
<InvalidPropertyAssignmentValue occurrences="2">
16291622
<code>$this-&gt;entityChangeSets</code>
16301623
<code>$this-&gt;entityChangeSets</code>

0 commit comments

Comments
 (0)