Skip to content

Commit ca2ac32

Browse files
committed
minor #18356 Add property types and return types in a few places (alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- Add property types and return types in a few places Commits ------- 472f579 Add property types and return types in a few places
2 parents ae9405e + 472f579 commit ca2ac32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+310
-308
lines changed

bundles/best_practices.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ The end user can provide values in any configuration file:
436436
// config/services.php
437437
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
438438
439-
return static function (ContainerConfigurator $container) {
439+
return static function (ContainerConfigurator $container): void {
440440
$container->parameters()
441441
->set('acme_blog.author.email', 'fabien@example.com')
442442
;

bundles/configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ as integration of other related components:
4242
// config/packages/framework.php
4343
use Symfony\Config\FrameworkConfig;
4444
45-
return static function (FrameworkConfig $framework) {
45+
return static function (FrameworkConfig $framework): void {
4646
$framework->form()->enabled(true);
4747
};
4848

bundles/prepend_extension.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to
139139
// config/packages/acme_something.php
140140
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
141141
142-
return static function (ContainerConfigurator $container) {
142+
return static function (ContainerConfigurator $container): void {
143143
$container->extension('acme_something', [
144144
// ...
145145
'use_acme_goodbye' => false,

cache.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ adapter (template) they use by using the ``app`` and ``system`` key like:
8585
// config/packages/cache.php
8686
use Symfony\Config\FrameworkConfig;
8787
88-
return static function (FrameworkConfig $framework) {
88+
return static function (FrameworkConfig $framework): void {
8989
$framework->cache()
9090
->app('cache.adapter.filesystem')
9191
->system('cache.adapter.system')
@@ -163,7 +163,7 @@ will create pools with service IDs that follow the pattern ``cache.[type]``.
163163
// config/packages/cache.php
164164
use Symfony\Config\FrameworkConfig;
165165
166-
return static function (FrameworkConfig $framework) {
166+
return static function (FrameworkConfig $framework): void {
167167
$framework->cache()
168168
// Only used with cache.adapter.filesystem
169169
->directory('%kernel.cache_dir%/pools')
@@ -264,7 +264,7 @@ You can also create more customized pools:
264264
// config/packages/cache.php
265265
use Symfony\Config\FrameworkConfig;
266266
267-
return static function (FrameworkConfig $framework) {
267+
return static function (FrameworkConfig $framework): void {
268268
$cache = $framework->cache();
269269
$cache->defaultMemcachedProvider('memcached://localhost');
270270
@@ -444,7 +444,7 @@ and use that when configuring the pool.
444444
use Symfony\Component\DependencyInjection\ContainerBuilder;
445445
use Symfony\Config\FrameworkConfig;
446446
447-
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
447+
return static function (ContainerBuilder $container, FrameworkConfig $framework): void {
448448
$framework->cache()
449449
->pool('cache.my_redis')
450450
->adapters(['cache.adapter.redis'])
@@ -524,7 +524,7 @@ Symfony stores the item automatically in all the missing pools.
524524
// config/packages/cache.php
525525
use Symfony\Config\FrameworkConfig;
526526
527-
return static function (FrameworkConfig $framework) {
527+
return static function (FrameworkConfig $framework): void {
528528
$framework->cache()
529529
->pool('my_cache_pool')
530530
->defaultLifetime(31536000) // One year
@@ -616,7 +616,7 @@ to enable this feature. This could be added by using the following configuration
616616
// config/packages/cache.php
617617
use Symfony\Config\FrameworkConfig;
618618
619-
return static function (FrameworkConfig $framework) {
619+
return static function (FrameworkConfig $framework): void {
620620
$framework->cache()
621621
->pool('my_cache_pool')
622622
->tags(true)
@@ -670,7 +670,7 @@ achieved by specifying the adapter.
670670
// config/packages/cache.php
671671
use Symfony\Config\FrameworkConfig;
672672
673-
return static function (FrameworkConfig $framework) {
673+
return static function (FrameworkConfig $framework): void {
674674
$framework->cache()
675675
->pool('my_cache_pool')
676676
->tags('tag_pool')

components/dependency_injection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ config files:
313313
314314
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
315315
316-
return static function (ContainerConfigurator $container) {
316+
return static function (ContainerConfigurator $container): void {
317317
$container->parameters()
318318
// ...
319319
->set('mailer.transport', 'sendmail')

components/dependency_injection/_imports-parameters-note.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
// config/services.php
3232
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
3333

34-
return static function (ContainerConfigurator $container) {
34+
return static function (ContainerConfigurator $container): void {
3535
$container->import('%kernel.project_dir%/somefile.yaml');
3636
};

components/expression_language.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ PHP type (including objects)::
107107

108108
class Apple
109109
{
110-
public $variety;
110+
public string $variety;
111111
}
112112

113113
$apple = new Apple();

components/property_access.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ method::
177177
// ...
178178
class Person
179179
{
180-
public $name;
180+
public string $name;
181181
}
182182

183183
$person = new Person();
@@ -321,26 +321,26 @@ can use setters, the magic ``__set()`` method or properties to set values::
321321
// ...
322322
class Person
323323
{
324-
public $firstName;
325-
private $lastName;
326-
private $children = [];
324+
public string $firstName;
325+
private string $lastName;
326+
private array $children = [];
327327

328-
public function setLastName($name)
328+
public function setLastName($name): void
329329
{
330330
$this->lastName = $name;
331331
}
332332

333-
public function getLastName()
333+
public function getLastName(): string
334334
{
335335
return $this->lastName;
336336
}
337337

338-
public function getChildren()
338+
public function getChildren(): array
339339
{
340340
return $this->children;
341341
}
342342

343-
public function __set($property, $value)
343+
public function __set($property, $value): void
344344
{
345345
$this->$property = $value;
346346
}
@@ -507,15 +507,15 @@ You can also mix objects and arrays::
507507
// ...
508508
class Person
509509
{
510-
public $firstName;
511-
private $children = [];
510+
public string $firstName;
511+
private array $children = [];
512512

513-
public function setChildren($children)
513+
public function setChildren($children): void
514514
{
515515
$this->children = $children;
516516
}
517517

518-
public function getChildren()
518+
public function getChildren(): array
519519
{
520520
return $this->children;
521521
}

components/serializer.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,15 @@ It is also possible to serialize only a set of specific attributes::
398398

399399
class User
400400
{
401-
public $familyName;
402-
public $givenName;
403-
public $company;
401+
public string $familyName;
402+
public string $givenName;
403+
public string $company;
404404
}
405405

406406
class Company
407407
{
408-
public $name;
409-
public $address;
408+
public string $name;
409+
public string $address;
410410
}
411411

412412
$company = new Company();
@@ -529,8 +529,8 @@ Given you have the following object::
529529

530530
class Company
531531
{
532-
public $name;
533-
public $address;
532+
public string $name;
533+
public string $address;
534534
}
535535

536536
And in the serialized form, all attributes must be prefixed by ``org_`` like
@@ -925,7 +925,7 @@ faster alternative to the
925925
926926
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
927927
928-
return static function (ContainerConfigurator $container) {
928+
return static function (ContainerConfigurator $container): void {
929929
$container->services()
930930
// ...
931931
->set('get_set_method_normalizer', GetSetMethodNormalizer::class)

components/var_dumper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ the :ref:`dump_destination option <configuration-debug-dump_destination>` of the
144144
// config/packages/debug.php
145145
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
146146
147-
return static function (ContainerConfigurator $container) {
147+
return static function (ContainerConfigurator $container): void {
148148
$container->extension('debug', [
149149
'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%',
150150
]);

configuration.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ configuration files, even if they use a different format:
136136
// config/services.php
137137
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
138138
139-
return static function (ContainerConfigurator $container) {
139+
return static function (ContainerConfigurator $container): void {
140140
$container->import('legacy_config.php');
141141
142142
// glob expressions are also supported to load multiple files
@@ -242,7 +242,7 @@ reusable configuration value. By convention, parameters are defined under the
242242
use App\Entity\BlogPost;
243243
use App\Enum\PostState;
244244
245-
return static function (ContainerConfigurator $container) {
245+
return static function (ContainerConfigurator $container): void {
246246
$container->parameters()
247247
// the parameter name is an arbitrary string (the 'app.' prefix is recommended
248248
// to better differentiate your parameters from Symfony parameters).
@@ -321,7 +321,7 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
321321
// config/packages/some_package.php
322322
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
323323
324-
return static function (ContainerConfigurator $container) {
324+
return static function (ContainerConfigurator $container): void {
325325
$container->extension('some_package', [
326326
// any string surrounded by two % is replaced by that parameter value
327327
'email_address' => '%app.admin_email%',
@@ -358,7 +358,7 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
358358
// config/services.php
359359
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
360360
361-
return static function (ContainerConfigurator $container) {
361+
return static function (ContainerConfigurator $container): void {
362362
$container->parameters()
363363
->set('url_pattern', 'http://symfony.com/?foo=%%s&amp;bar=%%d');
364364
};
@@ -620,7 +620,7 @@ This example shows how you could configure the application secret using an env v
620620
// config/packages/framework.php
621621
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
622622
623-
return static function (ContainerConfigurator $container) {
623+
return static function (ContainerConfigurator $container): void {
624624
$container->extension('framework', [
625625
// by convention the env var names are always uppercase
626626
'secret' => '%env(APP_SECRET)%',
@@ -973,7 +973,7 @@ doesn't work for parameters:
973973
974974
use App\Service\MessageGenerator;
975975
976-
return static function (ContainerConfigurator $container) {
976+
return static function (ContainerConfigurator $container): void {
977977
$container->parameters()
978978
->set('app.contents_dir', '...');
979979
@@ -1030,7 +1030,7 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
10301030
10311031
use App\Controller\LuckyController;
10321032
1033-
return static function (ContainerConfigurator $container) {
1033+
return static function (ContainerConfigurator $container): void {
10341034
$container->services()
10351035
->defaults()
10361036
// pass this value to any $projectDir argument for any service

configuration/env_var_processors.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ processor to turn the value of the ``HTTP_PORT`` env var into an integer:
4545
4646
use Symfony\Config\FrameworkConfig;
4747
48-
return static function (FrameworkConfig $framework) {
48+
return static function (FrameworkConfig $framework): void {
4949
$framework->router()
5050
->httpPort('%env(int:HTTP_PORT)%')
5151
// or
@@ -98,7 +98,7 @@ Symfony provides the following env var processors:
9898
use Symfony\Component\DependencyInjection\ContainerBuilder;
9999
use Symfony\Config\FrameworkConfig;
100100
101-
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
101+
return static function (ContainerBuilder $container, FrameworkConfig $framework): void {
102102
$container->setParameter('env(SECRET)', 'some_secret');
103103
$framework->secret(env('SECRET')->string());
104104
};
@@ -144,7 +144,7 @@ Symfony provides the following env var processors:
144144
use Symfony\Component\DependencyInjection\ContainerBuilder;
145145
use Symfony\Config\FrameworkConfig;
146146
147-
return static function (ContainerBuilder $container, FrameworkConfig $framework) {
147+
return static function (ContainerBuilder $container, FrameworkConfig $framework): void {
148148
$container->setParameter('env(HTTP_METHOD_OVERRIDE)', 'true');
149149
$framework->httpMethodOverride(env('HTTP_METHOD_OVERRIDE')->bool());
150150
};
@@ -231,7 +231,7 @@ Symfony provides the following env var processors:
231231
use Symfony\Component\DependencyInjection\ContainerBuilder;
232232
use Symfony\Config\SecurityConfig;
233233
234-
return static function (ContainerBuilder $container, SecurityConfig $security) {
234+
return static function (ContainerBuilder $container, SecurityConfig $security): void {
235235
$container->setParameter('env(HEALTH_CHECK_METHOD)', 'Symfony\Component\HttpFoundation\Request::METHOD_HEAD');
236236
$security->accessControl()
237237
->path('^/health-check$')
@@ -280,7 +280,7 @@ Symfony provides the following env var processors:
280280
use Symfony\Component\DependencyInjection\ContainerBuilder;
281281
use Symfony\Config\FrameworkConfig;
282282
283-
return static function (ContainerBuilder $container) {
283+
return static function (ContainerBuilder $container): void {
284284
$container->setParameter('env(ALLOWED_LANGUAGES)', '["en","de","es"]');
285285
$container->setParameter('app_allowed_languages', '%env(json:ALLOWED_LANGUAGES)%');
286286
};
@@ -364,7 +364,7 @@ Symfony provides the following env var processors:
364364
use Symfony\Component\DependencyInjection\ContainerBuilder;
365365
use Symfony\Config\FrameworkConfig;
366366
367-
return static function (ContainerBuilder $container) {
367+
return static function (ContainerBuilder $container): void {
368368
$container->setParameter('env(ALLOWED_LANGUAGES)', 'en,de,es');
369369
$container->setParameter('app_allowed_languages', '%env(csv:ALLOWED_LANGUAGES)%');
370370
};

configuration/micro_kernel_trait.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ because the configuration started to get bigger:
369369
// config/framework.php
370370
use Symfony\Config\FrameworkConfig;
371371
372-
return static function (FrameworkConfig $framework) {
372+
return static function (FrameworkConfig $framework): void {
373373
$framework
374374
->secret('SOME_SECRET')
375375
->profiler()

configuration/override_dir_structure.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Console script::
6767
Web front-controller::
6868

6969
// public/index.php
70-
70+
7171
// ...
7272
$_SERVER['APP_RUNTIME_OPTIONS']['dotenv_path'] = 'another/custom/path/to/.env';
7373

@@ -236,7 +236,7 @@ configuration option to define your own translations directory (use :ref:`framew
236236
// config/packages/translation.php
237237
use Symfony\Config\FrameworkConfig;
238238
239-
return static function (FrameworkConfig $framework) {
239+
return static function (FrameworkConfig $framework): void {
240240
$framework->translator()
241241
->defaultPath('%kernel.project_dir%/i18n')
242242
;

configuration/secrets.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ The secrets system is enabled by default and some of its behavior can be configu
309309
// config/packages/framework.php
310310
use Symfony\Config\FrameworkConfig;
311311
312-
return static function (FrameworkConfig $framework) {
312+
return static function (FrameworkConfig $framework): void {
313313
$framework->secrets()
314314
// ->vaultDirectory('%kernel.project_dir%/config/secrets/%kernel.environment%')
315315
// ->localDotenvFile('%kernel.project_dir%/.env.%kernel.environment%.local')

controller/error_pages.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ configuration option to point to it:
277277
// config/packages/framework.php
278278
use Symfony\Config\FrameworkConfig;
279279
280-
return static function (FrameworkConfig $framework) {
280+
return static function (FrameworkConfig $framework): void {
281281
// ...
282282
$framework->errorController('App\Controller\ErrorController::show');
283283
};

controller/upload_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Then, define a service for this class:
312312
313313
use App\Service\FileUploader;
314314
315-
return static function (ContainerConfigurator $container) {
315+
return static function (ContainerConfigurator $container): void {
316316
$services = $container->services();
317317
318318
$services->set(FileUploader::class)

0 commit comments

Comments
 (0)