Created
April 2, 2021 13:39
-
-
Save vanbrabantf/f1ab01d40d2e43e785fb77bcdfbc83b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Car\Rent; | |
final class PriceCalculator | |
{ | |
public function calculate(CarRental $carRental): int | |
{ | |
$startDate = $carRental->getStartDate(); | |
$endDate = $carRental->getEndDate(); | |
$days = $startDate->diff($endDate); | |
$dayPrice = $days * $carRental->getPricePerDay(); | |
return $dayPrice + ($carRental->getDistance() * $carRental->getPricePerKm()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment