Passed
Push — master ( 489f2e...0cdf36 )
by
unknown
289:17 queued 286:28
created

ShowDonationConfirmationController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 0 38 3
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\App\Controllers\Donation;
6
7
use Silex\Application;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use WMDE\Fundraising\DonationContext\UseCases\GetDonation\GetDonationRequest;
11
use WMDE\Fundraising\Frontend\App\AccessDeniedException;
12
use WMDE\Fundraising\Frontend\App\Routes;
13
use WMDE\Fundraising\Frontend\Factories\FunFunFactory;
14
15
/**
16
 * @license GPL-2.0-or-later
17
 * @author Kai Nissen < [email protected] >
18
 */
19
class ShowDonationConfirmationController {
20
21
	public const SUBMISSION_COOKIE_NAME = 'donation_timestamp';
22
	public const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
23
24
	public function index( Request $request, FunFunFactory $ffFactory ): Response {
25
		$useCase = $ffFactory->newGetDonationUseCase( $request->get( 'accessToken', '' ) );
26
27
		$responseModel = $useCase->showConfirmation( new GetDonationRequest(
28
			(int)$request->get( 'id', '' )
29
		) );
30
31
		if ( !$responseModel->accessIsPermitted() ) {
32
			throw new AccessDeniedException( 'access_denied_donation_confirmation' );
33
		}
34
35
		$ffFactory->getTranslationCollector()->addTranslationFile( $ffFactory->getI18nDirectory() . '/messages/paymentTypes.json' );
36
		$httpResponse = new Response(
37
			$ffFactory->newDonationConfirmationPresenter()->present(
38
				$responseModel->getDonation(),
39
				$responseModel->getUpdateToken(),
0 ignored issues
show
Bug introduced by
It seems like $responseModel->getUpdateToken() can also be of type null; however, parameter $updateToken of WMDE\Fundraising\Fronten...tmlPresenter::present() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
				/** @scrutinizer ignore-type */ $responseModel->getUpdateToken(),
Loading history...
40
				$request->get( 'accessToken', '' ),
41
				array_merge(
42
					Routes::getNamedRouteUrls( $ffFactory->getUrlGenerator() ),
43
					[
44
						'updateDonor' => $ffFactory->getUrlGenerator()->generateAbsoluteUrl(
45
							Routes::UPDATE_DONOR,
46
							[
47
								'accessToken' => $request->get( 'accessToken', '' )
48
							]
49
						)
50
					]
51
				)
52
			)
53
		);
54
55
		if ( !$request->cookies->get( self::SUBMISSION_COOKIE_NAME ) ) {
56
			$cookie = $ffFactory->getCookieBuilder();
57
			$httpResponse->headers->setCookie(
58
				$cookie->newCookie( self::SUBMISSION_COOKIE_NAME, date( self::TIMESTAMP_FORMAT ) )
59
			);
60
		}
61
		return $httpResponse;
62
	}
63
64
}
65