@@ -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\MembershipContext\Domain\Repositories; |
| 6 | 6 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | class ApplicationPurgedException extends GetMembershipApplicationException { |
| 12 | 12 | |
| 13 | 13 | public function __construct() { |
| 14 | - parent::__construct( 'Tried to access a purged Application' ); |
|
| 14 | + parent::__construct('Tried to access a purged Application'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | } |
@@ -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\MembershipContext\Domain\Repositories; |
| 6 | 6 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class GetMembershipApplicationException extends \RuntimeException { |
| 12 | 12 | |
| 13 | - public function __construct( string $message = null, \Exception $previous = null ) { |
|
| 13 | + public function __construct(string $message = null, \Exception $previous = null) { |
|
| 14 | 14 | parent::__construct( |
| 15 | 15 | $message ?? 'Could not get membership application', |
| 16 | 16 | 0, |
@@ -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\MembershipContext\DataAccess; |
| 6 | 6 | |
@@ -36,108 +36,108 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | private $entityManager; |
| 38 | 38 | |
| 39 | - public function __construct( EntityManager $entityManager ) { |
|
| 39 | + public function __construct(EntityManager $entityManager) { |
|
| 40 | 40 | $this->entityManager = $entityManager; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function storeApplication( Application $application ): void { |
|
| 44 | - if ( $application->hasId() ) { |
|
| 45 | - $this->updateApplication( $application ); |
|
| 43 | + public function storeApplication(Application $application): void { |
|
| 44 | + if ($application->hasId()) { |
|
| 45 | + $this->updateApplication($application); |
|
| 46 | 46 | } |
| 47 | 47 | else { |
| 48 | - $this->insertApplication( $application ); |
|
| 48 | + $this->insertApplication($application); |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - private function insertApplication( Application $application ): void { |
|
| 52 | + private function insertApplication(Application $application): void { |
|
| 53 | 53 | $doctrineApplication = new DoctrineApplication(); |
| 54 | - $this->updateDoctrineApplication( $doctrineApplication, $application ); |
|
| 54 | + $this->updateDoctrineApplication($doctrineApplication, $application); |
|
| 55 | 55 | |
| 56 | 56 | try { |
| 57 | - $this->entityManager->persist( $doctrineApplication ); |
|
| 57 | + $this->entityManager->persist($doctrineApplication); |
|
| 58 | 58 | $this->entityManager->flush(); |
| 59 | 59 | } |
| 60 | - catch ( ORMException $ex ) { |
|
| 61 | - throw new StoreMembershipApplicationException( $ex ); |
|
| 60 | + catch (ORMException $ex) { |
|
| 61 | + throw new StoreMembershipApplicationException($ex); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $application->assignId( $doctrineApplication->getId() ); |
|
| 64 | + $application->assignId($doctrineApplication->getId()); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - private function updateApplication( Application $application ): void { |
|
| 68 | - $doctrineApplication = $this->getDoctrineApplicationById( $application->getId() ); |
|
| 67 | + private function updateApplication(Application $application): void { |
|
| 68 | + $doctrineApplication = $this->getDoctrineApplicationById($application->getId()); |
|
| 69 | 69 | |
| 70 | - if ( $doctrineApplication === null ) { |
|
| 70 | + if ($doctrineApplication === null) { |
|
| 71 | 71 | throw new StoreMembershipApplicationException(); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->updateDoctrineApplication( $doctrineApplication, $application ); |
|
| 74 | + $this->updateDoctrineApplication($doctrineApplication, $application); |
|
| 75 | 75 | |
| 76 | 76 | try { |
| 77 | - $this->entityManager->persist( $doctrineApplication ); |
|
| 77 | + $this->entityManager->persist($doctrineApplication); |
|
| 78 | 78 | $this->entityManager->flush(); |
| 79 | 79 | } |
| 80 | - catch ( ORMException $ex ) { |
|
| 81 | - throw new StoreMembershipApplicationException( $ex ); |
|
| 80 | + catch (ORMException $ex) { |
|
| 81 | + throw new StoreMembershipApplicationException($ex); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - private function updateDoctrineApplication( DoctrineApplication $doctrineApplication, Application $application ): void { |
|
| 86 | - $doctrineApplication->setId( $application->getId() ); |
|
| 87 | - $doctrineApplication->setMembershipType( $application->getType() ); |
|
| 85 | + private function updateDoctrineApplication(DoctrineApplication $doctrineApplication, Application $application): void { |
|
| 86 | + $doctrineApplication->setId($application->getId()); |
|
| 87 | + $doctrineApplication->setMembershipType($application->getType()); |
|
| 88 | 88 | |
| 89 | - $this->setApplicantFields( $doctrineApplication, $application->getApplicant() ); |
|
| 90 | - $this->setPaymentFields( $doctrineApplication, $application->getPayment() ); |
|
| 91 | - $doctrineApplication->setDonationReceipt( $application->getDonationReceipt() ); |
|
| 89 | + $this->setApplicantFields($doctrineApplication, $application->getApplicant()); |
|
| 90 | + $this->setPaymentFields($doctrineApplication, $application->getPayment()); |
|
| 91 | + $doctrineApplication->setDonationReceipt($application->getDonationReceipt()); |
|
| 92 | 92 | |
| 93 | - $doctrineStatus = $this->getDoctrineStatus( $application ); |
|
| 94 | - $this->preserveDoctrineStatus( $doctrineApplication, $doctrineStatus ); |
|
| 95 | - $doctrineApplication->setStatus( $doctrineStatus ); |
|
| 93 | + $doctrineStatus = $this->getDoctrineStatus($application); |
|
| 94 | + $this->preserveDoctrineStatus($doctrineApplication, $doctrineStatus); |
|
| 95 | + $doctrineApplication->setStatus($doctrineStatus); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - private function setApplicantFields( DoctrineApplication $application, Applicant $applicant ): void { |
|
| 99 | - $application->setApplicantFirstName( $applicant->getName()->getFirstName() ); |
|
| 100 | - $application->setApplicantLastName( $applicant->getName()->getLastName() ); |
|
| 101 | - $application->setApplicantSalutation( $applicant->getName()->getSalutation() ); |
|
| 102 | - $application->setApplicantTitle( $applicant->getName()->getTitle() ); |
|
| 103 | - $application->setCompany( $applicant->getName()->getCompanyName() ); |
|
| 98 | + private function setApplicantFields(DoctrineApplication $application, Applicant $applicant): void { |
|
| 99 | + $application->setApplicantFirstName($applicant->getName()->getFirstName()); |
|
| 100 | + $application->setApplicantLastName($applicant->getName()->getLastName()); |
|
| 101 | + $application->setApplicantSalutation($applicant->getName()->getSalutation()); |
|
| 102 | + $application->setApplicantTitle($applicant->getName()->getTitle()); |
|
| 103 | + $application->setCompany($applicant->getName()->getCompanyName()); |
|
| 104 | 104 | |
| 105 | - $application->setApplicantDateOfBirth( $applicant->getDateOfBirth() ); |
|
| 105 | + $application->setApplicantDateOfBirth($applicant->getDateOfBirth()); |
|
| 106 | 106 | |
| 107 | - $application->setApplicantEmailAddress( $applicant->getEmailAddress()->getFullAddress() ); |
|
| 108 | - $application->setApplicantPhoneNumber( $applicant->getPhoneNumber()->__toString() ); |
|
| 107 | + $application->setApplicantEmailAddress($applicant->getEmailAddress()->getFullAddress()); |
|
| 108 | + $application->setApplicantPhoneNumber($applicant->getPhoneNumber()->__toString()); |
|
| 109 | 109 | |
| 110 | 110 | $address = $applicant->getPhysicalAddress(); |
| 111 | 111 | |
| 112 | - $application->setCity( $address->getCity() ); |
|
| 113 | - $application->setCountry( $address->getCountryCode() ); |
|
| 114 | - $application->setPostcode( $address->getPostalCode() ); |
|
| 115 | - $application->setAddress( $address->getStreetAddress() ); |
|
| 112 | + $application->setCity($address->getCity()); |
|
| 113 | + $application->setCountry($address->getCountryCode()); |
|
| 114 | + $application->setPostcode($address->getPostalCode()); |
|
| 115 | + $application->setAddress($address->getStreetAddress()); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - private function setPaymentFields( DoctrineApplication $application, Payment $payment ): void { |
|
| 119 | - $application->setPaymentIntervalInMonths( $payment->getIntervalInMonths() ); |
|
| 120 | - $application->setPaymentAmount( (int)$payment->getAmount()->getEuroFloat() ); |
|
| 118 | + private function setPaymentFields(DoctrineApplication $application, Payment $payment): void { |
|
| 119 | + $application->setPaymentIntervalInMonths($payment->getIntervalInMonths()); |
|
| 120 | + $application->setPaymentAmount((int)$payment->getAmount()->getEuroFloat()); |
|
| 121 | 121 | $paymentMethod = $payment->getPaymentMethod(); |
| 122 | 122 | |
| 123 | - $application->setPaymentType( $paymentMethod->getType() ); |
|
| 124 | - if ( $paymentMethod instanceof DirectDebitPayment ) { |
|
| 125 | - $this->setBankDataFields( $application, $paymentMethod->getBankData() ); |
|
| 126 | - } elseif ( $paymentMethod instanceof PayPalPayment && $paymentMethod->getPayPalData() != new PayPalData() ) { |
|
| 127 | - $this->setPayPalDataFields( $application, $paymentMethod->getPayPalData() ); |
|
| 123 | + $application->setPaymentType($paymentMethod->getType()); |
|
| 124 | + if ($paymentMethod instanceof DirectDebitPayment) { |
|
| 125 | + $this->setBankDataFields($application, $paymentMethod->getBankData()); |
|
| 126 | + } elseif ($paymentMethod instanceof PayPalPayment && $paymentMethod->getPayPalData() != new PayPalData()) { |
|
| 127 | + $this->setPayPalDataFields($application, $paymentMethod->getPayPalData()); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - private function setBankDataFields( DoctrineApplication $application, BankData $bankData ): void { |
|
| 132 | - $application->setPaymentBankAccount( $bankData->getAccount() ); |
|
| 133 | - $application->setPaymentBankCode( $bankData->getBankCode() ); |
|
| 134 | - $application->setPaymentBankName( $bankData->getBankName() ); |
|
| 135 | - $application->setPaymentBic( $bankData->getBic() ); |
|
| 136 | - $application->setPaymentIban( $bankData->getIban()->toString() ); |
|
| 131 | + private function setBankDataFields(DoctrineApplication $application, BankData $bankData): void { |
|
| 132 | + $application->setPaymentBankAccount($bankData->getAccount()); |
|
| 133 | + $application->setPaymentBankCode($bankData->getBankCode()); |
|
| 134 | + $application->setPaymentBankName($bankData->getBankName()); |
|
| 135 | + $application->setPaymentBic($bankData->getBic()); |
|
| 136 | + $application->setPaymentIban($bankData->getIban()->toString()); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - private function setPayPalDataFields( DoctrineApplication $application, PayPalData $payPalData ): void { |
|
| 140 | - $application->encodeAndSetData( array_merge( |
|
| 139 | + private function setPayPalDataFields(DoctrineApplication $application, PayPalData $payPalData): void { |
|
| 140 | + $application->encodeAndSetData(array_merge( |
|
| 141 | 141 | $application->getDecodedData(), |
| 142 | 142 | [ |
| 143 | 143 | 'paypal_payer_id' => $payPalData->getPayerId(), |
@@ -159,43 +159,43 @@ discard block |
||
| 159 | 159 | 'ext_payment_timestamp' => $payPalData->getPaymentTimestamp(), |
| 160 | 160 | 'first_payment_date' => $payPalData->getFirstPaymentDate() |
| 161 | 161 | ] |
| 162 | - ) ); |
|
| 162 | + )); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - private function getDoctrineStatus( Application $application ): int { |
|
| 165 | + private function getDoctrineStatus(Application $application): int { |
|
| 166 | 166 | $status = DoctrineApplication::STATUS_NEUTRAL; |
| 167 | 167 | |
| 168 | - if ( $application->needsModeration() ) { |
|
| 168 | + if ($application->needsModeration()) { |
|
| 169 | 169 | $status += DoctrineApplication::STATUS_MODERATION; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if ( $application->isCancelled() ) { |
|
| 172 | + if ($application->isCancelled()) { |
|
| 173 | 173 | $status += DoctrineApplication::STATUS_CANCELED; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( $application->isDeleted() ) { |
|
| 176 | + if ($application->isDeleted()) { |
|
| 177 | 177 | $status += DoctrineApplication::STATUS_DELETED; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ( $application->isConfirmed() || $this->isAutoConfirmed( $status, $application ) ) { |
|
| 180 | + if ($application->isConfirmed() || $this->isAutoConfirmed($status, $application)) { |
|
| 181 | 181 | $status += DoctrineApplication::STATUS_CONFIRMED; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | return $status; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - private function isAutoConfirmed( int $status, Application $application ): bool { |
|
| 188 | - return $status === DoctrineApplication::STATUS_NEUTRAL && $this->isDirectDebitPayment( $application ); |
|
| 187 | + private function isAutoConfirmed(int $status, Application $application): bool { |
|
| 188 | + return $status === DoctrineApplication::STATUS_NEUTRAL && $this->isDirectDebitPayment($application); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - private function isDirectDebitPayment( Application $application ): bool { |
|
| 191 | + private function isDirectDebitPayment(Application $application): bool { |
|
| 192 | 192 | return $application->getPayment()->getPaymentMethod()->getType() === PaymentType::DIRECT_DEBIT; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - private function preserveDoctrineStatus( DoctrineApplication $doctrineApplication, int $doctrineStatus ): void { |
|
| 196 | - if ( $doctrineStatus < DoctrineApplication::STATUS_CONFIRMED ) { |
|
| 197 | - $doctrineApplication->modifyDataObject( function ( MembershipApplicationData $data ): void { |
|
| 198 | - $data->setPreservedStatus( DoctrineApplication::STATUS_CONFIRMED ); |
|
| 195 | + private function preserveDoctrineStatus(DoctrineApplication $doctrineApplication, int $doctrineStatus): void { |
|
| 196 | + if ($doctrineStatus < DoctrineApplication::STATUS_CONFIRMED) { |
|
| 197 | + $doctrineApplication->modifyDataObject(function(MembershipApplicationData $data): void { |
|
| 198 | + $data->setPreservedStatus(DoctrineApplication::STATUS_CONFIRMED); |
|
| 199 | 199 | } ); |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -206,20 +206,20 @@ discard block |
||
| 206 | 206 | * @return Application|null |
| 207 | 207 | * @throws GetMembershipApplicationException |
| 208 | 208 | */ |
| 209 | - public function getApplicationById( int $id ): ?Application { |
|
| 209 | + public function getApplicationById(int $id): ?Application { |
|
| 210 | 210 | try { |
| 211 | - $application = $this->getDoctrineApplicationById( $id ); |
|
| 211 | + $application = $this->getDoctrineApplicationById($id); |
|
| 212 | 212 | } |
| 213 | - catch ( ORMException $ex ) { |
|
| 214 | - throw new GetMembershipApplicationException( null, $ex ); |
|
| 213 | + catch (ORMException $ex) { |
|
| 214 | + throw new GetMembershipApplicationException(null, $ex); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( $application === null ) { |
|
| 217 | + if ($application === null) { |
|
| 218 | 218 | return null; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if ( $application->getBackup() === null ) { |
|
| 222 | - return $this->newApplicationDomainEntity( $application ); |
|
| 221 | + if ($application->getBackup() === null) { |
|
| 222 | + return $this->newApplicationDomainEntity($application); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | throw new ApplicationPurgedException(); |
@@ -230,25 +230,25 @@ discard block |
||
| 230 | 230 | * @return DoctrineApplication|null |
| 231 | 231 | * @throws ORMException |
| 232 | 232 | */ |
| 233 | - public function getDoctrineApplicationById( int $id ): ?DoctrineApplication { |
|
| 234 | - return $this->entityManager->find( DoctrineApplication::class, $id ); |
|
| 233 | + public function getDoctrineApplicationById(int $id): ?DoctrineApplication { |
|
| 234 | + return $this->entityManager->find(DoctrineApplication::class, $id); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - private function newApplicationDomainEntity( DoctrineApplication $application ): Application { |
|
| 237 | + private function newApplicationDomainEntity(DoctrineApplication $application): Application { |
|
| 238 | 238 | return new Application( |
| 239 | 239 | $application->getId(), |
| 240 | 240 | $application->getMembershipType(), |
| 241 | 241 | new Applicant( |
| 242 | - $this->newPersonName( $application ), |
|
| 243 | - $this->newAddress( $application ), |
|
| 244 | - new EmailAddress( $application->getApplicantEmailAddress() ), |
|
| 245 | - new PhoneNumber( $application->getApplicantPhoneNumber() ), |
|
| 242 | + $this->newPersonName($application), |
|
| 243 | + $this->newAddress($application), |
|
| 244 | + new EmailAddress($application->getApplicantEmailAddress()), |
|
| 245 | + new PhoneNumber($application->getApplicantPhoneNumber()), |
|
| 246 | 246 | $application->getApplicantDateOfBirth() |
| 247 | 247 | ), |
| 248 | 248 | new Payment( |
| 249 | 249 | $application->getPaymentIntervalInMonths(), |
| 250 | - Euro::newFromFloat( $application->getPaymentAmount() ), |
|
| 251 | - $this->newPaymentMethod( $application ) |
|
| 250 | + Euro::newFromFloat($application->getPaymentAmount()), |
|
| 251 | + $this->newPaymentMethod($application) |
|
| 252 | 252 | ), |
| 253 | 253 | $application->needsModeration(), |
| 254 | 254 | $application->isCancelled(), |
@@ -258,77 +258,77 @@ discard block |
||
| 258 | 258 | ); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - private function newPersonName( DoctrineApplication $application ): ApplicantName { |
|
| 262 | - if ( empty( $application->getCompany() ) ) { |
|
| 261 | + private function newPersonName(DoctrineApplication $application): ApplicantName { |
|
| 262 | + if (empty($application->getCompany())) { |
|
| 263 | 263 | $personName = ApplicantName::newPrivatePersonName(); |
| 264 | - $personName->setFirstName( $application->getApplicantFirstName() ); |
|
| 265 | - $personName->setLastName( $application->getApplicantLastName() ); |
|
| 266 | - $personName->setSalutation( $application->getApplicantSalutation() ); |
|
| 267 | - $personName->setTitle( $application->getApplicantTitle() ); |
|
| 264 | + $personName->setFirstName($application->getApplicantFirstName()); |
|
| 265 | + $personName->setLastName($application->getApplicantLastName()); |
|
| 266 | + $personName->setSalutation($application->getApplicantSalutation()); |
|
| 267 | + $personName->setTitle($application->getApplicantTitle()); |
|
| 268 | 268 | } else { |
| 269 | 269 | $personName = ApplicantName::newCompanyName(); |
| 270 | - $personName->setCompanyName( $application->getCompany() ); |
|
| 271 | - $personName->setSalutation( $application->getApplicantSalutation() ); |
|
| 270 | + $personName->setCompanyName($application->getCompany()); |
|
| 271 | + $personName->setSalutation($application->getApplicantSalutation()); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | return $personName->freeze()->assertNoNullFields(); |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - private function newAddress( DoctrineApplication $application ): ApplicantAddress { |
|
| 277 | + private function newAddress(DoctrineApplication $application): ApplicantAddress { |
|
| 278 | 278 | $address = new ApplicantAddress(); |
| 279 | 279 | |
| 280 | - $address->setCity( $application->getCity() ); |
|
| 281 | - $address->setCountryCode( $application->getCountry() ); |
|
| 282 | - $address->setPostalCode( $application->getPostcode() ); |
|
| 283 | - $address->setStreetAddress( $application->getAddress() ); |
|
| 280 | + $address->setCity($application->getCity()); |
|
| 281 | + $address->setCountryCode($application->getCountry()); |
|
| 282 | + $address->setPostalCode($application->getPostcode()); |
|
| 283 | + $address->setStreetAddress($application->getAddress()); |
|
| 284 | 284 | |
| 285 | 285 | return $address->freeze()->assertNoNullFields(); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - private function newPaymentMethod( DoctrineApplication $application ): PaymentMethod { |
|
| 289 | - if ( $application->getPaymentType() === PaymentType::DIRECT_DEBIT ) { |
|
| 290 | - return new DirectDebitPayment( $this->newBankData( $application ) ); |
|
| 288 | + private function newPaymentMethod(DoctrineApplication $application): PaymentMethod { |
|
| 289 | + if ($application->getPaymentType() === PaymentType::DIRECT_DEBIT) { |
|
| 290 | + return new DirectDebitPayment($this->newBankData($application)); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if ( $application->getPaymentType() === PaymentType::PAYPAL ) { |
|
| 294 | - return new PayPalPayment( $this->newPayPalData( $application ) ); |
|
| 293 | + if ($application->getPaymentType() === PaymentType::PAYPAL) { |
|
| 294 | + return new PayPalPayment($this->newPayPalData($application)); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - throw new \RuntimeException( 'Unsupported payment type' ); |
|
| 297 | + throw new \RuntimeException('Unsupported payment type'); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - private function newBankData( DoctrineApplication $application ): BankData { |
|
| 300 | + private function newBankData(DoctrineApplication $application): BankData { |
|
| 301 | 301 | $bankData = new BankData(); |
| 302 | 302 | |
| 303 | - $bankData->setAccount( $application->getPaymentBankAccount() ); |
|
| 304 | - $bankData->setBankCode( $application->getPaymentBankCode() ); |
|
| 305 | - $bankData->setBankName( $application->getPaymentBankName() ); |
|
| 306 | - $bankData->setBic( $application->getPaymentBic() ); |
|
| 307 | - $bankData->setIban( new Iban( $application->getPaymentIban() ) ); |
|
| 303 | + $bankData->setAccount($application->getPaymentBankAccount()); |
|
| 304 | + $bankData->setBankCode($application->getPaymentBankCode()); |
|
| 305 | + $bankData->setBankName($application->getPaymentBankName()); |
|
| 306 | + $bankData->setBic($application->getPaymentBic()); |
|
| 307 | + $bankData->setIban(new Iban($application->getPaymentIban())); |
|
| 308 | 308 | |
| 309 | 309 | return $bankData->freeze()->assertNoNullFields(); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - private function newPayPalData( DoctrineApplication $application ): ?PayPalData { |
|
| 312 | + private function newPayPalData(DoctrineApplication $application): ?PayPalData { |
|
| 313 | 313 | $data = $application->getDecodedData(); |
| 314 | 314 | |
| 315 | - return ( new PayPalData() ) |
|
| 316 | - ->setPayerId( $data['paypal_payer_id'] ?? '' ) |
|
| 317 | - ->setSubscriberId( $data['paypal_subscr_id'] ?? '' ) |
|
| 318 | - ->setPayerStatus( $data['paypal_payer_status'] ?? '' ) |
|
| 319 | - ->setAddressStatus( $data['paypal_address_status'] ?? '' ) |
|
| 320 | - ->setAmount( Euro::newFromString( $data['paypal_mc_gross'] ?? '0' ) ) |
|
| 321 | - ->setCurrencyCode( $data['paypal_mc_currency'] ?? '' ) |
|
| 322 | - ->setFee( Euro::newFromString( $data['paypal_mc_fee'] ?? '0' ) ) |
|
| 323 | - ->setSettleAmount( Euro::newFromString( $data['paypal_settle_amount'] ?? '0' ) ) |
|
| 324 | - ->setFirstName( $data['paypal_first_name'] ?? '' ) |
|
| 325 | - ->setLastName( $data['paypal_last_name'] ?? '' ) |
|
| 326 | - ->setAddressName( $data['paypal_address_name'] ?? '' ) |
|
| 327 | - ->setPaymentId( $data['ext_payment_id'] ?? '' ) |
|
| 328 | - ->setPaymentType( $data['ext_payment_type'] ?? '' ) |
|
| 329 | - ->setPaymentStatus( $data['ext_payment_status'] ?? '' ) |
|
| 330 | - ->setPaymentTimestamp( $data['ext_payment_timestamp'] ?? '' ) |
|
| 331 | - ->setFirstPaymentDate( $data['first_payment_date'] ?? '' ) |
|
| 315 | + return (new PayPalData()) |
|
| 316 | + ->setPayerId($data['paypal_payer_id'] ?? '') |
|
| 317 | + ->setSubscriberId($data['paypal_subscr_id'] ?? '') |
|
| 318 | + ->setPayerStatus($data['paypal_payer_status'] ?? '') |
|
| 319 | + ->setAddressStatus($data['paypal_address_status'] ?? '') |
|
| 320 | + ->setAmount(Euro::newFromString($data['paypal_mc_gross'] ?? '0')) |
|
| 321 | + ->setCurrencyCode($data['paypal_mc_currency'] ?? '') |
|
| 322 | + ->setFee(Euro::newFromString($data['paypal_mc_fee'] ?? '0')) |
|
| 323 | + ->setSettleAmount(Euro::newFromString($data['paypal_settle_amount'] ?? '0')) |
|
| 324 | + ->setFirstName($data['paypal_first_name'] ?? '') |
|
| 325 | + ->setLastName($data['paypal_last_name'] ?? '') |
|
| 326 | + ->setAddressName($data['paypal_address_name'] ?? '') |
|
| 327 | + ->setPaymentId($data['ext_payment_id'] ?? '') |
|
| 328 | + ->setPaymentType($data['ext_payment_type'] ?? '') |
|
| 329 | + ->setPaymentStatus($data['ext_payment_status'] ?? '') |
|
| 330 | + ->setPaymentTimestamp($data['ext_payment_timestamp'] ?? '') |
|
| 331 | + ->setFirstPaymentDate($data['first_payment_date'] ?? '') |
|
| 332 | 332 | ->freeze()->assertNoNullFields(); |
| 333 | 333 | } |
| 334 | 334 | |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | public function storeApplication( Application $application ): void { |
| 44 | 44 | if ( $application->hasId() ) { |
| 45 | 45 | $this->updateApplication( $application ); |
| 46 | - } |
|
| 47 | - else { |
|
| 46 | + } else { |
|
| 48 | 47 | $this->insertApplication( $application ); |
| 49 | 48 | } |
| 50 | 49 | } |
@@ -56,8 +55,7 @@ discard block |
||
| 56 | 55 | try { |
| 57 | 56 | $this->entityManager->persist( $doctrineApplication ); |
| 58 | 57 | $this->entityManager->flush(); |
| 59 | - } |
|
| 60 | - catch ( ORMException $ex ) { |
|
| 58 | + } catch ( ORMException $ex ) { |
|
| 61 | 59 | throw new StoreMembershipApplicationException( $ex ); |
| 62 | 60 | } |
| 63 | 61 | |
@@ -76,8 +74,7 @@ discard block |
||
| 76 | 74 | try { |
| 77 | 75 | $this->entityManager->persist( $doctrineApplication ); |
| 78 | 76 | $this->entityManager->flush(); |
| 79 | - } |
|
| 80 | - catch ( ORMException $ex ) { |
|
| 77 | + } catch ( ORMException $ex ) { |
|
| 81 | 78 | throw new StoreMembershipApplicationException( $ex ); |
| 82 | 79 | } |
| 83 | 80 | } |
@@ -209,8 +206,7 @@ discard block |
||
| 209 | 206 | public function getApplicationById( int $id ): ?Application { |
| 210 | 207 | try { |
| 211 | 208 | $application = $this->getDoctrineApplicationById( $id ); |
| 212 | - } |
|
| 213 | - catch ( ORMException $ex ) { |
|
| 209 | + } catch ( ORMException $ex ) { |
|
| 214 | 210 | throw new GetMembershipApplicationException( null, $ex ); |
| 215 | 211 | } |
| 216 | 212 | |
@@ -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\MembershipContext\UseCases\ShowApplicationConfirmation; |
| 6 | 6 | |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | return new self(); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public static function newValidResponse( Application $membershipApplication, string $updateToken ): self { |
|
| 23 | - return new self( $membershipApplication, $updateToken ); |
|
| 22 | + public static function newValidResponse(Application $membershipApplication, string $updateToken): self { |
|
| 23 | + return new self($membershipApplication, $updateToken); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - private function __construct( Application $membershipApplication = null, string $updateToken = null ) { |
|
| 26 | + private function __construct(Application $membershipApplication = null, string $updateToken = null) { |
|
| 27 | 27 | $this->membershipApplication = $membershipApplication; |
| 28 | 28 | $this->updateToken = $updateToken; |
| 29 | 29 | } |
@@ -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\MembershipContext\UseCases\ShowApplicationConfirmation; |
| 6 | 6 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | private $applicationId; |
| 14 | 14 | |
| 15 | - public function __construct( int $applicationId ) { |
|
| 15 | + public function __construct(int $applicationId) { |
|
| 16 | 16 | $this->applicationId = $applicationId; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -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\MembershipContext\Tests\Integration\DataAccess; |
| 6 | 6 | |
@@ -40,141 +40,141 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function testValidMembershipApplicationGetPersisted(): void { |
| 43 | - $this->newRepository()->storeApplication( ValidMembershipApplication::newDomainEntity() ); |
|
| 43 | + $this->newRepository()->storeApplication(ValidMembershipApplication::newDomainEntity()); |
|
| 44 | 44 | |
| 45 | 45 | $expectedDoctrineEntity = ValidMembershipApplication::newDoctrineEntity(); |
| 46 | - $expectedDoctrineEntity->setId( self::MEMBERSHIP_APPLICATION_ID ); |
|
| 46 | + $expectedDoctrineEntity->setId(self::MEMBERSHIP_APPLICATION_ID); |
|
| 47 | 47 | |
| 48 | - $this->assertDoctrineEntityIsInDatabase( $expectedDoctrineEntity ); |
|
| 48 | + $this->assertDoctrineEntityIsInDatabase($expectedDoctrineEntity); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private function newRepository(): ApplicationRepository { |
| 52 | - return new DoctrineApplicationRepository( $this->entityManager ); |
|
| 52 | + return new DoctrineApplicationRepository($this->entityManager); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function assertDoctrineEntityIsInDatabase( DoctrineApplication $expected ): void { |
|
| 56 | - $actual = $this->getApplicationFromDatabase( $expected->getId() ); |
|
| 55 | + private function assertDoctrineEntityIsInDatabase(DoctrineApplication $expected): void { |
|
| 56 | + $actual = $this->getApplicationFromDatabase($expected->getId()); |
|
| 57 | 57 | |
| 58 | - $this->assertNotNull( $actual->getCreationTime() ); |
|
| 59 | - $actual->setCreationTime( null ); |
|
| 58 | + $this->assertNotNull($actual->getCreationTime()); |
|
| 59 | + $actual->setCreationTime(null); |
|
| 60 | 60 | |
| 61 | - $this->assertEquals( $expected->getDecodedData(), $actual->getDecodedData() ); |
|
| 61 | + $this->assertEquals($expected->getDecodedData(), $actual->getDecodedData()); |
|
| 62 | 62 | |
| 63 | - $this->assertEquals( $expected, $actual ); |
|
| 63 | + $this->assertEquals($expected, $actual); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - private function getApplicationFromDatabase( int $id ): DoctrineApplication { |
|
| 67 | - $applicationRepo = $this->entityManager->getRepository( DoctrineApplication::class ); |
|
| 68 | - $donation = $applicationRepo->find( $id ); |
|
| 69 | - $this->assertInstanceOf( DoctrineApplication::class, $donation ); |
|
| 66 | + private function getApplicationFromDatabase(int $id): DoctrineApplication { |
|
| 67 | + $applicationRepo = $this->entityManager->getRepository(DoctrineApplication::class); |
|
| 68 | + $donation = $applicationRepo->find($id); |
|
| 69 | + $this->assertInstanceOf(DoctrineApplication::class, $donation); |
|
| 70 | 70 | return $donation; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function testIdGetsAssigned(): void { |
| 74 | 74 | $application = ValidMembershipApplication::newDomainEntity(); |
| 75 | 75 | |
| 76 | - $this->newRepository()->storeApplication( $application ); |
|
| 76 | + $this->newRepository()->storeApplication($application); |
|
| 77 | 77 | |
| 78 | - $this->assertSame( self::MEMBERSHIP_APPLICATION_ID, $application->getId() ); |
|
| 78 | + $this->assertSame(self::MEMBERSHIP_APPLICATION_ID, $application->getId()); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function testWhenPersistenceFails_domainExceptionIsThrown(): void { |
| 82 | 82 | $donation = ValidMembershipApplication::newDomainEntity(); |
| 83 | 83 | |
| 84 | - $repository = new DoctrineApplicationRepository( ThrowingEntityManager::newInstance( $this ) ); |
|
| 84 | + $repository = new DoctrineApplicationRepository(ThrowingEntityManager::newInstance($this)); |
|
| 85 | 85 | |
| 86 | - $this->expectException( StoreMembershipApplicationException::class ); |
|
| 87 | - $repository->storeApplication( $donation ); |
|
| 86 | + $this->expectException(StoreMembershipApplicationException::class); |
|
| 87 | + $repository->storeApplication($donation); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function testWhenMembershipApplicationInDatabase_itIsReturnedAsMatchingDomainEntity(): void { |
| 91 | - $this->storeDoctrineApplication( ValidMembershipApplication::newDoctrineEntity() ); |
|
| 91 | + $this->storeDoctrineApplication(ValidMembershipApplication::newDoctrineEntity()); |
|
| 92 | 92 | |
| 93 | 93 | $expected = ValidMembershipApplication::newAutoConfirmedDomainEntity(); |
| 94 | - $expected->assignId( self::MEMBERSHIP_APPLICATION_ID ); |
|
| 94 | + $expected->assignId(self::MEMBERSHIP_APPLICATION_ID); |
|
| 95 | 95 | |
| 96 | 96 | $this->assertEquals( |
| 97 | 97 | $expected, |
| 98 | - $this->newRepository()->getApplicationById( self::MEMBERSHIP_APPLICATION_ID ) |
|
| 98 | + $this->newRepository()->getApplicationById(self::MEMBERSHIP_APPLICATION_ID) |
|
| 99 | 99 | ); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - private function storeDoctrineApplication( DoctrineApplication $application ): void { |
|
| 103 | - $this->entityManager->persist( $application ); |
|
| 102 | + private function storeDoctrineApplication(DoctrineApplication $application): void { |
|
| 103 | + $this->entityManager->persist($application); |
|
| 104 | 104 | $this->entityManager->flush(); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | public function testWhenEntityDoesNotExist_getEntityReturnsNull(): void { |
| 108 | - $this->assertNull( $this->newRepository()->getApplicationById( self::ID_OF_APPLICATION_NOT_IN_DB ) ); |
|
| 108 | + $this->assertNull($this->newRepository()->getApplicationById(self::ID_OF_APPLICATION_NOT_IN_DB)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | public function testWhenReadFails_domainExceptionIsThrown(): void { |
| 112 | - $repository = new DoctrineApplicationRepository( ThrowingEntityManager::newInstance( $this ) ); |
|
| 112 | + $repository = new DoctrineApplicationRepository(ThrowingEntityManager::newInstance($this)); |
|
| 113 | 113 | |
| 114 | - $this->expectException( GetMembershipApplicationException::class ); |
|
| 115 | - $repository->getApplicationById( self::ID_OF_APPLICATION_NOT_IN_DB ); |
|
| 114 | + $this->expectException(GetMembershipApplicationException::class); |
|
| 115 | + $repository->getApplicationById(self::ID_OF_APPLICATION_NOT_IN_DB); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | public function testWhenApplicationAlreadyExists_persistingCausesUpdate(): void { |
| 119 | 119 | $repository = $this->newRepository(); |
| 120 | 120 | $originalApplication = ValidMembershipApplication::newDomainEntity(); |
| 121 | 121 | |
| 122 | - $repository->storeApplication( $originalApplication ); |
|
| 122 | + $repository->storeApplication($originalApplication); |
|
| 123 | 123 | |
| 124 | 124 | // It is important a new instance is created here to test "detached entity" handling |
| 125 | 125 | $newApplication = ValidMembershipApplication::newDomainEntity(); |
| 126 | - $newApplication->assignId( $originalApplication->getId() ); |
|
| 127 | - $newApplication->getApplicant()->changeEmailAddress( new EmailAddress( '[email protected]' ) ); |
|
| 126 | + $newApplication->assignId($originalApplication->getId()); |
|
| 127 | + $newApplication->getApplicant()->changeEmailAddress(new EmailAddress('[email protected]')); |
|
| 128 | 128 | |
| 129 | - $repository->storeApplication( $newApplication ); |
|
| 129 | + $repository->storeApplication($newApplication); |
|
| 130 | 130 | |
| 131 | - $doctrineApplication = $this->getApplicationFromDatabase( $newApplication->getId() ); |
|
| 131 | + $doctrineApplication = $this->getApplicationFromDatabase($newApplication->getId()); |
|
| 132 | 132 | |
| 133 | - $this->assertSame( '[email protected]', $doctrineApplication->getApplicantEmailAddress() ); |
|
| 133 | + $this->assertSame('[email protected]', $doctrineApplication->getApplicantEmailAddress()); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public function testWriteAndReadRoundtrip(): void { |
| 137 | 137 | $repository = $this->newRepository(); |
| 138 | 138 | $application = ValidMembershipApplication::newAutoConfirmedDomainEntity(); |
| 139 | 139 | |
| 140 | - $repository->storeApplication( $application ); |
|
| 140 | + $repository->storeApplication($application); |
|
| 141 | 141 | |
| 142 | 142 | $this->assertEquals( |
| 143 | 143 | $application, |
| 144 | - $repository->getApplicationById( self::MEMBERSHIP_APPLICATION_ID ) |
|
| 144 | + $repository->getApplicationById(self::MEMBERSHIP_APPLICATION_ID) |
|
| 145 | 145 | ); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | public function testWhenPersistingDeletedApplication_exceptionIsThrown(): void { |
| 149 | 149 | $application = ValidMembershipApplication::newDomainEntity(); |
| 150 | - $application->assignId( self::ID_OF_APPLICATION_NOT_IN_DB ); |
|
| 150 | + $application->assignId(self::ID_OF_APPLICATION_NOT_IN_DB); |
|
| 151 | 151 | |
| 152 | 152 | $repository = $this->newRepository(); |
| 153 | 153 | |
| 154 | - $this->expectException( StoreMembershipApplicationException::class ); |
|
| 155 | - $repository->storeApplication( $application ); |
|
| 154 | + $this->expectException(StoreMembershipApplicationException::class); |
|
| 155 | + $repository->storeApplication($application); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | public function testWhenPersistingApplicationWithModerationFlag_doctrineApplicationHasFlag(): void { |
| 159 | 159 | $application = ValidMembershipApplication::newDomainEntity(); |
| 160 | 160 | $application->markForModeration(); |
| 161 | 161 | |
| 162 | - $this->newRepository()->storeApplication( $application ); |
|
| 163 | - $doctrineApplication = $this->getApplicationFromDatabase( $application->getId() ); |
|
| 162 | + $this->newRepository()->storeApplication($application); |
|
| 163 | + $doctrineApplication = $this->getApplicationFromDatabase($application->getId()); |
|
| 164 | 164 | |
| 165 | - $this->assertTrue( $doctrineApplication->needsModeration() ); |
|
| 166 | - $this->assertFalse( $doctrineApplication->isCancelled() ); |
|
| 165 | + $this->assertTrue($doctrineApplication->needsModeration()); |
|
| 166 | + $this->assertFalse($doctrineApplication->isCancelled()); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | public function testWhenPersistingApplicationWithCancelledFlag_doctrineApplicationHasFlag(): void { |
| 170 | 170 | $application = ValidMembershipApplication::newDomainEntity(); |
| 171 | 171 | $application->cancel(); |
| 172 | 172 | |
| 173 | - $this->newRepository()->storeApplication( $application ); |
|
| 174 | - $doctrineApplication = $this->getApplicationFromDatabase( $application->getId() ); |
|
| 173 | + $this->newRepository()->storeApplication($application); |
|
| 174 | + $doctrineApplication = $this->getApplicationFromDatabase($application->getId()); |
|
| 175 | 175 | |
| 176 | - $this->assertFalse( $doctrineApplication->needsModeration() ); |
|
| 177 | - $this->assertTrue( $doctrineApplication->isCancelled() ); |
|
| 176 | + $this->assertFalse($doctrineApplication->needsModeration()); |
|
| 177 | + $this->assertTrue($doctrineApplication->isCancelled()); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function testWhenPersistingCancelledModerationApplication_doctrineApplicationHasFlags(): void { |
@@ -182,76 +182,76 @@ discard block |
||
| 182 | 182 | $application->markForModeration(); |
| 183 | 183 | $application->cancel(); |
| 184 | 184 | |
| 185 | - $this->newRepository()->storeApplication( $application ); |
|
| 186 | - $doctrineApplication = $this->getApplicationFromDatabase( $application->getId() ); |
|
| 185 | + $this->newRepository()->storeApplication($application); |
|
| 186 | + $doctrineApplication = $this->getApplicationFromDatabase($application->getId()); |
|
| 187 | 187 | |
| 188 | - $this->assertTrue( $doctrineApplication->needsModeration() ); |
|
| 189 | - $this->assertTrue( $doctrineApplication->isCancelled() ); |
|
| 188 | + $this->assertTrue($doctrineApplication->needsModeration()); |
|
| 189 | + $this->assertTrue($doctrineApplication->isCancelled()); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | public function testGivenDoctrineApplicationWithModerationAndCancelled_domainEntityHasFlags(): void { |
| 193 | 193 | $doctrineApplication = ValidMembershipApplication::newDoctrineEntity(); |
| 194 | - $doctrineApplication->setStatus( DoctrineApplication::STATUS_CANCELED + DoctrineApplication::STATUS_MODERATION ); |
|
| 194 | + $doctrineApplication->setStatus(DoctrineApplication::STATUS_CANCELED + DoctrineApplication::STATUS_MODERATION); |
|
| 195 | 195 | |
| 196 | - $this->storeDoctrineApplication( $doctrineApplication ); |
|
| 197 | - $application = $this->newRepository()->getApplicationById( $doctrineApplication->getId() ); |
|
| 196 | + $this->storeDoctrineApplication($doctrineApplication); |
|
| 197 | + $application = $this->newRepository()->getApplicationById($doctrineApplication->getId()); |
|
| 198 | 198 | |
| 199 | - $this->assertTrue( $application->needsModeration() ); |
|
| 200 | - $this->assertTrue( $application->isCancelled() ); |
|
| 199 | + $this->assertTrue($application->needsModeration()); |
|
| 200 | + $this->assertTrue($application->isCancelled()); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | public function testGivenDoctrineApplicationWithModerationFlag_domainEntityHasFlag(): void { |
| 204 | 204 | $doctrineApplication = ValidMembershipApplication::newDoctrineEntity(); |
| 205 | - $doctrineApplication->setStatus( DoctrineApplication::STATUS_MODERATION ); |
|
| 205 | + $doctrineApplication->setStatus(DoctrineApplication::STATUS_MODERATION); |
|
| 206 | 206 | |
| 207 | - $this->storeDoctrineApplication( $doctrineApplication ); |
|
| 208 | - $application = $this->newRepository()->getApplicationById( $doctrineApplication->getId() ); |
|
| 207 | + $this->storeDoctrineApplication($doctrineApplication); |
|
| 208 | + $application = $this->newRepository()->getApplicationById($doctrineApplication->getId()); |
|
| 209 | 209 | |
| 210 | - $this->assertTrue( $application->needsModeration() ); |
|
| 211 | - $this->assertFalse( $application->isCancelled() ); |
|
| 210 | + $this->assertTrue($application->needsModeration()); |
|
| 211 | + $this->assertFalse($application->isCancelled()); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | public function testGivenDoctrineApplicationWithCancelledFlag_domainEntityHasFlag(): void { |
| 215 | 215 | $doctrineApplication = ValidMembershipApplication::newDoctrineEntity(); |
| 216 | - $doctrineApplication->setStatus( DoctrineApplication::STATUS_CANCELED ); |
|
| 216 | + $doctrineApplication->setStatus(DoctrineApplication::STATUS_CANCELED); |
|
| 217 | 217 | |
| 218 | - $this->storeDoctrineApplication( $doctrineApplication ); |
|
| 219 | - $application = $this->newRepository()->getApplicationById( $doctrineApplication->getId() ); |
|
| 218 | + $this->storeDoctrineApplication($doctrineApplication); |
|
| 219 | + $application = $this->newRepository()->getApplicationById($doctrineApplication->getId()); |
|
| 220 | 220 | |
| 221 | - $this->assertFalse( $application->needsModeration() ); |
|
| 222 | - $this->assertTrue( $application->isCancelled() ); |
|
| 221 | + $this->assertFalse($application->needsModeration()); |
|
| 222 | + $this->assertTrue($application->isCancelled()); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | public function testGivenDoctrineApplicationWithCancelledFlag_initialStatusIsPreserved(): void { |
| 226 | 226 | $application = ValidMembershipApplication::newDomainEntity(); |
| 227 | 227 | $application->cancel(); |
| 228 | 228 | |
| 229 | - $this->newRepository()->storeApplication( $application ); |
|
| 230 | - $doctrineApplication = $this->getApplicationFromDatabase( $application->getId() ); |
|
| 229 | + $this->newRepository()->storeApplication($application); |
|
| 230 | + $doctrineApplication = $this->getApplicationFromDatabase($application->getId()); |
|
| 231 | 231 | |
| 232 | - $this->assertSame( DoctrineApplication::STATUS_CONFIRMED, $doctrineApplication->getDataObject()->getPreservedStatus() ); |
|
| 232 | + $this->assertSame(DoctrineApplication::STATUS_CONFIRMED, $doctrineApplication->getDataObject()->getPreservedStatus()); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public function testGivenCompanyApplication_companyNameIsPersisted(): void { |
| 236 | - $this->newRepository()->storeApplication( ValidMembershipApplication::newCompanyApplication() ); |
|
| 236 | + $this->newRepository()->storeApplication(ValidMembershipApplication::newCompanyApplication()); |
|
| 237 | 237 | |
| 238 | 238 | $expectedDoctrineEntity = ValidMembershipApplication::newDoctrineCompanyEntity(); |
| 239 | - $expectedDoctrineEntity->setId( self::MEMBERSHIP_APPLICATION_ID ); |
|
| 239 | + $expectedDoctrineEntity->setId(self::MEMBERSHIP_APPLICATION_ID); |
|
| 240 | 240 | |
| 241 | - $this->assertDoctrineEntityIsInDatabase( $expectedDoctrineEntity ); |
|
| 241 | + $this->assertDoctrineEntityIsInDatabase($expectedDoctrineEntity); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | public function testReadingPurgedApplication_purgedExceptionIsThrown(): void { |
| 245 | - $this->storeDoctrineApplication( $this->newPurgedApplication() ); |
|
| 245 | + $this->storeDoctrineApplication($this->newPurgedApplication()); |
|
| 246 | 246 | |
| 247 | - $this->expectException( ApplicationPurgedException::class ); |
|
| 247 | + $this->expectException(ApplicationPurgedException::class); |
|
| 248 | 248 | |
| 249 | - $this->newRepository()->getApplicationById( self::MEMBERSHIP_APPLICATION_ID ); |
|
| 249 | + $this->newRepository()->getApplicationById(self::MEMBERSHIP_APPLICATION_ID); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | private function newPurgedApplication(): DoctrineApplication { |
| 253 | 253 | $application = ValidMembershipApplication::newDoctrineEntity(); |
| 254 | - $application->setBackup( new \DateTime() ); |
|
| 254 | + $application->setBackup(new \DateTime()); |
|
| 255 | 255 | return $application; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -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\MembershipContext\UseCases\ShowApplicationConfirmation; |
| 6 | 6 | |
@@ -21,39 +21,39 @@ discard block |
||
| 21 | 21 | private $repository; |
| 22 | 22 | private $tokenFetcher; |
| 23 | 23 | |
| 24 | - public function __construct( ShowApplicationConfirmationPresenter $presenter, ApplicationAuthorizer $authorizer, |
|
| 25 | - ApplicationRepository $repository, ApplicationTokenFetcher $tokenFetcher ) { |
|
| 24 | + public function __construct(ShowApplicationConfirmationPresenter $presenter, ApplicationAuthorizer $authorizer, |
|
| 25 | + ApplicationRepository $repository, ApplicationTokenFetcher $tokenFetcher) { |
|
| 26 | 26 | $this->presenter = $presenter; |
| 27 | 27 | $this->authorizer = $authorizer; |
| 28 | 28 | $this->repository = $repository; |
| 29 | 29 | $this->tokenFetcher = $tokenFetcher; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function showConfirmation( ShowAppConfirmationRequest $request ): void { |
|
| 33 | - if ( !$this->authorizer->canAccessApplication( $request->getApplicationId() ) ) { |
|
| 32 | + public function showConfirmation(ShowAppConfirmationRequest $request): void { |
|
| 33 | + if (!$this->authorizer->canAccessApplication($request->getApplicationId())) { |
|
| 34 | 34 | // TODO: show access error |
| 35 | - $this->presenter->presentResponseModel( ShowApplicationConfirmationResponse::newNotAllowedResponse() ); |
|
| 35 | + $this->presenter->presentResponseModel(ShowApplicationConfirmationResponse::newNotAllowedResponse()); |
|
| 36 | 36 | return; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | try { |
| 40 | - $application = $this->repository->getApplicationById( $request->getApplicationId() ); |
|
| 40 | + $application = $this->repository->getApplicationById($request->getApplicationId()); |
|
| 41 | 41 | } |
| 42 | - catch ( ApplicationPurgedException $ex ) { |
|
| 42 | + catch (ApplicationPurgedException $ex) { |
|
| 43 | 43 | // TODO: show application was purged |
| 44 | - $this->presenter->presentResponseModel( ShowApplicationConfirmationResponse::newNotAllowedResponse() ); |
|
| 44 | + $this->presenter->presentResponseModel(ShowApplicationConfirmationResponse::newNotAllowedResponse()); |
|
| 45 | 45 | return; |
| 46 | 46 | } |
| 47 | - catch ( GetMembershipApplicationException $ex ) { |
|
| 47 | + catch (GetMembershipApplicationException $ex) { |
|
| 48 | 48 | // TODO: show technical error |
| 49 | - $this->presenter->presentResponseModel( ShowApplicationConfirmationResponse::newNotAllowedResponse() ); |
|
| 49 | + $this->presenter->presentResponseModel(ShowApplicationConfirmationResponse::newNotAllowedResponse()); |
|
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $this->presenter->presentResponseModel( |
| 54 | 54 | ShowApplicationConfirmationResponse::newValidResponse( |
| 55 | 55 | $application, // TODO: use DTO instead of Entity (currently violates the architecture) |
| 56 | - $this->tokenFetcher->getTokens( $request->getApplicationId() )->getUpdateToken() |
|
| 56 | + $this->tokenFetcher->getTokens($request->getApplicationId())->getUpdateToken() |
|
| 57 | 57 | ) |
| 58 | 58 | ); |
| 59 | 59 | } |
@@ -38,13 +38,11 @@ |
||
| 38 | 38 | |
| 39 | 39 | try { |
| 40 | 40 | $application = $this->repository->getApplicationById( $request->getApplicationId() ); |
| 41 | - } |
|
| 42 | - catch ( ApplicationPurgedException $ex ) { |
|
| 41 | + } catch ( ApplicationPurgedException $ex ) { |
|
| 43 | 42 | // TODO: show application was purged |
| 44 | 43 | $this->presenter->presentResponseModel( ShowApplicationConfirmationResponse::newNotAllowedResponse() ); |
| 45 | 44 | return; |
| 46 | - } |
|
| 47 | - catch ( GetMembershipApplicationException $ex ) { |
|
| 45 | + } catch ( GetMembershipApplicationException $ex ) { |
|
| 48 | 46 | // TODO: show technical error |
| 49 | 47 | $this->presenter->presentResponseModel( ShowApplicationConfirmationResponse::newNotAllowedResponse() ); |
| 50 | 48 | return; |
@@ -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\MembershipContext\Tests\Integration\UseCases\ShowApplicationConfirmation; |
| 6 | 6 | |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | public function testWhenExceptionIsThrown_failureResponseIsReturned() { |
| 55 | 55 | $this->repository->throwOnRead(); |
| 56 | 56 | |
| 57 | - $request = new ShowAppConfirmationRequest( self::APPLICATION_ID ); |
|
| 58 | - $this->newUseCase()->showConfirmation( $request ); |
|
| 57 | + $request = new ShowAppConfirmationRequest(self::APPLICATION_ID); |
|
| 58 | + $this->newUseCase()->showConfirmation($request); |
|
| 59 | 59 | |
| 60 | - $this->assertFalse( $this->presenter->getResponseModel()->accessIsPermitted() ); |
|
| 61 | - $this->assertNull( $this->presenter->getResponseModel()->getApplication() ); |
|
| 60 | + $this->assertFalse($this->presenter->getResponseModel()->accessIsPermitted()); |
|
| 61 | + $this->assertNull($this->presenter->getResponseModel()->getApplication()); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | private function newUseCase(): ShowApplicationConfirmationUseCase { |
@@ -71,19 +71,19 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function testHappyPath_successResponseWithApplicationIsReturned() { |
| 74 | - $this->repository->storeApplication( $this->newApplication() ); |
|
| 74 | + $this->repository->storeApplication($this->newApplication()); |
|
| 75 | 75 | |
| 76 | - $request = new ShowAppConfirmationRequest( self::APPLICATION_ID ); |
|
| 77 | - $this->newUseCase()->showConfirmation( $request ); |
|
| 76 | + $request = new ShowAppConfirmationRequest(self::APPLICATION_ID); |
|
| 77 | + $this->newUseCase()->showConfirmation($request); |
|
| 78 | 78 | |
| 79 | - $this->assertTrue( $this->presenter->getResponseModel()->accessIsPermitted() ); |
|
| 80 | - $this->assertSame( self::APPLICATION_ID, $this->presenter->getResponseModel()->getApplication()->getId() ); |
|
| 79 | + $this->assertTrue($this->presenter->getResponseModel()->accessIsPermitted()); |
|
| 80 | + $this->assertSame(self::APPLICATION_ID, $this->presenter->getResponseModel()->getApplication()->getId()); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | private function newApplication(): Application { |
| 84 | 84 | $application = ValidMembershipApplication::newDomainEntity(); |
| 85 | 85 | |
| 86 | - $application->assignId( self::APPLICATION_ID ); |
|
| 86 | + $application->assignId(self::APPLICATION_ID); |
|
| 87 | 87 | |
| 88 | 88 | return $application; |
| 89 | 89 | } |
@@ -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\MembershipContext\Tests\Integration\UseCases\ShowApplicationConfirmation; |
| 6 | 6 | |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | private $responseModel; |
| 17 | 17 | |
| 18 | - public function presentResponseModel( ShowApplicationConfirmationResponse $response ): void { |
|
| 19 | - if ( $this->responseModel !== null ) { |
|
| 20 | - throw new \RuntimeException( 'Presenter should only be invoked once' ); |
|
| 18 | + public function presentResponseModel(ShowApplicationConfirmationResponse $response): void { |
|
| 19 | + if ($this->responseModel !== null) { |
|
| 20 | + throw new \RuntimeException('Presenter should only be invoked once'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | $this->responseModel = $response; |