Passed
Push — master ( 445a0d...24c58d )
by Gabriel
01:40 queued 13s
created

ChoiceFactory::getSkinDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Factories;
6
7
use Symfony\Component\HttpFoundation\RedirectResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use WMDE\Euro\Euro;
10
use WMDE\Fundraising\Frontend\BucketTesting\FeatureToggle;
11
use WMDE\Fundraising\Frontend\Infrastructure\UrlGenerator;
12
13
/**
14
 * Factory for generating classes whose implementations differ due to A/B testing.
15
 *
16
 * @license GNU GPL v2+
17
 */
18
class ChoiceFactory {
19
20 100
	private $featureToggle;
21 100
22 100
	public function __construct( FeatureToggle $featureToggle ) {
23
		$this->featureToggle = $featureToggle;
24 14
	}
25
26 14
	public function getUseOfFundsResponse( FunFunFactory $factory ): \Closure {
27 10
		if ( $this->featureToggle->featureIsActive( 'campaigns.skins.laika' ) ) {
28
			$factory->getTranslationCollector()->addTranslationFile( $factory->getI18nDirectory() . '/messages/useOfFundsMessages.json' );
29 4
			$template = $factory->getLayoutTemplate( 'Funds_Usage.html.twig', [
30 4
				'use_of_funds_content' => $factory->getApplicationOfFundsContent(),
31
				'use_of_funds_messages' => $factory->getApplicationOfFundsMessages()
32
			] );
33
			return function() use ( $template )  {
34
				return $template->render( [] );
35
			};
36
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.skins.test' ) ) {
37 100
			// we don't care what happens in test
38 100
			return function() {
39 19
				return 'Test rendering: Use of funds';
40 81
			};
41 1
		}
42 80
		throw new UnknownChoiceDefinition( 'Use of funds configuration failure.' );
43 80
	}
44
45
	public function getMembershipCallToActionTemplate(): string {
46
		if ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.regular' ) ) {
47
			return 'partials/donation_confirmation/feature_toggle/call_to_action_regular.html.twig';
48 15
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.video' ) ) {
49 15
			return 'partials/donation_confirmation/feature_toggle/call_to_action_video.html.twig';
50 15
		}
51
		throw new UnknownChoiceDefinition( 'Membership Call to Action Template configuration failure.' );
52
	}
53
54
	public function getAmountOption(): array {
55
		if ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300_0' ) ) {
56
			return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] );
57 1
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300' ) ) {
58 1
			return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] );
59
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to100' ) ) {
60 1
			return $this->getAmountOptionInEuros( [ 500, 1000, 1500, 2000, 3000, 5000, 7500, 10000 ] );
61 1
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.15to250' ) ) {
62
			return $this->getAmountOptionInEuros( [ 1500, 2000, 2500, 3000, 5000, 7500, 10000, 25000 ] );
63
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.30to250' ) ) {
64
			return $this->getAmountOptionInEuros( [ 3000, 4000, 5000, 7500, 10000, 15000, 20000, 25000 ] );
65
		} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.50to500' ) ) {
66
			return $this->getAmountOptionInEuros( [ 5000, 10000, 15000, 20000, 25000, 30000, 50000 ] );
67
		}
68
		throw new UnknownChoiceDefinition( 'Amount option selection configuration failure.' );
69
	}
70
71
	public function getAmountOptionInEuros( array $amountOption ): array {
72
		return array_map( function ( int $amount ) {
73
			return Euro::newFromCents( $amount );
74 100
		}, $amountOption );
75
	}
76
}