public function getCheapestShippingMethod(array $shippingMethods)
    {
        return array_reduce(
            $shippingMethods,
            function ($lowestPriceShippingMethod, ShippingMethod $shippingMethod) {

                $shippingMethodPrice = $shippingMethod->getPrice();
                if (
                    !($lowestPriceShippingMethod instanceof ShippingMethod) ||
                    $shippingMethodPrice
                        ->isLessThan(
                            $this
                                ->currencyConverter
                                ->convertMoney(
                                    $lowestPriceShippingMethod->getPrice(),
                                    $shippingMethodPrice->getCurrency()
                                )
                        )
                ) {
                    return $shippingMethod;
                }

                return $lowestPriceShippingMethod;
            },
            null
        );
    }
public function getCheapestShippingMethod(array $shippingMethods)
    {
        return array_reduce(
            $shippingMethods,
            function ($lowestPriceShippingMethod, ShippingMethod $shippingMethod) {

                $shippingMethodPrice = $shippingMethod->getPrice();
                if (
                    !($lowestPriceShippingMethod instanceof ShippingMethod) ||
                    $shippingMethodPrice
                        ->isLessThan(
                            $this
                                ->currencyConverter
                                ->convertMoney(
                                    $lowestPriceShippingMethod->getPrice(),
                                    $shippingMethodPrice->getCurrency()
                                )
                        )
                ) {
                    return $shippingMethod;
                }

                return $lowestPriceShippingMethod;
            },
            null
        );
    }
public function getCheapestShippingMethod ( array $ shippingMethods ) { return array_reduce ( $ shippingMethods , function ( $ lowestPriceShippingMethod , ShippingMethod $ shippingMethod ) { $ shippingMethodPrice = $ shippingMethod -> getPrice ( ) ; if ( ! ( $ lowestPriceShippingMethod instanceof ShippingMethod ) || $ shippingMethodPrice -> isLessThan ( $ this -> currencyConverter -> convertMoney ( $ lowestPriceShippingMethod -> getPrice ( ) , $ shippingMethodPrice -> getCurrency ( ) ) ) ) { return $ shippingMethod ; } return $ lowestPriceShippingMethod ; } , null ) ; }
Given a set of shipping methods, return the one with the lowest price.

@param ShippingMethod[] $shippingMethods Shipping methods

@return ShippingMethod Lowest price shipping method
Given a set of shipping methods return the one with the lowest price .