* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ declare(strict_types=1); namespace PrestaShop\PrestaShop\Adapter\Carrier; use Carrier; use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierException; use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierNotFoundException; use PrestaShop\PrestaShop\Core\Domain\Carrier\ValueObject\CarrierId; use PrestaShopException; /** * Provides reusable methods for carrier command/query handlers */ abstract class AbstractCarrierHandler { protected function getCarrier(CarrierId $carrierId) { try { $carrier = new Carrier($carrierId->getValue()); } catch (PrestaShopException $exception) { throw new CarrierException('Failed to create new carrier', 0, $exception); } if ($carrier->id !== $carrierId->getValue()) { throw new CarrierNotFoundException(sprintf('Carrier with id "%s" was not found', $carrierId->getValue())); } return $carrier; } }