Skip to content

Commit

Permalink
Add return types and parameter types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Jul 13, 2023
1 parent 4a4ed4a commit 0a00d17
Show file tree
Hide file tree
Showing 105 changed files with 370 additions and 338 deletions.
4 changes: 2 additions & 2 deletions best_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,15 @@ checks that all application URLs load successfully::
/**
* @dataProvider urlProvider
*/
public function testPageIsSuccessful($url)
public function testPageIsSuccessful($url): void
{
$client = self::createClient();
$client->request('GET', $url);

$this->assertResponseIsSuccessful();
}

public function urlProvider()
public function urlProvider(): \Generator
{
yield ['/'];
yield ['/posts'];
Expand Down
14 changes: 7 additions & 7 deletions bundles/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ The ``Configuration`` class to handle the sample configuration looks like::

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('acme_social');

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

// src/Acme/SocialBundle/DependencyInjection/AcmeSocialExtension.php
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();

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

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

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

public function getNamespace()
public function getNamespace(): string
{
return 'http://acme_company.com/schema/dic/hello';
}
Expand Down Expand Up @@ -490,7 +490,7 @@ can place it anywhere you like. You should return this path as the base path::
{
// ...

public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string
{
return __DIR__.'/../Resources/config/schema';
}
Expand Down
6 changes: 3 additions & 3 deletions bundles/extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This is how the extension of an AcmeHelloBundle should look like::

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

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

public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
// ...

Expand Down
4 changes: 2 additions & 2 deletions bundles/prepend_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To give an Extension the power to do this, it needs to implement
{
// ...

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

// src/Acme/HelloBundle/DependencyInjection/AcmeHelloExtension.php
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
// get all bundles
$bundles = $container->getParameter('kernel.bundles');
Expand Down
5 changes: 3 additions & 2 deletions cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ with either :class:`Symfony\\Contracts\\Cache\\CacheInterface` or
``Psr\Cache\CacheItemPoolInterface``::

use Symfony\Contracts\Cache\CacheInterface;
// ...

// from a controller method
public function listProducts(CacheInterface $customThingCache)
public function listProducts(CacheInterface $customThingCache): Response
{
// ...
}
Expand Down Expand Up @@ -555,7 +556,7 @@ the same key could be invalidated with one function call::
) {
}

public function someMethod()
public function someMethod(): void
{
$value0 = $this->myCachePool->get('item_0', function (ItemInterface $item): string {
$item->tag(['foo', 'bar']);
Expand Down
4 changes: 2 additions & 2 deletions components/asset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ every day::
$this->version = date('Ymd');
}

public function getVersion(string $path)
public function getVersion(string $path): \DateTimeInterface
{
return $this->version;
}

public function applyVersion(string $path)
public function applyVersion(string $path): string
{
return sprintf('%s?v=%s', $path, $this->getVersion($path));
}
Expand Down
2 changes: 1 addition & 1 deletion components/browser_kit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ This method accepts a request and should return a response::

class Client extends AbstractBrowser
{
protected function doRequest($request)
protected function doRequest($request): Response
{
// ... convert request into a response

Expand Down
8 changes: 5 additions & 3 deletions components/config/definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ implements the :class:`Symfony\\Component\\Config\\Definition\\ConfigurationInte

class DatabaseConfiguration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('database');

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

public function getConfigTreeBuilder()
use Symfony\Component\Config\Definition\Builder\NodeDefinition;

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('database');

Expand Down Expand Up @@ -569,7 +571,7 @@ tree with ``append()``::
return $treeBuilder;
}

public function addParametersNode()
public function addParametersNode(): NodeDefinition
{
$treeBuilder = new TreeBuilder('parameters');

Expand Down
4 changes: 2 additions & 2 deletions components/config/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ which allows for recursively importing other resources::

class YamlUserLoader extends FileLoader
{
public function load($resource, $type = null)
public function load($resource, $type = null): void
{
$configValues = Yaml::parse(file_get_contents($resource));

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

public function supports($resource, $type = null)
public function supports($resource, $type = null): bool
{
return is_string($resource) && 'yaml' === pathinfo(
$resource,
Expand Down
6 changes: 4 additions & 2 deletions components/console/changing_default_command.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ name to the ``setDefaultCommand()`` method::
#[AsCommand(name: 'hello:world')]
class HelloWorldCommand extends Command
{
protected function configure()
protected function configure(): void
{
$this->setDescription('Outputs "Hello World"');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Hello World');

return Command::SUCCESS;
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/console/console_arguments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Have a look at the following command that has three options::
#[AsCommand(name: 'demo:args', description: 'Describe args behaviors')]
class DemoArgsCommand extends Command
{
protected function configure()
protected function configure(): void
{
$this
->setDefinition(
Expand All @@ -34,7 +34,7 @@ Have a look at the following command that has three options::
);
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
// ...
}
Expand Down
2 changes: 1 addition & 1 deletion components/console/helpers/questionhelper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ from the command line, you need to set the inputs that the command expects::
use Symfony\Component\Console\Tester\CommandTester;

// ...
public function testExecute()
public function testExecute(): void
{
// ...
$commandTester = new CommandTester($command);
Expand Down
6 changes: 4 additions & 2 deletions components/console/logger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PSR-3 compliant logger::
) {
}

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

$myDependency = new MyDependency($logger);
$myDependency->doStuff();

// ...
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/dependency_injection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ it was only optional then you could use setter injection instead::
{
private \Mailer $mailer;

public function setMailer(\Mailer $mailer)
public function setMailer(\Mailer $mailer): void
{
$this->mailer = $mailer;
}
Expand Down
Loading

0 comments on commit 0a00d17

Please sign in to comment.