getFareAmount(); }, $fareList); return max($pricesArr); } /** * Fare Selection - Get fare with lowest price. * @param RoomFare[] $fareList List of fares. */ public static function selectFare_Lowest(array $fareList): int { $pricesArr = array_map(function (RoomFare $f) { return $f->getFareAmount(); }, $fareList); return min($pricesArr); } /** * Fare Selection - Get average price of given fares. * @param RoomFare[] $fareList List of fares. */ public static function selectFare_Average(array $fareList): int|null { $totalAmount = 0; $count = 0; foreach ($fareList as $fare) { $fareAmount = $fare->getFareAmount(); if ($fareAmount != null) { $totalAmount += $fareAmount; $count++; } } return $count > 0 ? ($totalAmount / $count) : null; } #endregion #region Price Selection /** * Price Method - Total price is the sum of daily prices. * @param array $prices * @return int Total price. */ public static function priceMethod_Sum(array $prices): int { $values = array_values($prices); return array_sum($values); } /** * Price Method - Apply the hightest daily price to all days. * @param array $prices * @return int Total price. */ public static function priceMethod_Highest(array $prices): int { $highestPrice = max($prices); $numDays = count($prices); return $numDays * $highestPrice; } /** * Price Method - Apply the lowest daily price to all days. * @param array $prices * @return int Total price. */ public static function priceMethod_Lowest(array $prices): int { $highestPrice = min($prices); $numDays = count($prices); return $numDays * $highestPrice; } /** * Price Method - Calculate average daily price and apply it to all days. * @param array $prices * @return int Total price. */ public static function priceMethod_Average(array $prices): int|null { $sum = array_sum($prices); $numDays = count($prices); $averagePrice = $numDays > 0 ? $sum / $numDays : null; return $averagePrice != null ? $averagePrice * $numDays : null; } #endregion }