@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Fundraising\Frontend\DonationContext\Domain\Model; |
| 6 | 6 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @throws \InvalidArgumentException |
| 57 | 57 | */ |
| 58 | - public function __construct( ?int $id, string $status, ?Donor $donor, DonationPayment $payment, |
|
| 59 | - bool $optsIntoNewsletter, DonationTrackingInfo $trackingInfo, DonationComment $comment = null ) { |
|
| 58 | + public function __construct(? int $id, string $status, ? Donor $donor, DonationPayment $payment, |
|
| 59 | + bool $optsIntoNewsletter, DonationTrackingInfo $trackingInfo, DonationComment $comment = null) { |
|
| 60 | 60 | |
| 61 | 61 | $this->id = $id; |
| 62 | - $this->setStatus( $status ); |
|
| 62 | + $this->setStatus($status); |
|
| 63 | 63 | $this->donor = $donor; |
| 64 | 64 | $this->payment = $payment; |
| 65 | 65 | $this->optsIntoNewsletter = $optsIntoNewsletter; |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | $this->comment = $comment; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - private function setStatus( string $status ) { |
|
| 71 | - if ( !$this->isValidStatus( $status ) ) { |
|
| 72 | - throw new \InvalidArgumentException( 'Invalid donation status' ); |
|
| 70 | + private function setStatus(string $status) { |
|
| 71 | + if (!$this->isValidStatus($status)) { |
|
| 72 | + throw new \InvalidArgumentException('Invalid donation status'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $this->status = $status; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - private function isValidStatus( string $status ): bool { |
|
| 78 | + private function isValidStatus(string $status): bool { |
|
| 79 | 79 | return in_array( |
| 80 | 80 | $status, |
| 81 | 81 | [ |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | ); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function getId(): ?int { |
|
| 92 | + public function getId(): ? int { |
|
| 93 | 93 | return $this->id; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * @param int $id |
| 98 | 98 | * @throws \RuntimeException |
| 99 | 99 | */ |
| 100 | - public function assignId( int $id ) { |
|
| 101 | - if ( $this->id !== null && $this->id !== $id ) { |
|
| 102 | - throw new \RuntimeException( 'Id cannot be changed after initial assignment' ); |
|
| 100 | + public function assignId(int $id) { |
|
| 101 | + if ($this->id !== null && $this->id !== $id) { |
|
| 102 | + throw new \RuntimeException('Id cannot be changed after initial assignment'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $this->id = $id; |
@@ -129,20 +129,20 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * Returns the Donor or null for anonymous donations. |
| 131 | 131 | */ |
| 132 | - public function getDonor(): ?Donor { |
|
| 132 | + public function getDonor(): ? Donor { |
|
| 133 | 133 | return $this->donor; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * Returns the DonationComment or null for when there is none. |
| 138 | 138 | */ |
| 139 | - public function getComment(): ?DonationComment { |
|
| 139 | + public function getComment(): ? DonationComment { |
|
| 140 | 140 | return $this->comment; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - public function addComment( DonationComment $comment ) { |
|
| 144 | - if ( $this->hasComment() ) { |
|
| 145 | - throw new RuntimeException( 'Can only add a single comment to a donation' ); |
|
| 143 | + public function addComment(DonationComment $comment) { |
|
| 144 | + if ($this->hasComment()) { |
|
| 145 | + throw new RuntimeException('Can only add a single comment to a donation'); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $this->comment = $comment; |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | * @throws RuntimeException |
| 165 | 165 | */ |
| 166 | 166 | public function cancel() { |
| 167 | - if ( $this->getPaymentType() !== PaymentType::DIRECT_DEBIT ) { |
|
| 168 | - throw new RuntimeException( 'Can only cancel direct debit' ); |
|
| 167 | + if ($this->getPaymentType() !== PaymentType::DIRECT_DEBIT) { |
|
| 168 | + throw new RuntimeException('Can only cancel direct debit'); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if ( !$this->statusIsCancellable() ) { |
|
| 172 | - throw new RuntimeException( 'Can only cancel new donations' ); |
|
| 171 | + if (!$this->statusIsCancellable()) { |
|
| 172 | + throw new RuntimeException('Can only cancel new donations'); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $this->status = self::STATUS_CANCELLED; |
@@ -179,15 +179,15 @@ discard block |
||
| 179 | 179 | * @throws RuntimeException |
| 180 | 180 | */ |
| 181 | 181 | public function confirmBooked() { |
| 182 | - if ( !$this->hasExternalPayment() ) { |
|
| 183 | - throw new RuntimeException( 'Only external payments can be confirmed as booked' ); |
|
| 182 | + if (!$this->hasExternalPayment()) { |
|
| 183 | + throw new RuntimeException('Only external payments can be confirmed as booked'); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - if ( !$this->statusAllowsForBooking() ) { |
|
| 187 | - throw new RuntimeException( 'Only incomplete donations can be confirmed as booked' ); |
|
| 186 | + if (!$this->statusAllowsForBooking()) { |
|
| 187 | + throw new RuntimeException('Only incomplete donations can be confirmed as booked'); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if ( $this->hasComment() && ( $this->needsModeration() || $this->isCancelled() ) ) { |
|
| 190 | + if ($this->hasComment() && ($this->needsModeration() || $this->isCancelled())) { |
|
| 191 | 191 | $this->makeCommentPrivate(); |
| 192 | 192 | } |
| 193 | 193 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | public function notifyOfPolicyValidationFailure() { |
| 218 | - if ( !$this->hasExternalPayment() ) { |
|
| 218 | + if (!$this->hasExternalPayment()) { |
|
| 219 | 219 | $this->markForModeration(); |
| 220 | 220 | } |
| 221 | 221 | } |
@@ -232,14 +232,14 @@ discard block |
||
| 232 | 232 | * @param PayPalData $payPalData |
| 233 | 233 | * @throws RuntimeException |
| 234 | 234 | */ |
| 235 | - public function addPayPalData( PayPalData $payPalData ) { |
|
| 235 | + public function addPayPalData(PayPalData $payPalData) { |
|
| 236 | 236 | $paymentMethod = $this->payment->getPaymentMethod(); |
| 237 | 237 | |
| 238 | - if ( !( $paymentMethod instanceof PayPalPayment ) ) { |
|
| 239 | - throw new RuntimeException( 'Cannot set PayPal data on a non PayPal payment' ); |
|
| 238 | + if (!($paymentMethod instanceof PayPalPayment)) { |
|
| 239 | + throw new RuntimeException('Cannot set PayPal data on a non PayPal payment'); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - $paymentMethod->addPayPalData( $payPalData ); |
|
| 242 | + $paymentMethod->addPayPalData($payPalData); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -247,14 +247,14 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @throws RuntimeException |
| 249 | 249 | */ |
| 250 | - public function addCreditCardData( CreditCardTransactionData $creditCardData ) { |
|
| 250 | + public function addCreditCardData(CreditCardTransactionData $creditCardData) { |
|
| 251 | 251 | $paymentMethod = $this->payment->getPaymentMethod(); |
| 252 | 252 | |
| 253 | - if ( !( $paymentMethod instanceof CreditCardPayment ) ) { |
|
| 254 | - throw new RuntimeException( 'Cannot set credit card transaction data on a non credit card payment' ); |
|
| 253 | + if (!($paymentMethod instanceof CreditCardPayment)) { |
|
| 254 | + throw new RuntimeException('Cannot set credit card transaction data on a non credit card payment'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $paymentMethod->addCreditCardTransactionData( $creditCardData ); |
|
| 257 | + $paymentMethod->addCreditCardTransactionData($creditCardData); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | private function statusIsCancellable(): bool { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | public function hasExternalPayment(): bool { |
| 265 | - return in_array( $this->getPaymentType(), [ PaymentType::PAYPAL, PaymentType::CREDIT_CARD ] ); |
|
| 265 | + return in_array($this->getPaymentType(), [PaymentType::PAYPAL, PaymentType::CREDIT_CARD]); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | private function isIncomplete(): bool { |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Fundraising\Frontend\DonationContext\UseCases\AddComment; |
| 6 | 6 | |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | private $textPolicyValidator; |
| 24 | 24 | private $commentValidator; |
| 25 | 25 | |
| 26 | - public function __construct( DonationRepository $repository, DonationAuthorizer $authorizationService, |
|
| 27 | - TextPolicyValidator $textPolicyValidator, AddCommentValidator $commentValidator ) { |
|
| 26 | + public function __construct(DonationRepository $repository, DonationAuthorizer $authorizationService, |
|
| 27 | + TextPolicyValidator $textPolicyValidator, AddCommentValidator $commentValidator) { |
|
| 28 | 28 | |
| 29 | 29 | $this->donationRepository = $repository; |
| 30 | 30 | $this->authorizationService = $authorizationService; |
@@ -32,72 +32,72 @@ discard block |
||
| 32 | 32 | $this->commentValidator = $commentValidator; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function addComment( AddCommentRequest $addCommentRequest ): AddCommentResponse { |
|
| 36 | - if ( !$this->requestIsAllowed( $addCommentRequest ) ) { |
|
| 37 | - return AddCommentResponse::newFailureResponse( 'comment_failure_access_denied' ); |
|
| 35 | + public function addComment(AddCommentRequest $addCommentRequest): AddCommentResponse { |
|
| 36 | + if (!$this->requestIsAllowed($addCommentRequest)) { |
|
| 37 | + return AddCommentResponse::newFailureResponse('comment_failure_access_denied'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $validationResult = $this->commentValidator->validate( $addCommentRequest ); |
|
| 41 | - if ( !$validationResult->isSuccessful() ) { |
|
| 42 | - return AddCommentResponse::newFailureResponse( $validationResult->getFirstViolation() ); |
|
| 40 | + $validationResult = $this->commentValidator->validate($addCommentRequest); |
|
| 41 | + if (!$validationResult->isSuccessful()) { |
|
| 42 | + return AddCommentResponse::newFailureResponse($validationResult->getFirstViolation()); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | try { |
| 46 | - $donation = $this->donationRepository->getDonationById( $addCommentRequest->getDonationId() ); |
|
| 46 | + $donation = $this->donationRepository->getDonationById($addCommentRequest->getDonationId()); |
|
| 47 | 47 | } |
| 48 | - catch ( GetDonationException $ex ) { |
|
| 49 | - return AddCommentResponse::newFailureResponse( 'comment_failure_donation_error' ); |
|
| 48 | + catch (GetDonationException $ex) { |
|
| 49 | + return AddCommentResponse::newFailureResponse('comment_failure_donation_error'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if ( $donation === null ) { |
|
| 53 | - return AddCommentResponse::newFailureResponse( 'comment_failure_donation_not_found' ); |
|
| 52 | + if ($donation === null) { |
|
| 53 | + return AddCommentResponse::newFailureResponse('comment_failure_donation_not_found'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - if ( $donation->getComment() !== null ) { |
|
| 57 | - return AddCommentResponse::newFailureResponse( 'comment_failure_donation_has_comment' ); |
|
| 56 | + if ($donation->getComment() !== null) { |
|
| 57 | + return AddCommentResponse::newFailureResponse('comment_failure_donation_has_comment'); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $successMessage = 'comment_success_ok'; |
| 61 | - if ( $donation->needsModeration() ) { |
|
| 61 | + if ($donation->needsModeration()) { |
|
| 62 | 62 | $successMessage = 'comment_success_needs_moderation'; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $donation->addComment( $this->newCommentFromRequest( $addCommentRequest ) ); |
|
| 65 | + $donation->addComment($this->newCommentFromRequest($addCommentRequest)); |
|
| 66 | 66 | |
| 67 | - if ( !$this->commentTextPassesValidation( $addCommentRequest->getCommentText() ) ) { |
|
| 67 | + if (!$this->commentTextPassesValidation($addCommentRequest->getCommentText())) { |
|
| 68 | 68 | $donation->notifyOfCommentValidationFailure(); |
| 69 | 69 | $successMessage = 'comment_success_needs_moderation'; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | try { |
| 73 | - $this->donationRepository->storeDonation( $donation ); |
|
| 73 | + $this->donationRepository->storeDonation($donation); |
|
| 74 | 74 | } |
| 75 | - catch ( StoreDonationException $ex ) { |
|
| 76 | - return AddCommentResponse::newFailureResponse( 'comment_failure_save_error' ); |
|
| 75 | + catch (StoreDonationException $ex) { |
|
| 76 | + return AddCommentResponse::newFailureResponse('comment_failure_save_error'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - return AddCommentResponse::newSuccessResponse( $successMessage ); |
|
| 79 | + return AddCommentResponse::newSuccessResponse($successMessage); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - private function requestIsAllowed( AddCommentRequest $addCommentRequest ): bool { |
|
| 83 | - return $this->authorizationService->userCanModifyDonation( $addCommentRequest->getDonationId() ); |
|
| 82 | + private function requestIsAllowed(AddCommentRequest $addCommentRequest): bool { |
|
| 83 | + return $this->authorizationService->userCanModifyDonation($addCommentRequest->getDonationId()); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - private function newCommentFromRequest( AddCommentRequest $request ): DonationComment { |
|
| 86 | + private function newCommentFromRequest(AddCommentRequest $request): DonationComment { |
|
| 87 | 87 | return new DonationComment( |
| 88 | 88 | $request->getCommentText(), |
| 89 | - $this->commentCanBePublic( $request ), |
|
| 89 | + $this->commentCanBePublic($request), |
|
| 90 | 90 | $request->getAuthorDisplayName() |
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - private function commentCanBePublic( AddCommentRequest $request ): bool { |
|
| 94 | + private function commentCanBePublic(AddCommentRequest $request): bool { |
|
| 95 | 95 | return $request->isPublic() |
| 96 | - && $this->commentTextPassesValidation( $request->getCommentText() ); |
|
| 96 | + && $this->commentTextPassesValidation($request->getCommentText()); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - private function commentTextPassesValidation( string $text ): bool { |
|
| 100 | - return $this->textPolicyValidator->textIsHarmless( $text ); |
|
| 99 | + private function commentTextPassesValidation(string $text): bool { |
|
| 100 | + return $this->textPolicyValidator->textIsHarmless($text); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Fundraising\Frontend\DonationContext\UseCases\AddDonation; |
| 6 | 6 | |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | private $transferCodeGenerator; |
| 38 | 38 | private $tokenFetcher; |
| 39 | 39 | |
| 40 | - public function __construct( DonationRepository $donationRepository, AddDonationValidator $donationValidator, |
|
| 40 | + public function __construct(DonationRepository $donationRepository, AddDonationValidator $donationValidator, |
|
| 41 | 41 | AddDonationPolicyValidator $policyValidator, ReferrerGeneralizer $referrerGeneralizer, |
| 42 | 42 | DonationConfirmationMailer $mailer, TransferCodeGenerator $transferCodeGenerator, |
| 43 | - DonationTokenFetcher $tokenFetcher ) { |
|
| 43 | + DonationTokenFetcher $tokenFetcher) { |
|
| 44 | 44 | $this->donationRepository = $donationRepository; |
| 45 | 45 | $this->donationValidator = $donationValidator; |
| 46 | 46 | $this->policyValidator = $policyValidator; |
@@ -51,31 +51,31 @@ discard block |
||
| 51 | 51 | $this->tokenFetcher = $tokenFetcher; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function addDonation( AddDonationRequest $donationRequest ): AddDonationResponse { |
|
| 55 | - $validationResult = $this->donationValidator->validate( $donationRequest ); |
|
| 54 | + public function addDonation(AddDonationRequest $donationRequest): AddDonationResponse { |
|
| 55 | + $validationResult = $this->donationValidator->validate($donationRequest); |
|
| 56 | 56 | |
| 57 | - if ( $validationResult->hasViolations() ) { |
|
| 58 | - return AddDonationResponse::newFailureResponse( $validationResult->getViolations() ); |
|
| 57 | + if ($validationResult->hasViolations()) { |
|
| 58 | + return AddDonationResponse::newFailureResponse($validationResult->getViolations()); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $donation = $this->newDonationFromRequest( $donationRequest ); |
|
| 61 | + $donation = $this->newDonationFromRequest($donationRequest); |
|
| 62 | 62 | |
| 63 | - if ( $this->policyValidator->needsModeration( $donationRequest ) ) { |
|
| 63 | + if ($this->policyValidator->needsModeration($donationRequest)) { |
|
| 64 | 64 | $donation->notifyOfPolicyValidationFailure(); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( $this->policyValidator->isAutoDeleted( $donationRequest ) ) { |
|
| 67 | + if ($this->policyValidator->isAutoDeleted($donationRequest)) { |
|
| 68 | 68 | $donation->markAsDeleted(); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // TODO: handle exceptions |
| 72 | - $this->donationRepository->storeDonation( $donation ); |
|
| 72 | + $this->donationRepository->storeDonation($donation); |
|
| 73 | 73 | |
| 74 | 74 | // TODO: handle exceptions |
| 75 | - $tokens = $this->tokenFetcher->getTokens( $donation->getId() ); |
|
| 75 | + $tokens = $this->tokenFetcher->getTokens($donation->getId()); |
|
| 76 | 76 | |
| 77 | 77 | // TODO: handle exceptions |
| 78 | - $this->sendDonationConfirmationEmail( $donation ); |
|
| 78 | + $this->sendDonationConfirmationEmail($donation); |
|
| 79 | 79 | |
| 80 | 80 | return AddDonationResponse::newSuccessResponse( |
| 81 | 81 | $donation, |
@@ -84,97 +84,97 @@ discard block |
||
| 84 | 84 | ); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - private function newDonationFromRequest( AddDonationRequest $donationRequest ): Donation { |
|
| 87 | + private function newDonationFromRequest(AddDonationRequest $donationRequest): Donation { |
|
| 88 | 88 | return new Donation( |
| 89 | 89 | null, |
| 90 | - $this->getInitialDonationStatus( $donationRequest->getPaymentType() ), |
|
| 91 | - $this->getPersonalInfoFromRequest( $donationRequest ), |
|
| 92 | - $this->getPaymentFromRequest( $donationRequest ), |
|
| 90 | + $this->getInitialDonationStatus($donationRequest->getPaymentType()), |
|
| 91 | + $this->getPersonalInfoFromRequest($donationRequest), |
|
| 92 | + $this->getPaymentFromRequest($donationRequest), |
|
| 93 | 93 | $donationRequest->getOptIn() === '1', |
| 94 | - $this->newTrackingInfoFromRequest( $donationRequest ) |
|
| 94 | + $this->newTrackingInfoFromRequest($donationRequest) |
|
| 95 | 95 | ); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - private function getPersonalInfoFromRequest( AddDonationRequest $request ) { |
|
| 99 | - if ( $request->donorIsAnonymous() ) { |
|
| 98 | + private function getPersonalInfoFromRequest(AddDonationRequest $request) { |
|
| 99 | + if ($request->donorIsAnonymous()) { |
|
| 100 | 100 | return null; |
| 101 | 101 | } |
| 102 | 102 | return new Donor( |
| 103 | - $this->getNameFromRequest( $request ), |
|
| 104 | - $this->getPhysicalAddressFromRequest( $request ), |
|
| 103 | + $this->getNameFromRequest($request), |
|
| 104 | + $this->getPhysicalAddressFromRequest($request), |
|
| 105 | 105 | $request->getDonorEmailAddress() |
| 106 | 106 | ); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - private function getPhysicalAddressFromRequest( AddDonationRequest $request ): DonorAddress { |
|
| 109 | + private function getPhysicalAddressFromRequest(AddDonationRequest $request): DonorAddress { |
|
| 110 | 110 | $address = new DonorAddress(); |
| 111 | 111 | |
| 112 | - $address->setStreetAddress( $request->getDonorStreetAddress() ); |
|
| 113 | - $address->setPostalCode( $request->getDonorPostalCode() ); |
|
| 114 | - $address->setCity( $request->getDonorCity() ); |
|
| 115 | - $address->setCountryCode( $request->getDonorCountryCode() ); |
|
| 112 | + $address->setStreetAddress($request->getDonorStreetAddress()); |
|
| 113 | + $address->setPostalCode($request->getDonorPostalCode()); |
|
| 114 | + $address->setCity($request->getDonorCity()); |
|
| 115 | + $address->setCountryCode($request->getDonorCountryCode()); |
|
| 116 | 116 | |
| 117 | 117 | return $address->freeze()->assertNoNullFields(); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - private function getNameFromRequest( AddDonationRequest $request ): DonorName { |
|
| 120 | + private function getNameFromRequest(AddDonationRequest $request): DonorName { |
|
| 121 | 121 | $name = $request->donorIsCompany() ? DonorName::newCompanyName() : DonorName::newPrivatePersonName(); |
| 122 | 122 | |
| 123 | - $name->setSalutation( $request->getDonorSalutation() ); |
|
| 124 | - $name->setTitle( $request->getDonorTitle() ); |
|
| 125 | - $name->setCompanyName( $request->getDonorCompany() ); |
|
| 126 | - $name->setFirstName( $request->getDonorFirstName() ); |
|
| 127 | - $name->setLastName( $request->getDonorLastName() ); |
|
| 123 | + $name->setSalutation($request->getDonorSalutation()); |
|
| 124 | + $name->setTitle($request->getDonorTitle()); |
|
| 125 | + $name->setCompanyName($request->getDonorCompany()); |
|
| 126 | + $name->setFirstName($request->getDonorFirstName()); |
|
| 127 | + $name->setLastName($request->getDonorLastName()); |
|
| 128 | 128 | |
| 129 | 129 | return $name->freeze()->assertNoNullFields(); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - private function getInitialDonationStatus( string $paymentType ): string { |
|
| 133 | - if ( $paymentType === PaymentType::DIRECT_DEBIT ) { |
|
| 132 | + private function getInitialDonationStatus(string $paymentType): string { |
|
| 133 | + if ($paymentType === PaymentType::DIRECT_DEBIT) { |
|
| 134 | 134 | return Donation::STATUS_NEW; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if ( $paymentType === PaymentType::BANK_TRANSFER ) { |
|
| 137 | + if ($paymentType === PaymentType::BANK_TRANSFER) { |
|
| 138 | 138 | return Donation::STATUS_PROMISE; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | return Donation::STATUS_EXTERNAL_INCOMPLETE; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - private function getPaymentFromRequest( AddDonationRequest $donationRequest ): DonationPayment { |
|
| 144 | + private function getPaymentFromRequest(AddDonationRequest $donationRequest): DonationPayment { |
|
| 145 | 145 | return new DonationPayment( |
| 146 | 146 | $donationRequest->getAmount(), |
| 147 | 147 | $donationRequest->getInterval(), |
| 148 | - $this->getPaymentMethodFromRequest( $donationRequest ) |
|
| 148 | + $this->getPaymentMethodFromRequest($donationRequest) |
|
| 149 | 149 | ); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - private function getPaymentMethodFromRequest( AddDonationRequest $donationRequest ): PaymentMethod { |
|
| 153 | - if ( $donationRequest->getPaymentType() === PaymentType::BANK_TRANSFER ) { |
|
| 154 | - return new BankTransferPayment( $this->transferCodeGenerator->generateTransferCode() ); |
|
| 152 | + private function getPaymentMethodFromRequest(AddDonationRequest $donationRequest): PaymentMethod { |
|
| 153 | + if ($donationRequest->getPaymentType() === PaymentType::BANK_TRANSFER) { |
|
| 154 | + return new BankTransferPayment($this->transferCodeGenerator->generateTransferCode()); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if ( $donationRequest->getPaymentType() === PaymentType::DIRECT_DEBIT ) { |
|
| 158 | - return new DirectDebitPayment( $donationRequest->getBankData() ); |
|
| 157 | + if ($donationRequest->getPaymentType() === PaymentType::DIRECT_DEBIT) { |
|
| 158 | + return new DirectDebitPayment($donationRequest->getBankData()); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if ( $donationRequest->getPaymentType() === PaymentType::PAYPAL ) { |
|
| 162 | - return new PayPalPayment( new PayPalData() ); |
|
| 161 | + if ($donationRequest->getPaymentType() === PaymentType::PAYPAL) { |
|
| 162 | + return new PayPalPayment(new PayPalData()); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - return new PaymentWithoutAssociatedData( $donationRequest->getPaymentType() ); |
|
| 165 | + return new PaymentWithoutAssociatedData($donationRequest->getPaymentType()); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - private function newTrackingInfoFromRequest( AddDonationRequest $request ): DonationTrackingInfo { |
|
| 168 | + private function newTrackingInfoFromRequest(AddDonationRequest $request): DonationTrackingInfo { |
|
| 169 | 169 | $trackingInfo = new DonationTrackingInfo(); |
| 170 | 170 | |
| 171 | - $trackingInfo->setTracking( $request->getTracking() ); |
|
| 172 | - $trackingInfo->setSource( $this->referrerGeneralizer->generalize( $request->getSource() ) ); |
|
| 173 | - $trackingInfo->setTotalImpressionCount( $request->getTotalImpressionCount() ); |
|
| 174 | - $trackingInfo->setSingleBannerImpressionCount( $request->getSingleBannerImpressionCount() ); |
|
| 175 | - $trackingInfo->setColor( $request->getColor() ); |
|
| 176 | - $trackingInfo->setSkin( $request->getSkin() ); |
|
| 177 | - $trackingInfo->setLayout( $request->getLayout() ); |
|
| 171 | + $trackingInfo->setTracking($request->getTracking()); |
|
| 172 | + $trackingInfo->setSource($this->referrerGeneralizer->generalize($request->getSource())); |
|
| 173 | + $trackingInfo->setTotalImpressionCount($request->getTotalImpressionCount()); |
|
| 174 | + $trackingInfo->setSingleBannerImpressionCount($request->getSingleBannerImpressionCount()); |
|
| 175 | + $trackingInfo->setColor($request->getColor()); |
|
| 176 | + $trackingInfo->setSkin($request->getSkin()); |
|
| 177 | + $trackingInfo->setLayout($request->getLayout()); |
|
| 178 | 178 | |
| 179 | 179 | return $trackingInfo->freeze()->assertNoNullFields(); |
| 180 | 180 | } |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @throws \RuntimeException |
| 186 | 186 | */ |
| 187 | - private function sendDonationConfirmationEmail( Donation $donation ) { |
|
| 188 | - if ( $donation->getDonor() !== null && !$donation->hasExternalPayment() ) { |
|
| 189 | - $this->mailer->sendConfirmationMailFor( $donation ); |
|
| 187 | + private function sendDonationConfirmationEmail(Donation $donation) { |
|
| 188 | + if ($donation->getDonor() !== null && !$donation->hasExternalPayment()) { |
|
| 189 | + $this->mailer->sendConfirmationMailFor($donation); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare( strict_types = 1 ); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace WMDE\Fundraising\Frontend\DonationContext\Tests\Unit\Domain\Model; |
| 6 | 6 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function testGivenNonDirectDebitDonation_cancellationFails() { |
| 21 | 21 | $donation = ValidDonation::newBankTransferDonation(); |
| 22 | 22 | |
| 23 | - $this->expectException( RuntimeException::class ); |
|
| 23 | + $this->expectException(RuntimeException::class); |
|
| 24 | 24 | $donation->cancel(); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -28,20 +28,20 @@ discard block |
||
| 28 | 28 | $donation = ValidDonation::newDirectDebitDonation(); |
| 29 | 29 | |
| 30 | 30 | $donation->cancel(); |
| 31 | - $this->assertSame( Donation::STATUS_CANCELLED, $donation->getStatus() ); |
|
| 31 | + $this->assertSame(Donation::STATUS_CANCELLED, $donation->getStatus()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * @dataProvider nonCancellableStatusProvider |
| 36 | 36 | */ |
| 37 | - public function testGivenNonNewStatus_cancellationFails( $nonCancellableStatus ) { |
|
| 38 | - $donation = $this->newDirectDebitDonationWithStatus( $nonCancellableStatus ); |
|
| 37 | + public function testGivenNonNewStatus_cancellationFails($nonCancellableStatus) { |
|
| 38 | + $donation = $this->newDirectDebitDonationWithStatus($nonCancellableStatus); |
|
| 39 | 39 | |
| 40 | - $this->expectException( RuntimeException::class ); |
|
| 40 | + $this->expectException(RuntimeException::class); |
|
| 41 | 41 | $donation->cancel(); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - private function newDirectDebitDonationWithStatus( string $status ) { |
|
| 44 | + private function newDirectDebitDonationWithStatus(string $status) { |
|
| 45 | 45 | return new Donation( |
| 46 | 46 | null, |
| 47 | 47 | $status, |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | public function nonCancellableStatusProvider() { |
| 56 | 56 | return [ |
| 57 | - [ Donation::STATUS_CANCELLED ], |
|
| 58 | - [ Donation::STATUS_EXTERNAL_BOOKED ], |
|
| 59 | - [ Donation::STATUS_EXTERNAL_INCOMPLETE ], |
|
| 60 | - [ Donation::STATUS_PROMISE ], |
|
| 57 | + [Donation::STATUS_CANCELLED], |
|
| 58 | + [Donation::STATUS_EXTERNAL_BOOKED], |
|
| 59 | + [Donation::STATUS_EXTERNAL_INCOMPLETE], |
|
| 60 | + [Donation::STATUS_PROMISE], |
|
| 61 | 61 | ]; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -65,14 +65,14 @@ discard block |
||
| 65 | 65 | $donation = ValidDonation::newDirectDebitDonation(); |
| 66 | 66 | |
| 67 | 67 | $donation->cancel(); |
| 68 | - $this->assertSame( Donation::STATUS_CANCELLED, $donation->getStatus() ); |
|
| 68 | + $this->assertSame(Donation::STATUS_CANCELLED, $donation->getStatus()); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | public function testModerationStatusCanBeQueried() { |
| 72 | 72 | $donation = ValidDonation::newDirectDebitDonation(); |
| 73 | 73 | |
| 74 | 74 | $donation->markForModeration(); |
| 75 | - $this->assertTrue( $donation->needsModeration() ); |
|
| 75 | + $this->assertTrue($donation->needsModeration()); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | public function testGivenModerationStatus_cancellationSucceeds() { |
@@ -80,72 +80,72 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | $donation->markForModeration(); |
| 82 | 82 | $donation->cancel(); |
| 83 | - $this->assertSame( Donation::STATUS_CANCELLED, $donation->getStatus() ); |
|
| 83 | + $this->assertSame(Donation::STATUS_CANCELLED, $donation->getStatus()); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | public function testIdIsNullWhenNotAssigned() { |
| 87 | - $this->assertNull( ValidDonation::newDirectDebitDonation()->getId() ); |
|
| 87 | + $this->assertNull(ValidDonation::newDirectDebitDonation()->getId()); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function testCanAssignIdToNewDonation() { |
| 91 | 91 | $donation = ValidDonation::newDirectDebitDonation(); |
| 92 | 92 | |
| 93 | - $donation->assignId( 42 ); |
|
| 94 | - $this->assertSame( 42, $donation->getId() ); |
|
| 93 | + $donation->assignId(42); |
|
| 94 | + $this->assertSame(42, $donation->getId()); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function testCannotAssignIdToDonationWithIdentity() { |
| 98 | 98 | $donation = ValidDonation::newDirectDebitDonation(); |
| 99 | - $donation->assignId( 42 ); |
|
| 99 | + $donation->assignId(42); |
|
| 100 | 100 | |
| 101 | - $this->expectException( RuntimeException::class ); |
|
| 102 | - $donation->assignId( 43 ); |
|
| 101 | + $this->expectException(RuntimeException::class); |
|
| 102 | + $donation->assignId(43); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | public function testGivenNonExternalPaymentType_confirmBookedThrowsException() { |
| 106 | 106 | $donation = ValidDonation::newDirectDebitDonation(); |
| 107 | 107 | |
| 108 | - $this->expectException( RuntimeException::class ); |
|
| 109 | - $this->expectExceptionMessageRegExp( '/Only external payments/' ); |
|
| 108 | + $this->expectException(RuntimeException::class); |
|
| 109 | + $this->expectExceptionMessageRegExp('/Only external payments/'); |
|
| 110 | 110 | $donation->confirmBooked(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | public function testAddingPayPalDataToNoPayPalDonationCausesException() { |
| 114 | 114 | $donation = ValidDonation::newDirectDebitDonation(); |
| 115 | 115 | |
| 116 | - $this->expectException( RuntimeException::class ); |
|
| 117 | - $donation->addPayPalData( new PayPalData() ); |
|
| 116 | + $this->expectException(RuntimeException::class); |
|
| 117 | + $donation->addPayPalData(new PayPalData()); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | 121 | * @dataProvider statusesThatDoNotAllowForBookingProvider |
| 122 | 122 | */ |
| 123 | - public function testGivenStatusThatDoesNotAllowForBooking_confirmBookedThrowsException( Donation $donation ) { |
|
| 124 | - $this->expectException( RuntimeException::class ); |
|
| 123 | + public function testGivenStatusThatDoesNotAllowForBooking_confirmBookedThrowsException(Donation $donation) { |
|
| 124 | + $this->expectException(RuntimeException::class); |
|
| 125 | 125 | $donation->confirmBooked(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function statusesThatDoNotAllowForBookingProvider() { |
| 129 | 129 | return [ |
| 130 | - [ ValidDonation::newBookedPayPalDonation() ], |
|
| 131 | - [ ValidDonation::newBookedCreditCardDonation() ], |
|
| 130 | + [ValidDonation::newBookedPayPalDonation()], |
|
| 131 | + [ValidDonation::newBookedCreditCardDonation()], |
|
| 132 | 132 | ]; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * @dataProvider statusesThatAllowsForBookingProvider |
| 137 | 137 | */ |
| 138 | - public function testGivenStatusThatAllowsForBooking_confirmBookedSetsBookedStatus( Donation $donation ) { |
|
| 138 | + public function testGivenStatusThatAllowsForBooking_confirmBookedSetsBookedStatus(Donation $donation) { |
|
| 139 | 139 | $donation->confirmBooked(); |
| 140 | - $this->assertSame( Donation::STATUS_EXTERNAL_BOOKED, $donation->getStatus() ); |
|
| 140 | + $this->assertSame(Donation::STATUS_EXTERNAL_BOOKED, $donation->getStatus()); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | public function statusesThatAllowsForBookingProvider() { |
| 144 | 144 | return [ |
| 145 | - [ ValidDonation::newIncompletePayPalDonation() ], |
|
| 146 | - [ ValidDonation::newIncompleteCreditCardDonation() ], |
|
| 147 | - [ $this->newInModerationPayPalDonation() ], |
|
| 148 | - [ ValidDonation::newCancelledPayPalDonation() ], |
|
| 145 | + [ValidDonation::newIncompletePayPalDonation()], |
|
| 146 | + [ValidDonation::newIncompleteCreditCardDonation()], |
|
| 147 | + [$this->newInModerationPayPalDonation()], |
|
| 148 | + [ValidDonation::newCancelledPayPalDonation()], |
|
| 149 | 149 | ]; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | ValidDonation::newPublicComment() |
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | - $this->expectException( RuntimeException::class ); |
|
| 170 | - $donation->addComment( ValidDonation::newPublicComment() ); |
|
| 169 | + $this->expectException(RuntimeException::class); |
|
| 170 | + $donation->addComment(ValidDonation::newPublicComment()); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function testAddCommentSetsWhenCommentNotSetYet() { |
@@ -181,30 +181,30 @@ discard block |
||
| 181 | 181 | null |
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - $donation->addComment( ValidDonation::newPublicComment() ); |
|
| 185 | - $this->assertEquals( ValidDonation::newPublicComment(), $donation->getComment() ); |
|
| 184 | + $donation->addComment(ValidDonation::newPublicComment()); |
|
| 185 | + $this->assertEquals(ValidDonation::newPublicComment(), $donation->getComment()); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | public function testWhenNoCommentHasBeenSet_getCommentReturnsNull() { |
| 189 | - $this->assertNull( ValidDonation::newDirectDebitDonation()->getComment() ); |
|
| 189 | + $this->assertNull(ValidDonation::newDirectDebitDonation()->getComment()); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | public function testWhenCompletingBookingOfExternalPaymentInModeration_commentIsMadePrivate() { |
| 193 | 193 | $donation = $this->newInModerationPayPalDonation(); |
| 194 | - $donation->addComment( ValidDonation::newPublicComment() ); |
|
| 194 | + $donation->addComment(ValidDonation::newPublicComment()); |
|
| 195 | 195 | |
| 196 | 196 | $donation->confirmBooked(); |
| 197 | 197 | |
| 198 | - $this->assertFalse( $donation->getComment()->isPublic() ); |
|
| 198 | + $this->assertFalse($donation->getComment()->isPublic()); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | public function testWhenCompletingBookingOfCancelledExternalPayment_commentIsMadePrivate() { |
| 202 | 202 | $donation = ValidDonation::newCancelledPayPalDonation(); |
| 203 | - $donation->addComment( ValidDonation::newPublicComment() ); |
|
| 203 | + $donation->addComment(ValidDonation::newPublicComment()); |
|
| 204 | 204 | |
| 205 | 205 | $donation->confirmBooked(); |
| 206 | 206 | |
| 207 | - $this->assertFalse( $donation->getComment()->isPublic() ); |
|
| 207 | + $this->assertFalse($donation->getComment()->isPublic()); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | public function testWhenCompletingBookingOfCancelledExternalPayment_lackOfCommentCausesNoError() { |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $donation->confirmBooked(); |
| 214 | 214 | |
| 215 | - $this->assertFalse( $donation->hasComment() ); |
|
| 215 | + $this->assertFalse($donation->hasComment()); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | public function testWhenConstructingWithInvalidStatus_exceptionIsThrown() { |
| 219 | - $this->expectException( \InvalidArgumentException::class ); |
|
| 219 | + $this->expectException(\InvalidArgumentException::class); |
|
| 220 | 220 | |
| 221 | 221 | new Donation( |
| 222 | 222 | null, |
@@ -232,13 +232,13 @@ discard block |
||
| 232 | 232 | public function testWhenNonExternalPaymentIsNotifiedOfPolicyValidationFailure_itIsPutInModeration() { |
| 233 | 233 | $donation = ValidDonation::newBankTransferDonation(); |
| 234 | 234 | $donation->notifyOfPolicyValidationFailure(); |
| 235 | - $this->assertTrue( $donation->needsModeration() ); |
|
| 235 | + $this->assertTrue($donation->needsModeration()); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | public function testWhenExternalPaymentIsNotifiedOfPolicyValidationFailure_itIsNotPutInModeration() { |
| 239 | 239 | $donation = ValidDonation::newIncompletePayPalDonation(); |
| 240 | 240 | $donation->notifyOfPolicyValidationFailure(); |
| 241 | - $this->assertFalse( $donation->needsModeration() ); |
|
| 241 | + $this->assertFalse($donation->needsModeration()); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | } |