Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix devision by zero PHP notice #27

Merged
merged 2 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/UseCases/ValidateMembershipFee/ValidateFeeResult.php
Expand Up @@ -7,6 +7,7 @@
class ValidateFeeResult {

public const ERROR_TOO_LOW = 'error-too-low';
public const ERROR_INTERVAL_INVALID = 'error-interval-invalid';

private $errorCode;

Expand All @@ -18,6 +19,10 @@ public static function newTooLowResponse(): self {
return self::newErrorResponse( self::ERROR_TOO_LOW );
}

public static function newIntervalInvalidResponse(): self {
return self::newErrorResponse( self::ERROR_INTERVAL_INVALID );
}

private static function newErrorResponse( string $errorCode ): self {
$result = new self();
$result->errorCode = $errorCode;
Expand Down
Expand Up @@ -28,6 +28,10 @@ public function validate( ValidateFeeRequest $request ): ValidateFeeResult {
$this->paymentIntervalInMonths = $request->getPaymentIntervalInMonths();
$this->applicantType = $request->getApplicantType();

if ( $this->paymentIntervalInMonths === 0 ) {
Copy link
Member

@gbirke gbirke Mar 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this < 1 instead, as negative intervals make no sense here, but are the default value on the client side (although wmde/fundraising-application#1452 makes sure we don't send it any more).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the test case if you do :)

return ValidateFeeResult::newIntervalInvalidResponse();
}

if ( $this->getYearlyPaymentAmount() < $this->getYearlyPaymentRequirement() ) {
return ValidateFeeResult::newTooLowResponse();
}
Expand Down
Expand Up @@ -107,4 +107,17 @@ public function testGivenInvalidCompanyAmount_validationFails(): void {
);
}

public function testGivenInvalidInterval_validationFails() {
$useCase = $this->newUseCase();

$response = $useCase->validate(
ValidateFeeRequest::newInstance()
->withFee( Euro::newFromString( '12.34' ) )
->withApplicantType( ValidateFeeRequest::PERSON_APPLICANT )
->withInterval( 0 )
);

$this->assertSame( ValidateFeeResult::ERROR_INTERVAL_INVALID, $response->getErrorCode() );
}

}