Completed
Pull Request — master (#1958)
by
unknown
65:12
created

OutputCookiePreference::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\App\EventHandlers;
6
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
9
use Symfony\Component\HttpKernel\KernelEvents;
10
11
class OutputCookiePreference implements EventSubscriberInterface {
12
13
	public static function getSubscribedEvents() {
14
		return [
15
			KernelEvents::RESPONSE => [ 'addCookiePreference' ]
16
		];
17
	}
18
19
	public function addCookiePreference( FilterResponseEvent $event ): void {
20
		if ( !$event->isMasterRequest() ) {
21
			return;
22
		}
23
24
		$cookieConsent = $event->getRequest()->cookies->get('cookie_consent', 'unset' );
0 ignored issues
show
introduced by
Single space expected after opening parenthesis
Loading history...
25
		$response = $event->getResponse();
26
27
		$response->setContent(str_replace(
0 ignored issues
show
introduced by
Single space expected after opening parenthesis
Loading history...
28
			'data-application-vars=',
29
			'data-cookie-consent="' . $cookieConsent . '" data-application-vars=',
30
			$response->getContent()
31
		));
0 ignored issues
show
introduced by
Single space expected before closing parenthesis
Loading history...
32
	}
33
}
34