Skip to content

Commit e6c771d

Browse files
committed
fix warnings
1 parent 472d25b commit e6c771d

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/EventSubscriber/FlashMessageSubscriber.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
66
use Symfony\Component\HttpFoundation\RequestStack;
7+
use Symfony\Component\HttpFoundation\Session\FlashBagAwareSessionInterface;
78
use Symfony\Component\HttpKernel\Event\ResponseEvent;
89
use Symfony\Component\HttpKernel\HttpKernelInterface;
910
use Symfony\Component\HttpKernel\KernelEvents;
@@ -17,20 +18,20 @@ class FlashMessageSubscriber implements EventSubscriberInterface
1718
public function __construct(RequestStack $requestStack, TranslatorInterface $translator)
1819
{
1920
$this->requestStack = $requestStack;
20-
$this->translator = $translator;
21+
$this->translator = $translator;
2122
}
2223

2324
public static function getSubscribedEvents(): array
2425
{
2526
return [
2627
// we want that to run early (before the Session->Cookie transformation)
27-
KernelEvents::RESPONSE => ['onKernelResponse', 10]
28+
KernelEvents::RESPONSE => ['onKernelResponse', 10],
2829
];
2930
}
3031

3132
public function onKernelResponse(ResponseEvent $event)
3233
{
33-
// @todo remove this when we drop support for SF4, see https://github.com/symfony/http-kernel/blob/7.1/CHANGELOG.md#53
34+
// @todo remove this when we drop support for SF4, see https://github.com/symfony/http-kernel/blob/7.1/CHANGELOG.md#53
3435
if (defined('HttpKernelInterface::MASTER_REQUEST') && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
3536
return;
3637
}
@@ -57,9 +58,11 @@ public function onKernelResponse(ResponseEvent $event)
5758
return;
5859
}
5960

61+
assert($session instanceof FlashBagAwareSessionInterface);
62+
6063
$flashBag = $session->getFlashBag();
6164
// Use peekAll because we want to keep existing messages in the bag
62-
$flashes = $flashBag->peekAll();
65+
$flashes = $flashBag->peekAll();
6366

6467
if (empty($flashes)) {
6568
return;
@@ -68,30 +71,30 @@ public function onKernelResponse(ResponseEvent $event)
6871
$titleKeys = [
6972
'success' => 'successes',
7073
'warning' => 'warnings',
71-
'error' => 'errors',
72-
'info' => 'info'
74+
'error' => 'errors',
75+
'info' => 'info',
7376
];
7477

7578
$existingTitles = array_keys(
7679
array_filter(
7780
$flashes,
78-
fn(string $key) => strpos($key, 'title-') === 0,
81+
fn (string $key) => 0 === strpos($key, 'title-'),
7982
ARRAY_FILTER_USE_KEY
8083
)
8184
);
8285

83-
foreach(array_keys($flashes) as $type) {
86+
foreach (array_keys($flashes) as $type) {
8487
// $type is not a title and its corresponding title doesn't already exist
8588
if (
86-
strpos($type, 'title-') === false &&
87-
!in_array('title-' . $type, $existingTitles) &&
88-
array_key_exists($type, $titleKeys)
89+
false === strpos($type, 'title-')
90+
&& !in_array('title-'.$type, $existingTitles)
91+
&& array_key_exists($type, $titleKeys)
8992
) {
9093
$flashBag->add(
91-
'title-' . $type,
92-
$this->translator->trans('notes.' . $titleKeys[$type] . '.default_title', [], 'w3c_website_templates_bundle')
94+
'title-'.$type,
95+
$this->translator->trans('notes.'.$titleKeys[$type].'.default_title', [], 'w3c_website_templates_bundle')
9396
);
94-
$existingTitles[] = 'title-' . $type;
97+
$existingTitles[] = 'title-'.$type;
9598
}
9699
}
97100
}

0 commit comments

Comments
 (0)