Skip to content

Commit 3a8132c

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: Add property types
2 parents d237144 + 4a4ed4a commit 3a8132c

30 files changed

+93
-110
lines changed

components/asset.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ every day::
203203

204204
class DateVersionStrategy implements VersionStrategyInterface
205205
{
206-
private $version;
206+
private \DateTimeInterface $version;
207207

208208
public function __construct()
209209
{

components/dependency_injection.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ you want to make available as a service::
3131

3232
class Mailer
3333
{
34-
private $transport;
34+
private string $transport;
3535

3636
public function __construct()
3737
{
@@ -55,7 +55,7 @@ so this is passed into the constructor::
5555
class Mailer
5656
{
5757
public function __construct(
58-
private $transport,
58+
private string $transport,
5959
) {
6060
}
6161

@@ -124,7 +124,7 @@ it was only optional then you could use setter injection instead::
124124

125125
class NewsletterManager
126126
{
127-
private $mailer;
127+
private \Mailer $mailer;
128128

129129
public function setMailer(\Mailer $mailer)
130130
{

components/property_access.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ it with ``get``. So the actual method becomes ``getFirstName()``::
135135
// ...
136136
class Person
137137
{
138-
private $firstName = 'Wouter';
138+
private string $firstName = 'Wouter';
139139

140140
public function getFirstName()
141141
{
@@ -157,8 +157,8 @@ getters, this means that you can do something like this::
157157
// ...
158158
class Person
159159
{
160-
private $author = true;
161-
private $children = [];
160+
private bool $author = true;
161+
private array $children = [];
162162

163163
public function isAuthor()
164164
{
@@ -250,7 +250,7 @@ The ``getValue()`` method can also use the magic ``__get()`` method::
250250
// ...
251251
class Person
252252
{
253-
private $children = [
253+
private array $children = [
254254
'Wouter' => [...],
255255
];
256256

@@ -280,7 +280,7 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert
280280
// ...
281281
class Person
282282
{
283-
private $children = [
283+
private array $children = [
284284
'wouter' => [...],
285285
];
286286

@@ -379,7 +379,7 @@ see `Enable other Features`_::
379379
// ...
380380
class Person
381381
{
382-
private $children = [];
382+
private array $children = [];
383383

384384
public function __call($name, $args)
385385
{
@@ -422,7 +422,7 @@ properties through *adder* and *remover* methods::
422422
/**
423423
* @var string[]
424424
*/
425-
private $children = [];
425+
private array $children = [];
426426

427427
public function getChildren(): array
428428
{

components/property_info.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ information from annotations of properties and methods, such as ``@var``,
431431
* @param string $bar
432432
*/
433433
public function __construct(
434-
private $bar,
434+
private string $bar,
435435
) {
436436
}
437437
}

components/runtime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ always using this ``ReactPHPRunner``::
440440

441441
class ReactPHPRuntime extends GenericRuntime
442442
{
443-
private $port;
443+
private int $port;
444444

445445
public function __construct(array $options)
446446
{

components/serializer.rst

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ Assume you have the following plain-old-PHP object::
244244

245245
class MyObj
246246
{
247-
public $foo;
247+
public string $foo;
248248

249-
private $bar;
249+
private string $bar;
250250

251251
public function getBar()
252252
{
@@ -303,10 +303,10 @@ Then, create your groups definition:
303303
class MyObj
304304
{
305305
#[Groups(['group1', 'group2'])]
306-
public $foo;
306+
public string $foo;
307307
308308
#[Groups(['group4'])]
309-
public $anotherProperty;
309+
public string $anotherProperty;
310310
311311
#[Groups(['group3'])]
312312
public function getBar() // is* methods are also supported
@@ -449,10 +449,10 @@ Option 1: Using ``@Ignore`` Annotation
449449
450450
class MyClass
451451
{
452-
public $foo;
452+
public string $foo;
453453
454454
#[Ignore]
455-
public $bar;
455+
public string $bar;
456456
}
457457
458458
.. code-block:: yaml
@@ -1237,8 +1237,8 @@ You can change this behavior by setting the ``AbstractObjectNormalizer::SKIP_NUL
12371237
to ``true``::
12381238

12391239
$dummy = new class {
1240-
public $foo;
1241-
public $bar = 'notNull';
1240+
public ?string $foo = null;
1241+
public string $bar = 'notNull';
12421242
};
12431243

12441244
$normalizer = new ObjectNormalizer();
@@ -1313,8 +1313,8 @@ Circular references are common when dealing with entity relations::
13131313

13141314
class Organization
13151315
{
1316-
private $name;
1317-
private $members;
1316+
private string $name;
1317+
private array $members;
13181318

13191319
public function setName($name)
13201320
{
@@ -1339,10 +1339,10 @@ Circular references are common when dealing with entity relations::
13391339

13401340
class Member
13411341
{
1342-
private $name;
1343-
private $organization;
1342+
private string $name;
1343+
private Organization $organization;
13441344

1345-
public function setName($name)
1345+
public function setName(string $name)
13461346
{
13471347
$this->name = $name;
13481348
}
@@ -1412,12 +1412,12 @@ structure::
14121412

14131413
class MyObj
14141414
{
1415-
public $foo;
1415+
public string $foo;
14161416

14171417
/**
14181418
* @var self
14191419
*/
1420-
public $child;
1420+
public MyObj $child;
14211421
}
14221422

14231423
$level1 = new MyObj();
@@ -1445,7 +1445,7 @@ Here, we set it to 2 for the ``$child`` property:
14451445
class MyObj
14461446
{
14471447
#[MaxDepth(2)]
1448-
public $child;
1448+
public MyObj $child;
14491449
14501450
// ...
14511451
}
@@ -1507,10 +1507,10 @@ having unique identifiers::
15071507

15081508
class Foo
15091509
{
1510-
public $id;
1510+
public int $id;
15111511

15121512
#[MaxDepth(1)]
1513-
public $child;
1513+
public MyObj $child;
15141514
}
15151515

15161516
$level1 = new Foo();
@@ -1606,8 +1606,8 @@ context option::
16061606
class MyObj
16071607
{
16081608
public function __construct(
1609-
private $foo,
1610-
private $bar,
1609+
private string $foo,
1610+
private string $bar,
16111611
) {
16121612
}
16131613
}
@@ -1646,8 +1646,8 @@ parameter of the ``ObjectNormalizer``::
16461646

16471647
class ObjectOuter
16481648
{
1649-
private $inner;
1650-
private $date;
1649+
private ObjectInner $inner;
1650+
private \DateTimeInterface $date;
16511651

16521652
public function getInner()
16531653
{
@@ -1672,8 +1672,8 @@ parameter of the ``ObjectNormalizer``::
16721672

16731673
class ObjectInner
16741674
{
1675-
public $foo;
1676-
public $bar;
1675+
public string $foo;
1676+
public string $bar;
16771677
}
16781678

16791679
$normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());

components/validator/metadata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ the ``Author`` class has at least 3 characters::
1717

1818
class Author
1919
{
20-
private $firstName;
20+
private string $firstName;
2121

2222
public static function loadValidatorMetadata(ClassMetadata $metadata)
2323
{

configuration/using_parameters_in_dic.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ be injected with this parameter via the extension as follows::
101101

102102
class Configuration implements ConfigurationInterface
103103
{
104-
private $debug;
104+
private bool $debug;
105105

106-
public function __construct($debug)
106+
public function __construct(private bool $debug)
107107
{
108-
$this->debug = (bool) $debug;
109108
}
110109

111110
public function getConfigTreeBuilder()

contributing/code/standards.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ short example containing most features described below::
4949
{
5050
public const SOME_CONST = 42;
5151

52-
/**
53-
* @var string
54-
*/
55-
private $fooBar;
52+
private string $fooBar;
5653

5754
/**
5855
* @param $dummy some argument description

controller/upload_file.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ add a PDF brochure for each product. To do so, add a new property called
2222
// ...
2323

2424
#[ORM\Column(type: 'string')]
25-
private $brochureFilename;
25+
private string $brochureFilename;
2626

2727
public function getBrochureFilename(): string
2828
{
@@ -238,7 +238,7 @@ logic to a separate service::
238238
class FileUploader
239239
{
240240
public function __construct(
241-
private $targetDirectory,
241+
private string $targetDirectory,
242242
private SluggerInterface $slugger,
243243
) {
244244
}

doctrine/associations.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ the ``Product`` entity (and getter & setter methods):
148148
// ...
149149
150150
#[ORM\ManyToOne(targetEntity: Category::class, inversedBy: 'products')]
151-
private $category;
151+
private Category $category;
152152
153153
public function getCategory(): ?Category
154154
{
@@ -220,7 +220,7 @@ class that will hold these objects:
220220
// ...
221221
222222
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'category')]
223-
private $products;
223+
private array $products;
224224
225225
public function __construct()
226226
{
@@ -588,7 +588,7 @@ that behavior, use the `orphanRemoval`_ option inside ``Category``:
588588
// ...
589589
590590
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'category', orphanRemoval: true)]
591-
private $products;
591+
private array $products;
592592
593593
594594
Thanks to this, if the ``Product`` is removed from the ``Category``, it will be

form/create_form_type_extension.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ the database::
107107
/**
108108
* @var string The path - typically stored in the database
109109
*/
110-
private $path;
110+
private string $path;
111111

112112
// ...
113113

form/inherit_data_option.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ entities, a ``Company`` and a ``Customer``::
1010

1111
class Company
1212
{
13-
private $name;
14-
private $website;
13+
private string $name;
14+
private string $website;
1515

16-
private $address;
17-
private $zipcode;
18-
private $city;
19-
private $country;
16+
private string $address;
17+
private string $zipcode;
18+
private string $city;
19+
private string $country;
2020
}
2121

2222
.. code-block:: php
@@ -26,13 +26,13 @@ entities, a ``Company`` and a ``Customer``::
2626
2727
class Customer
2828
{
29-
private $firstName;
30-
private $lastName;
29+
private string $firstName;
30+
private string $lastName;
3131
32-
private $address;
33-
private $zipcode;
34-
private $city;
35-
private $country;
32+
private string $address;
33+
private string $zipcode;
34+
private string $city;
35+
private string $country;
3636
}
3737
3838
As you can see, each entity shares a few of the same fields: ``address``,

form/unit_testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ make sure the ``FormRegistry`` uses the created instance::
154154

155155
class TestedTypeTest extends TypeTestCase
156156
{
157-
private $objectManager;
157+
private MockObject|ObjectManager $objectManager;
158158

159159
protected function setUp(): void
160160
{

0 commit comments

Comments
 (0)