Skip to content

Commit

Permalink
feat: add all dhl carriers (#446)
Browse files Browse the repository at this point in the history
* feat: add all dhl carriers

* fix conflict

* fix conflict

* fix failing tests

* refactor: indexing

* refactor: changed if

* refactor: feedback

* refactor: feedback

* refactor: feedback

* refactor: feedback

* refactor: fix test

* refactor: fix test

* refactor: feedback
  • Loading branch information
wthijmen committed Feb 24, 2023
1 parent 1f0445d commit 0d1cb21
Show file tree
Hide file tree
Showing 19 changed files with 629 additions and 16 deletions.
16 changes: 16 additions & 0 deletions src/Model/Carrier/AbstractCarrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ abstract class AbstractCarrier
*/
protected $name;

/**
* @var string
*/
protected $type;

/**
* @return class-string<\MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment>
*/
Expand Down Expand Up @@ -60,6 +65,17 @@ public function getName(): string
return $this->name;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @return bool
*/
public function isDropOffPointRequired(): bool
{
return false;
Expand Down
42 changes: 42 additions & 0 deletions src/Model/Carrier/CarrierDHLEuroplus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
use MyParcelNL\Sdk\src\Model\Consignment\DHLEuroplusConsignment;

class CarrierDHLEuroplus extends AbstractCarrier
{
public const CONSIGNMENT = DHLEuroplusConsignment::class;
public const HUMAN = 'DHL Europlus';
public const ID = 11;
public const NAME = 'dhleuroplus';
public const TYPE = AbstractConsignment::TYPE_B2B;

/**
* @var class-string
*/
protected $consignmentClass = self::CONSIGNMENT;

/**
* @var string
*/
protected $human = self::HUMAN;

/**
* @var int
*/
protected $id = self::ID;

/**
* @var string
*/
protected $name = self::NAME;

/**
* @var string
*/
protected $type = self::TYPE;
}
7 changes: 7 additions & 0 deletions src/Model/Carrier/CarrierDHLForYou.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
use MyParcelNL\Sdk\src\Model\Consignment\DHLForYouConsignment;

class CarrierDHLForYou extends AbstractCarrier
Expand All @@ -12,6 +13,7 @@ class CarrierDHLForYou extends AbstractCarrier
public const HUMAN = 'DHL For You Vandaag';
public const ID = 9;
public const NAME = 'dhlforyou';
public const TYPE = AbstractConsignment::TYPE_B2C;

/**
* @var class-string
Expand All @@ -32,4 +34,9 @@ class CarrierDHLForYou extends AbstractCarrier
* @var string
*/
protected $name = self::NAME;

/**
* @var string
*/
protected $type = self::TYPE;
}
42 changes: 42 additions & 0 deletions src/Model/Carrier/CarrierDHLParcelConnect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
use MyParcelNL\Sdk\src\Model\Consignment\DHLParcelConnectConsignment;

class CarrierDHLParcelConnect extends AbstractCarrier
{
public const CONSIGNMENT = DHLParcelConnectConsignment::class;
public const HUMAN = 'DHL Parcel Connect';
public const ID = 10;
public const NAME = 'dhlparcelconnect';
public const TYPE = AbstractConsignment::TYPE_B2C;

/**
* @var class-string
*/
protected $consignmentClass = self::CONSIGNMENT;

/**
* @var string
*/
protected $human = self::HUMAN;

/**
* @var int
*/
protected $id = self::ID;

/**
* @var string
*/
protected $name = self::NAME;

/**
* @var string
*/
protected $type = self::TYPE;
}
2 changes: 2 additions & 0 deletions src/Model/Carrier/CarrierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CarrierFactory
CarrierPostNL::class,
CarrierInstabox::class,
CarrierDHLForYou::class,
CarrierDHLParcelConnect::class,
CarrierDHLEuroplus::class
];

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Model/Consignment/AbstractConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ abstract class AbstractConsignment
public const CC_NL = 'NL';
public const CC_BE = 'BE';

public const TYPE_B2C = 'b2c';
public const TYPE_B2B = 'b2b';

