8000 Add return types and parameter types · symfony/symfony-docs@0a00d17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a00d17

Browse files
Add return types and parameter types
1 parent 4a4ed4a commit 0a00d17
  • validator
  • configuration
  • console
  • contributing
  • controller
  • create_framework
  • form
  • frontend
  • http_cache
  • logging
  • messenger
  • quick_tour
  • reference
  • routing
  • security
  • serializer
  • service_container
  • testing
  • validation
  • workflow
  • 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

    +370
    -338
    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

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

    543-
    public function getConfigTreeBuilder()
    543+
    use Symfony\Component\Config\Definition\Builder\NodeDefinition;
    544+
    545+
    public function getConfigTreeBuilder(): TreeBuilder
    544546
    {
    545547
    $treeBuilder = new TreeBuilder('database');
    546548

    @@ -569,7 +571,7 @@ tree with ``append()``::
    569571
    return $treeBuilder;
    570572
    }
    571573

    572-
    public function addParametersNode()
    574+
    public function addParametersNode(): NodeDefinition
    573575
    {
    574576
    $treeBuilder = new TreeBuilder('parameters');
    575577

    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
    }

    0 commit comments

    Comments
     (0)
    0