8000 Merge branch '6.2' into 6.3 · symfony/symfony-docs@1782e6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1782e6d

Browse files
committed
Merge branch '6.2' into 6.3
* 6.2: Add return types and parameter types
2 parents 3a8132c + f90b324 commit 1782e6d

File tree

105 files changed

+369
-337
lines changed

Some content is hidden

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

105 files changed

+369
-337
lines changed

best_practices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,15 @@ checks that all application URLs load successfully::
411411
/**
412412
* @dataProvider urlProvider
413413
*/
414-
public function testPageIsSuccessful($url)
414+
public function testPageIsSuccessful($url): void
415415
{
416416
$client = self::createClient();
417417
$client->request('GET', $url);
418418

419419
$this->assertResponseIsSuccessful();
420420
}
421421

422-
public function urlProvider()
422+
public function urlProvider(): \Generator
423423
{
424424
yield ['/'];
425425
yield ['/posts'];

bundles/configuration.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ The ``Configuration`` class to handle the sample configuration looks like::
183183

184184
class Configuration implements ConfigurationInterface
185185
{
186-
public function getConfigTreeBuilder()
186+
public function getConfigTreeBuilder(): TreeBuilder
187187
{
188188
$treeBuilder = new TreeBuilder('acme_social');
189189

@@ -217,7 +217,7 @@ force validation (e.g. if an additional option was passed, an exception will be
217217
thrown)::
218218

219219
// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
220-
public function load(array $configs, ContainerBuilder $container)
220+
public function load(array $configs, ContainerBuilder $container): void
221221
{
222222
$configuration = new Configuration();
223223

@@ -259,7 +259,7 @@ In your extension, you can load this and dynamically set its arguments::
259259
use Symfony\Component\Config\FileLocator;
260260
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
261261

262-
public function load(array $configs, ContainerBuilder $container)
262+
public function load(array $configs, ContainerBuilder $container): void
263263
{
264264
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
265265
$loader->load('services.xml');
@@ -288,7 +288,7 @@ In your extension, you can load this and dynamically set its arguments::
288288
class AcmeHelloExtension extends ConfigurableExtension
289289
{
290290
// note that this method is called loadInternal and not load
291-
protected function loadInternal(array $mergedConfig, ContainerBuilder $container)
291+
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
292292
{
293293
// ...
294294
}
@@ -304,7 +304,7 @@ In your extension, you can load this and dynamically set its arguments::
304304
(e.g. by overriding configurations and using :phpfunction:`isset` to check
305305
for the existence of a value). Be aware that it'll be very hard to support XML::
306306

307-
public function load(array $configs, ContainerBuilder $container)
307+
public function load(array $configs, ContainerBuilder $container): void
308308
{
309309
$config = [];
310310
// let resources override the previous set value
@@ -458,7 +458,7 @@ the extension. You might want to change this to a more professional URL::
458458
{
459459
// ...
460460

461-
public function getNamespace()
461+
public function getNamespace(): string
462462
{
463463
return 'http://acme_company.com/schema/dic/hello';
464464
}
@@ -490,7 +490,7 @@ can place it anywhere you like. You should return this path as the base path::
490490
{
491491
// ...
492492

493-
public function getXsdValidationBasePath()
493+
public function getXsdValidationBasePath(): string
494494
{
495495
return __DIR__.'/../Resources/config/schema';
496496
}

bundles/extension.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This is how the extension of an AcmeHelloBundle should look like::
3434

3535
class AcmeHelloExtension extends Extension
3636
{
37-
public function load(array $configs, ContainerBuilder $container)
37+
public function load(array $configs, ContainerBuilder $container): void
3838
{
3939
// ... you'll load the files here later
4040
}
@@ -90,7 +90,7 @@ For instance, assume you have a file called ``services.xml`` in the
9090
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
9191

9292
// ...
93-
public function load(array $configs, ContainerBuilder $container)
93+
public function load(array $configs, ContainerBuilder $container): void
9494
{
9595
$loader = new XmlFileLoader(
9696
$container,
@@ -167,7 +167,7 @@ they are compiled when generating the application cache to improve the overall
167167
performance. Define the list of annotated classes to compile in the
168168
``addAnnotatedClassesToCompile()`` method::
169169

170-
public function load(array $configs, ContainerBuilder $container)
170+
public function load(array $configs, ContainerBuilder $container): void
171171
{
172172
// ...
173173

bundles/prepend_extension.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ To give an Extension the power to do this, it needs to implement
3131
{
3232
// ...
3333

34-
public function prepend(ContainerBuilder $container)
34+
public function prepend(ContainerBuilder $container): void
3535
{
3636
// ...
3737
}
@@ -52,7 +52,7 @@ a configuration setting in multiple bundles as well as disable a flag in multipl
5252
in case a specific other bundle is not registered::
5353

5454
// src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php
55-
public function prepend(ContainerBuilder $container)
55+
public function prepend(ContainerBuilder $container): void
5656
{
5757
// get all bundles
5858
$bundles = $container->getParameter('kernel.bundles');

cache.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,10 @@ with either :class:`Symfony\\Contracts\\Cache\\CacheInterface` or
307307
``Psr\Cache\CacheItemPoolInterface``::
308308

309309
use Symfony\Contracts\Cache\CacheInterface;
310+
// ...
310311

311312
// from a controller method
312-
public function listProducts(CacheInterface $customThingCache)
313+
public function listProducts(CacheInterface $customThingCache): Response
313314
{
314315
// ...
315316
}
@@ -555,7 +556,7 @@ the same key could be invalidated with one function call::
555556
) {
556557
}
557558

558-
public function someMethod()
559+
public function someMethod(): void
559560
{
560561
$value0 = $this->myCachePool->get('item_0', function (ItemInterface $item): string {
561562
$item->tag(['foo', 'bar']);

components/asset.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ every day::
210210
$this->version = date('Ymd');
211211
}
212212

213-
public function getVersion(string $path)
213+
public function getVersion(string $path): \DateTimeInterface
214214
{
215215
return $this->version;
216216
}
217217

218-
public function applyVersion(string $path)
218+
public function applyVersion(string $path): string
219219
{
220220
return sprintf('%s?v=%s', $path, $this->getVersion($path));
221221
}

components/browser_kit.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ This method accepts a request and should return a response::
3838

3939
class Client extends AbstractBrowser
4040
{
41-
protected function doRequest($request)
41+
protected function doRequest($request): Response
4242
{
4343
// ... convert request into a response
4444

components/config/definition.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ implements the :class:`Symfony\\Component\\Config\\Definition\\ConfigurationInte
5454

5555
class DatabaseConfiguration implements ConfigurationInterface
5656
{
57-
public function getConfigTreeBuilder()
57+
public function getConfigTreeBuilder(): TreeBuilder
5858
{
5959
$treeBuilder = new TreeBuilder('database');
6060

@@ -568,7 +568,9 @@ be large and you may want to split it up into sections. You can do this
568568
by making a section a separate node and then appending it into the main
569569
tree with ``append()``::
570570

571-
public function getConfigTreeBuilder()
571+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
572+
573+
public function getConfigTreeBuilder(): TreeBuilder
572574
{
573575
$treeBuilder = new TreeBuilder('database');
574576

@@ -597,7 +599,7 @@ tree with ``append()``::
597599
return $treeBuilder;
598600
}
599601

600-
public function addParametersNode()
602+
public function addParametersNode(): NodeDefinition
601603
{
602604
$treeBuilder = new TreeBuilder('parameters');
603605

components/config/resources.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ which allows for recursively importing other resources::
4343

4444
class YamlUserLoader extends FileLoader
4545
{
46-
public function load($resource, $type = null)
46+
public function load($resource, $type = null): void
4747
{
4848
$configValues = Yaml::parse(file_get_contents($resource));
4949

@@ -54,7 +54,7 @@ which allows for recursively importing other resources::
5454
// $this->import('extra_users.yaml');
5555
}
5656

57-
public function supports($resource, $type = null)
57+
public function supports($resource, $type = null): bool
5858
{
5959
return is_string($resource) && 'yaml' === pathinfo(
6060
$resource,

components/console/changing_default_command.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ name to the ``setDefaultCommand()`` method::
1515
#[AsCommand(name: 'hello:world')]
1616
class HelloWorldCommand extends Command
1717
{
18-
protected function configure()
18+
protected function configure(): void
1919
{
2020
$this->setDescription('Outputs "Hello World"');
2121
}
2222

23-
protected function execute(InputInterface $input, OutputInterface $output)
23+
protected function execute(InputInterface $input, OutputInterface $output): int
2424
{
2525
$output->writeln('Hello World');
26+
27+
return Command::SUCCESS;
2628
}
2729
}
2830

components/console/console_arguments.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Have a look at the following command that has three options::
2222
#[AsCommand(name: 'demo:args', description: 'Describe args behaviors')]
2323
class DemoArgsCommand extends Command
2424
{
25-
protected function configure()
25+
protected function configure(): void
2626
{
2727
$this
2828
->setDefinition(
@@ -34,7 +34,7 @@ Have a look at the following command that has three options::
3434
);
3535
}
3636

37-
protected function execute(InputInterface $input, OutputInterface $output)
37+
protected function execute(InputInterface $input, OutputInterface $output): int
3838
{
3939
// ...
4040
}

components/console/helpers/questionhelper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ from the command line, you need to set the inputs that the command expects::
488488
use Symfony\Component\Console\Tester\CommandTester;
489489

490490
// ...
491-
public function testExecute()
491+
public function testExecute(): void
492492
{
493493
// ...
494494
$commandTester = new CommandTester($command);

components/console/logger.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PSR-3 compliant logger::
2121
) {
2222
}
2323

24-
public function doStuff()
24+
public function doStuff(): void
2525
{
2626
$this->logger->info('I love Tony Vairelles\' hairdresser.');
2727
}
@@ -44,12 +44,14 @@ You can rely on the logger to use this dependency inside a command::
4444
)]
4545
class MyCommand extends Command
4646
{
47-
protected function execute(InputInterface $input, OutputInterface $output)
47+
protected function execute(InputInterface $input, OutputInterface $output): int
4848
{
4949
$logger = new ConsoleLogger($output);
5050

5151
$myDependency = new MyDependency($logger);
5252
$myDependency->doStuff();
53+
54+
// ...
5355
}
5456
}
5557

components/dependency_injection.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ it was only optional then you could use setter injection instead::
126126
{
127127
private \Mailer $mailer;
128128

129-
public function setMailer(\Mailer $mailer)
129+
public function setMailer(\Mailer $mailer): void
130130
{
131131
$this->mailer = $mailer;
132132
}

components/dependency_injection/compilation.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ A very simple extension may just load configuration files into the container::
6161

6262
class AcmeDemoExtension implements ExtensionInterface
6363
{
64-
public function load(array $configs, ContainerBuilder $container)
64+
public function load(array $configs, ContainerBuilder $container): void
6565
{
6666
$loader = new XmlFileLoader(
6767
$container,
@@ -90,7 +90,7 @@ The Extension must specify a ``getAlias()`` method to implement the interface::
9090
{
9191
// ...
9292

93-
public function getAlias()
93+
public function getAlias(): string
9494
{
9595
return 'acme_demo';
9696
}
@@ -132,7 +132,7 @@ are loaded::
132132
The values from those sections of the config files are passed into the first
133133
argument of the ``load()`` method of the extension::
134134

135-
public function load(array $configs, ContainerBuilder $container)
135+
public function load(array $configs, ContainerBuilder $container): void
136136
{
137137
$foo = $configs[0]['foo']; //fooValue
138138
$bar = $configs[0]['bar']; //barValue
@@ -158,7 +158,7 @@ you could access the config value this way::
158158
use Symfony\Component\Config\Definition\Processor;
159159
// ...
160160

161-
public function load(array $configs, ContainerBuilder $container)
161+
public function load(array $configs, ContainerBuilder $container): void
162162
{
163163
$configuration = new Configuration();
164164
$processor = new Processor();
@@ -175,12 +175,12 @@ namespace so that the relevant parts of an XML config file are passed to
175175
the extension. The other to specify the base path to XSD files to validate
176176
the XML configuration::
177177

178-
public function getXsdValidationBasePath()
178+
public function getXsdValidationBasePath(): string
179179
{
180180
return __DIR__.'/../Resources/config/';
181181
}
182182

183-
public function getNamespace()
183+
public function getNamespace(): string
184184
{
185185
return 'http://www.example.com/symfony/schema/';
186186
}
@@ -219,7 +219,7 @@ The processed config value can now be added as container parameters as if
219219
it were listed in a ``parameters`` section of the config file but with the
220220
additional benefit of merging multiple files and validation of the configuration::
221221

222-
public function load(array $configs, ContainerBuilder $container)
222+
public function load(array $configs, ContainerBuilder $container): void
223223
{
224224
$configuration = new Configuration();
225225
$processor = new Processor();
@@ -234,7 +234,7 @@ More complex configuration requirements can be catered for in the Extension
234234
classes. For example, you may choose to load a main service configuration
235235
file but also load a secondary one only if a certain parameter is set::
236236

237-
public function load(array $configs, ContainerBuilder $container)
237+
public function load(array $configs, ContainerBuilder $container): void
238238
{
239239
$configuration = new Configuration();
240240
$processor = new Processor();
@@ -323,7 +323,7 @@ method is called by implementing
323323
{
324324
// ...
325325

326-
public function prepend(ContainerBuilder $container)
326+
public function prepend(ContainerBuilder $container): void
327327
{
328328
// ...
329329

@@ -354,7 +354,7 @@ compilation::
354354

355355
class AcmeDemoExtension implements ExtensionInterface, CompilerPassInterface
356356
{
357-
public function process(ContainerBuilder $container)
357+
public function process(ContainerBuilder $container): void
358358
{
359359
// ... do something during the compilation
360360
}
@@ -408,7 +408,7 @@ class implementing the ``CompilerPassInterface``::
408408

409409
class CustomPass implements CompilerPassInterface
410410
{
411-
public function process(ContainerBuilder $container)
411+
public function process(ContainerBuilder $container): void
412412
{
413413
// ... do something during the compilation
414414
}

0 commit comments

Comments
 (0)
0