Skip to content

Commit dd284af

Browse files
committed
minor #18439 Add type-hints and return types (alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- Add type-hints and return types Here we go 🙂 Commits ------- 8728589 Add type-hints and return types
2 parents 17c2bd1 + 8728589 commit dd284af

File tree

102 files changed

+312
-305
lines changed

Some content is hidden

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

102 files changed

+312
-305
lines changed

bundles/configuration.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ can add some configuration that looks like this:
8585
// config/packages/acme_social.php
8686
use Symfony\Config\AcmeSocialConfig;
8787
88-
return static function (AcmeSocialConfig $acmeSocial) {
88+
return static function (AcmeSocialConfig $acmeSocial): void {
8989
$acmeSocial->twitter()
9090
->clientId(123)
9191
->clientSecret('your_secret');
@@ -394,7 +394,7 @@ logic to the bundle class directly::
394394
// config/definition.php
395395
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
396396
397-
return static function (DefinitionConfigurator $definition) {
397+
return static function (DefinitionConfigurator $definition): void {
398398
$definition->rootNode()
399399
->children()
400400
->scalarNode('foo')->defaultValue('bar')->end()

cache.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The following example shows a typical usage of the cache::
1010
use Symfony\Contracts\Cache\ItemInterface;
1111

1212
// The callable will only be executed on a cache miss.
13-
$value = $pool->get('my_cache_key', function (ItemInterface $item) {
13+
$value = $pool->get('my_cache_key', function (ItemInterface $item): string {
1414
$item->expiresAfter(3600);
1515

1616
// ... do some HTTP request or heavy computations
@@ -557,13 +557,13 @@ the same key could be invalidated with one function call::
557557

558558
public function someMethod()
559559
{
560-
$value0 = $this->myCachePool->get('item_0', function (ItemInterface $item) {
560+
$value0 = $this->myCachePool->get('item_0', function (ItemInterface $item): string {
561561
$item->tag(['foo', 'bar']);
562562

563563
return 'debug';
564564
});
565565

566-
$value1 = $this->myCachePool->get('item_1', function (ItemInterface $item) {
566+
$value1 = $this->myCachePool->get('item_1', function (ItemInterface $item): string {
567567
$item->tag('foo');
568568

569569
return 'debug';

components/cache.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ generate and return the value::
6565
use Symfony\Contracts\Cache\ItemInterface;
6666

6767
// The callable will only be executed on a cache miss.
68-
$value = $cache->get('my_cache_key', function (ItemInterface $item) {
68+
$value = $cache->get('my_cache_key', function (ItemInterface $item): string {
6969
$item->expiresAfter(3600);
7070

7171
// ... do some HTTP request or heavy computations
@@ -115,7 +115,7 @@ recompute::
115115
use Symfony\Contracts\Cache\ItemInterface;
116116

117117
$beta = 1.0;
118-
$value = $cache->get('my_cache_key', function (ItemInterface $item) {
118+
$value = $cache->get('my_cache_key', function (ItemInterface $item): string {
119119
$item->expiresAfter(3600);
120120
$item->tag(['tag_0', 'tag_1']);
121121

components/cache/cache_invalidation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To attach tags to cached items, you need to use the
2424
:method:`Symfony\\Contracts\\Cache\\ItemInterface::tag` method that is implemented by
2525
cache items::
2626

27-
$item = $cache->get('cache_key', function (ItemInterface $item) {
27+
$item = $cache->get('cache_key', function (ItemInterface $item): string {
2828
// [...]
2929
// add one or more tags
3030
$item->tag('tag_1');

components/cache/cache_items.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The only way to create cache items is via cache pools. When using the Cache
2727
Contracts, they are passed as arguments to the recomputation callback::
2828

2929
// $cache pool object was created before
30-
$productsCount = $cache->get('stats.products_count', function (ItemInterface $item) {
30+
$productsCount = $cache->get('stats.products_count', function (ItemInterface $item): string {
3131
// [...]
3232
});
3333

components/cache/cache_pools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ and deleting cache items using only two methods and a callback::
3838
$cache = new FilesystemAdapter();
3939

4040
// The callable will only be executed on a cache miss.
41-
$value = $cache->get('my_cache_key', function (ItemInterface $item) {
41+
$value = $cache->get('my_cache_key', function (ItemInterface $item): string {
4242
$item->expiresAfter(3600);
4343

4444
// ... do some HTTP request or heavy computations

components/config/definition.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ By changing a string value into an associative array with ``name`` as the key::
737737
->arrayNode('connection')
738738
->beforeNormalization()
739739
->ifString()
740-
->then(function ($v) { return ['name' => $v]; })
740+
->then(function (string $v): array { return ['name' => $v]; })
741741
->end()
742742
->children()
743743
->scalarNode('name')->isRequired()->end()

components/console/events.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dispatched. Listeners receive a
3333
use Symfony\Component\Console\ConsoleEvents;
3434
use Symfony\Component\Console\Event\ConsoleCommandEvent;
3535

36-
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
36+
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event): void {
3737
// gets the input instance
3838
$input = $event->getInput();
3939

@@ -64,7 +64,7 @@ C/C++ standard::
6464
use Symfony\Component\Console\ConsoleEvents;
6565
use Symfony\Component\Console\Event\ConsoleCommandEvent;
6666

67-
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
67+
$dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event): void {
6868
// gets the command to be executed
6969
$command = $event->getCommand();
7070

@@ -97,7 +97,7 @@ Listeners receive a
9797
use Symfony\Component\Console\ConsoleEvents;
9898
use Symfony\Component\Console\Event\ConsoleErrorEvent;
9999

100-
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) {
100+
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event): void {
101101
$output = $event->getOutput();
102102

103103
$command = $event->getCommand();
@@ -131,7 +131,7 @@ Listeners receive a
131131
use Symfony\Component\Console\ConsoleEvents;
132132
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
133133

134-
$dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) {
134+
$dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event): void {
135135
// gets the output
136136
$output = $event->getOutput();
137137

@@ -170,11 +170,11 @@ Listeners receive a
170170
use Symfony\Component\Console\ConsoleEvents;
171171
use Symfony\Component\Console\Event\ConsoleSignalEvent;
172172

173-
$dispatcher->addListener(ConsoleEvents::SIGNAL, function (ConsoleSignalEvent $event) {
174-
173+
$dispatcher->addListener(ConsoleEvents::SIGNAL, function (ConsoleSignalEvent $event): void {
174+
175175
// gets the signal number
176176
$signal = $event->getHandlingSignal();
177-
177+
178178
if (\SIGINT === $signal) {
179179
echo "bye bye!";
180180
}

components/console/helpers/debug_formatter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ using
7878
// ...
7979
$process = new Process(...);
8080

81-
$process->run(function ($type, $buffer) use ($output, $debugFormatter, $process) {
81+
$process->run(function (string $type, string $buffer) use ($output, $debugFormatter, $process): void {
8282
$output->writeln(
8383
$debugFormatter->progress(
8484
spl_object_hash($process),

components/console/helpers/processhelper.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ A custom process callback can be passed as the fourth argument. Refer to the
6969

7070
use Symfony\Component\Process\Process;
7171

72-
$helper->run($output, $process, 'The process failed :(', function ($type, $data) {
72+
$helper->run($output, $process, 'The process failed :(', function (string $type, string $data): void {
7373
if (Process::ERR === $type) {
7474
// ... do something with the stderr output
7575
} else {

0 commit comments

Comments
 (0)