Skip to content

Commit ff8eff5

Browse files
Add property types and return types in a few places
1 parent b5ac484 commit ff8eff5

36 files changed

+236
-235
lines changed

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

cache.rst

Lines changed: 6 additions & 6 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
@@ -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')

configuration/env_var_processors.rst

Lines changed: 1 addition & 1 deletion
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

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
};

deployment/proxies.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ and what headers your reverse proxy uses to send information:
7171
// config/packages/framework.php
7272
use Symfony\Config\FrameworkConfig;
7373
74-
return static function (FrameworkConfig $framework) {
74+
return static function (FrameworkConfig $framework): void {
7575
$framework
7676
// the IP address (or range) of your proxy
7777
->trustedProxies('192.0.0.1,10.0.0.0/8')

doctrine.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ methods:
282282
// ...
283283
284284
+ #[ORM\Column(type: Types::TEXT)]
285-
+ private $description;
285+
+ private string $description;
286286
287287
// getDescription() & setDescription() were also added
288288
}

event_dispatcher.rst

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,17 @@ listen to the same ``kernel.exception`` event::
263263
];
264264
}
265265

266-
public function processException(ExceptionEvent $event)
266+
public function processException(ExceptionEvent $event): void
267267
{
268268
// ...
269269
}
270270

271-
public function logException(ExceptionEvent $event)
271+
public function logException(ExceptionEvent $event): void
272272
{
273273
// ...
274274
}
275275

276-
public function notifyException(ExceptionEvent $event)
276+
public function notifyException(ExceptionEvent $event): void
277277
{
278278
// ...
279279
}
@@ -306,7 +306,7 @@ a "main" request or a "sub request"::
306306

