Passed
Pull Request — master (#1936)
by
unknown
63:36
created

BucketLoggingConsentHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onKernelRequest() 0 3 1
A __construct() 0 2 1
A getSubscribedEvents() 0 3 1
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\GetResponseEvent;
9
use Symfony\Component\HttpKernel\KernelEvents;
10
use WMDE\Fundraising\Frontend\Infrastructure\EventHandling\DomainEventHandler\BucketLoggingHandler;
11
12
/**
13
 * Set consent state of BucketLoggingHandler on every request, depending on the consent cookie value.
14
 *
15
 * This will prevent the BucketLoggingHandler from logging the buckets when no consent was given.
16
 */
17
class BucketLoggingConsentHandler implements EventSubscriberInterface {
18
19
	private BucketLoggingHandler $bucketLoggingHandler;
20
21
	public static function getSubscribedEvents() {
22
		return [
23
			KernelEvents::REQUEST => 'onKernelRequest'
24
		];
25
	}
26
27
	public function __construct( BucketLoggingHandler $bucketLoggingHandler ) {
28
		$this->bucketLoggingHandler = $bucketLoggingHandler;
29
	}
30
31
	public function onKernelRequest( GetResponseEvent $event ): void {
32
		$this->bucketLoggingHandler->setConsentGiven(
33
			$event->getRequest()->cookies->get( 'cookie_consent' ) === 'yes'
34
		);
35
	}
36
}
37