Skip to content

Commit d3bf55d

Browse files
minor symfony#61112 [HttpKernel][Security] Refactor: use getAttributes with argument (santysisi)
This PR was merged into the 7.4 branch. Discussion ---------- [HttpKernel][Security] Refactor: use `getAttributes` with argument | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | no | License | MIT Refactored code to consistently use `$event->getAttributes($className)` instead of accessing the full array. This simplifies attribute retrieval and improves readability. [Reference](symfony#60395 (comment)) Commits ------- 6769c9a [HttpKernel][Security] Refactor: use `getAttributes` with argument
2 parents dfb3d28 + 6769c9a commit d3bf55d

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
5151
{
5252
$request = $event->getRequest();
5353

54-
if (!\is_array($attributes = $request->attributes->get('_cache') ?? $event->getAttributes()[Cache::class] ?? null)) {
54+
if (!$attributes = $request->attributes->get('_cache') ?? $event->getAttributes(Cache::class)) {
5555
return;
5656
}
5757

src/Symfony/Component/Security/Http/EventListener/IsCsrfTokenValidAttributeListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function __construct(
3535

3636
public function onKernelControllerArguments(ControllerArgumentsEvent $event): void
3737
{
38-
/** @var IsCsrfTokenValid[] $attributes */
39-
if (!\is_array($attributes = $event->getAttributes()[IsCsrfTokenValid::class] ?? null)) {
38+
if (!$attributes = $event->getAttributes(IsCsrfTokenValid::class)) {
4039
return;
4140
}
4241

src/Symfony/Component/Security/Http/EventListener/IsGrantedAttributeListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public function __construct(
3939

4040
public function onKernelControllerArguments(ControllerArgumentsEvent $event): void
4141
{
42-
/** @var IsGranted[] $attributes */
43-
if (!\is_array($attributes = $event->getAttributes()[IsGranted::class] ?? null)) {
42+
if (!$attributes = $event->getAttributes(IsGranted::class)) {
4443
return;
4544
}
4645

0 commit comments

Comments
 (0)