307307
class RequestListener
308308
{
309-
public function onKernelRequest(RequestEvent $event)
309+
public function onKernelRequest(RequestEvent $event): void
310310
{
311311
if (!$event->isMainRequest()) {
312312
// don't do anything if it's not the main request
@@ -357,7 +357,7 @@ name (FQCN) of the corresponding event class::
357357
];
358358
}
359359

360-
public function onKernelRequest(RequestEvent $event)
360+
public function onKernelRequest(RequestEvent $event): void
361361
{
362362
// ...
363363
}
@@ -381,7 +381,7 @@ compiler pass ``AddEventAliasesPass``::
381381

382382
class Kernel extends BaseKernel
383383
{
384-
protected function build(ContainerBuilder $container)
384+
protected function build(ContainerBuilder $container): void
385385
{
386386
$container->addCompilerPass(new AddEventAliasesPass([
387387
MyCustomEvent::class => 'my_custom_event',
@@ -519,11 +519,12 @@ A controller that implements this interface looks like this::
519519

520520
use App\Controller\TokenAuthenticatedController;
521521
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
522+
use Symfony\Component\HttpFoundation\Response;
522523

523524
class FooController extends AbstractController implements TokenAuthenticatedController
524525
{
525526
// An action that needs authentication
526-
public function bar()
527+
public function bar(): Response
527528
{
528529
// ...
529530
}
@@ -548,11 +549,11 @@ event subscribers, you can learn more about them at :doc:`/event_dispatcher`::
548549
class TokenSubscriber implements EventSubscriberInterface
549550
{
550551
public function __construct(
551-
private $tokens
552+
private array $tokens
552553
) {
553554
}
554555

555-
public function onKernelController(ControllerEvent $event)
556+
public function onKernelController(ControllerEvent $event): void
556557
{
557558
$controller = $event->getController();
558559

@@ -570,7 +571,7 @@ event subscribers, you can learn more about them at :doc:`/event_dispatcher`::
570571
}
571572
}
572573

573-
public static function getSubscribedEvents()
574+
public static function getSubscribedEvents(): array
574575
{
575576
return [
576577
KernelEvents::CONTROLLER => 'onKernelController',
@@ -609,7 +610,7 @@ For example, take the ``TokenSubscriber`` from the previous example and first
609610
record the authentication token inside the request attributes. This will
610611
serve as a basic flag that this request underwent token authentication::
611612

612-
public function onKernelController(ControllerEvent $event)
613+
public function onKernelController(ControllerEvent $event): void
613614
{
614615
// ...
615616

@@ -631,7 +632,7 @@ header on the response if it's found::
631632
// add the new use statement at the top of your file
632633
use Symfony\Component\HttpKernel\Event\ResponseEvent;
633634

634-
public function onKernelResponse(ResponseEvent $event)
635+
public function onKernelResponse(ResponseEvent $event): void
635636
{
636637
// check to see if onKernelController marked this as a token "auth'ed" request
637638
if (!$token = $event->getRequest()->attributes->get('auth_token')) {
@@ -645,7 +646,7 @@ header on the response if it's found::
645646
$response->headers->set('X-CONTENT-HASH', $hash);
646647
}
647648

648-
public static function getSubscribedEvents()
649+
public static function getSubscribedEvents(): array
649650
{
650651
return [
651652
KernelEvents::CONTROLLER => 'onKernelController',
@@ -673,7 +674,7 @@ end of the method::
673674
{
674675
// ...
675676

676-
public function send($subject, $message)
677+
public function send(string $subject, string $message): mixed
677678
{
678679
// dispatch an event before the method
679680
$event = new BeforeSendMailEvent($subject, $message);
@@ -711,27 +712,27 @@ this::
711712
class BeforeSendMailEvent extends Event
712713
{
713714
public function __construct(
714-
private $subject,
715-
private $message,
715+
private string $subject,
716+
private string $message,
716717
) {
717718
}
718719

719-
public function getSubject()
720+
public function getSubject(): string
720721
{
721722
return $this->subject;
722723
}
723724

724-
public function setSubject($subject)
725+
public function setSubject(string $subject): string
725726
{
726727
$this->subject = $subject;
727728
}
728729

729-
public function getMessage()
730+
public function getMessage(): string
730731
{
731732
return $this->message;
732733
}
733734

734-
public function setMessage($message)
735+
public function setMessage(string $message)
735736
{
736737
$this->message = $message;
737738
}
@@ -747,16 +748,16 @@ And the ``AfterSendMailEvent`` even like this::
747748
class AfterSendMailEvent extends Event
748749
{
749750
public function __construct(
750-
private $returnValue,
751+
private mixed $returnValue,
751752
) {
752753
}
753754

754-
public function getReturnValue()
755+
public function getReturnValue(): mixed
755756
{
756757
return $this->returnValue;
757758
}
758759

759-
public function setReturnValue($returnValue)
760+
public function setReturnValue(mixed $returnValue)
760761
{
761762
$this->returnValue = $returnValue;
762763
}
@@ -776,15 +777,15 @@ could listen to the ``mailer.post_send`` event and change the method's return va
776777

777778
class MailPostSendSubscriber implements EventSubscriberInterface
778779
{
779-
public function onMailerPostSend(AfterSendMailEvent $event)
780+
public function onMailerPostSend(AfterSendMailEvent $event): void
780781
{
781782
$returnValue = $event->getReturnValue();
782783
// modify the original $returnValue value
783784

784785
$event->setReturnValue($returnValue);
785786
}
786787

787-
public static function getSubscribedEvents()
788+
public static function getSubscribedEvents(): array
788789
{
789790
return [
790791
'mailer.post_send' => 'onMailerPostSend',

frontend/custom_version_strategy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ the :ref:`version_strategy <reference-assets-version-strategy>` option:
178178
use App\Asset\VersionStrategy\GulpBusterVersionStrategy;
179179
use Symfony\Config\FrameworkConfig;
180180
181-
return static function (FrameworkConfig $framework) {
181+
return static function (FrameworkConfig $framework): void {
182182
// ...
183183
$framework->assets()
184184
->versionStrategy(GulpBusterVersionStrategy::class)

0 commit comments

Comments
 (0)