Completed
Push — master ( f48979...1564bf )
by wiese
195:26 queued 130:26
created

ShowApplicationConfirmationUseCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 5
lcom 1
cbo 6
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B showConfirmation() 0 23 4
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowApplicationConfirmation;
6
7
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer;
8
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationTokenFetcher;
9
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationPurgedException;
10
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\ApplicationRepository;
11
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Repositories\GetMembershipApplicationException;
12
13
/**
14
 * @license GNU GPL v2+
15
 * @author Kai Nissen < [email protected] >
16
 */
17
class ShowApplicationConfirmationUseCase {
18
19
	private $presenter;
20
	private $authorizer;
21
	private $repository;
22
	private $tokenFetcher;
23
24
	public function __construct( ShowApplicationConfirmationPresenter $presenter, ApplicationAuthorizer $authorizer,
25
		ApplicationRepository $repository, ApplicationTokenFetcher $tokenFetcher ) {
26
		$this->presenter = $presenter;
27
		$this->authorizer = $authorizer;
28
		$this->repository = $repository;
29
		$this->tokenFetcher = $tokenFetcher;
30
	}
31
32
	public function showConfirmation( ShowAppConfirmationRequest $request ): void {
33
		if ( !$this->authorizer->canAccessApplication( $request->getApplicationId() ) ) {
34
			$this->presenter->presentAccessViolation();
35
			return;
36
		}
37
38
		try {
39
			$application = $this->repository->getApplicationById( $request->getApplicationId() );
40
		}
41
		catch ( ApplicationPurgedException $ex ) {
42
			$this->presenter->presentApplicationWasPurged();
43
			return;
44
		}
45
		catch ( GetMembershipApplicationException $ex ) {
46
			$this->presenter->presentTechnicalError( 'A database error occurred' );
47
			return;
48
		}
49
50
		$this->presenter->presentConfirmation(
51
			$application, // TODO: use DTO instead of Entity (currently violates the architecture)
52
			$this->tokenFetcher->getTokens( $request->getApplicationId() )->getUpdateToken()
53
		);
54
	}
55
56
}