public const EURO_COUNTRIES = [
'NL',
'BE',
Expand Down
78 changes: 78 additions & 0 deletions src/Model/Consignment/DHLEuroplusConsignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLEuroplus;
use MyParcelNL\Sdk\src\Validator\Consignment\DHLEuroplusConsignmentValidator;

class DHLEuroplusConsignment extends AbstractConsignment
{
/**
* @var string
*/
protected $carrierClass = CarrierDHLEuroplus::class;

/**
* @var string
*/
protected $validatorClass = DHLEuroplusConsignmentValidator::class;

/**
* @return string[]
*/
public function getAllowedDeliveryTypes(): array
{
return [
self::DELIVERY_TYPE_STANDARD_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedPackageTypes(): array
{
return [
self::PACKAGE_TYPE_PACKAGE_NAME,
self::PACKAGE_TYPE_MAILBOX_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedShipmentOptions(): array
{
return [
self::SHIPMENT_OPTION_INSURANCE,
self::SHIPMENT_OPTION_SIGNATURE,
self::EXTRA_OPTION_DELIVERY_SATURDAY
];
}

/**
* @return string
*/
public function getLocalCountryCode(): string
{
return self::CC_NL;
}

/**
* @return int[]
*/
protected function getLocalInsurancePossibilities(): array
{
return [500, 1000, 5000];
}

/**
* @return int[]
*/
protected function getEuInsurancePossibilities(): array
{
return [500, 1000, 5000];
}
}
14 changes: 14 additions & 0 deletions src/Model/Consignment/DHLForYouConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public function getAllowedShipmentOptions(): array
];
}

/**
* @return array|string[]
*/
public function getAllowedShipmentOptionsForPickup(): array
{
return [
self::SHIPMENT_OPTION_AGE_CHECK,
self::SHIPMENT_OPTION_HIDE_SENDER,
self::SHIPMENT_OPTION_INSURANCE,
self::SHIPMENT_OPTION_ONLY_RECIPIENT,
self::SHIPMENT_OPTION_SIGNATURE,
];
}

/**
* @return string
*/
Expand Down
80 changes: 80 additions & 0 deletions src/Model/Consignment/DHLParcelConnectConsignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLParcelConnect;
use MyParcelNL\Sdk\src\Validator\Consignment\DHLParcelConnectConsignmentValidator;

class DHLParcelConnectConsignment extends AbstractConsignment
{
/**
* @var string
*/
protected $carrierClass = CarrierDHLParcelConnect::class;

/**
* @var string
*/
protected $validatorClass = DHLParcelConnectConsignmentValidator::class;

/**
* @return string[]
*/
public function getAllowedDeliveryTypes(): array
{
return [
self::DELIVERY_TYPE_STANDARD_NAME,
self::DELIVERY_TYPE_PICKUP_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedPackageTypes(): array
{
return [
self::PACKAGE_TYPE_PACKAGE_NAME,
self::PACKAGE_TYPE_MAILBOX_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedShipmentOptions(): array
{
return [
self::SHIPMENT_OPTION_INSURANCE,
self::SHIPMENT_OPTION_SIGNATURE,
];
}

/**
* @return array|string[]
*/
public function getAllowedShipmentOptionsForPickup(): array
{
return [
self::SHIPMENT_OPTION_SIGNATURE,
];
}

/**
* @return string
*/
public function getLocalCountryCode(): string
{
return self::CC_NL;
}

/**
* @return int[]
*/
protected function getLocalInsurancePossibilities(): array
{
return [500, 1000, 5000];
}
}
34 changes: 34 additions & 0 deletions src/Rule/Consignment/RestrictCountriesRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Rule\Consignment;

use MyParcelNL\Sdk\src\Rule\Rule;

class RestrictCountriesRule extends Rule
{
private $allowedCountries;

/**
* @param array $countries
*/
public function __construct(array $countries) {
$this->allowedCountries = $countries;
parent::__construct();
}

/**
* @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $validationSubject
*/
public function validate($validationSubject): void
{
if (in_array($validationSubject->getCountry(), $this->allowedCountries, true)) {
return;
}

$this->addError(
'Shipments are only allowed to the following countries: ' . implode(', ', $this->allowedCountries)
);
}
}

0 comments on commit 0d1cb21

Please sign in to comment.