| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class CarDeliveryConfig |
| 4 |
* |
| 5 |
* @package Packetery |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Packetery\Module\Carrier; |
| 9 |
|
| 10 |
use Packetery\Core\Entity\Carrier; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class CarDeliveryConfig |
| 14 |
* |
| 15 |
* @package Packetery |
| 16 |
*/ |
| 17 |
class CarDeliveryConfig { |
| 18 |
|
| 19 |
/** |
| 20 |
* True if sample mode enabled. |
| 21 |
* |
| 22 |
* @var bool |
| 23 |
*/ |
| 24 |
private $sample; |
| 25 |
|
| 26 |
/** |
| 27 |
* True if enabled. |
| 28 |
* |
| 29 |
* @var bool |
| 30 |
*/ |
| 31 |
private $enabled; |
| 32 |
|
| 33 |
/** |
| 34 |
* CarDeliveryConfig constructor. |
| 35 |
* |
| 36 |
* @param bool $sample Sample. |
| 37 |
* @param bool $enabled Enabled. |
| 38 |
*/ |
| 39 |
public function __construct( bool $sample, bool $enabled ) { |
| 40 |
$this->sample = $sample; |
| 41 |
$this->enabled = $enabled; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Tells whether the sample cars for Packeta CD are enabled, or not. |
| 46 |
* |
| 47 |
* @return bool |
| 48 |
*/ |
| 49 |
public function isSampleEnabled(): bool { |
| 50 |
return $this->sample; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Tells whether the car delivery is disabled, or otherwise. |
| 55 |
* |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
public function isDisabled(): bool { |
| 59 |
return ! $this->enabled; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Checks if carrier is car delivery carrier. |
| 64 |
* |
| 65 |
* @param string $carrierId Carrier ID. |
| 66 |
* |
| 67 |
* @return bool |
| 68 |
*/ |
| 69 |
public function isCarDeliveryCarrier( string $carrierId ): bool { |
| 70 |
return in_array( $carrierId, Carrier::CAR_DELIVERY_CARRIERS, true ); |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Checks if car delivery is disabled. |
| 75 |
* |
| 76 |
* @param string $carrierId Carrier ID. |
| 77 |
* |
| 78 |
* @return bool |
| 79 |
*/ |
| 80 |
public function isCarDeliveryCarrierDisabled( string $carrierId ): bool { |
| 81 |
return $this->isCarDeliveryCarrier( $carrierId ) && $this->isDisabled(); |
| 82 |
} |
| 83 |
} |
| 84 |
|