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

OutputCookiePreference   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 3 1
A addCookiePreference() 0 12 2
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