Completed
Pull Request — master (#971)
by wiese
94:17 queued 29:21
created

SofortToggleServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 21
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register() 0 2 1
A boot() 0 7 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Presentation;
6
7
use Pimple\Container;
8
use Pimple\ServiceProviderInterface;
9
use Silex\Api\BootableProviderInterface;
10
use Silex\Application;
11
use Symfony\Component\HttpFoundation\Request;
12
13
class SofortToggleServiceProvider implements ServiceProviderInterface, BootableProviderInterface {
14
15
	private const QUERY_PARAM_NAME = 'pmt';
16
17
	private $paymentTypesSettings;
18
19
	public function __construct( PaymentTypesSettings $paymentTypesSettings ) {
20
		$this->paymentTypesSettings = $paymentTypesSettings;
21
	}
22
23
	public function register( Container $app ): void {
24
	}
25
26
	public function boot( Application $app ): void {
27
		$app->before( function( Request $request ): void {
28
			if ( $request->query->get( self::QUERY_PARAM_NAME ) === '0' ) {
29
				$this->paymentTypesSettings->updateSetting( 'SUB', PaymentTypesSettings::PURPOSE_DONATION, false );
30
			}
31
		}, Application::EARLY_EVENT );
32
	}
33
}
34