Skip to content

Commit

Permalink
Refactor carrier/service type, add test for branch service
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Jul 28, 2022
1 parent daa56c4 commit def2fbf
Show file tree
Hide file tree
Showing 179 changed files with 5,192 additions and 5,571 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ext-json": "*",
"psr/http-message": "^1.0",
"guzzlehttp/psr7": "^2.0",
"inspirum/arrayable": "^1.0"
"inspirum/arrayable": "^1.1"
},
"require-dev": {
"inspirum/coding-standard": "^1.1",
Expand Down
4 changes: 3 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
<arg value="sp"/>
<file>src</file>
<file>tests</file>
<rule ref="InspirumCodingStandard"/>
<rule ref="InspirumCodingStandard" >
<exclude name="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment"/>
</rule>
</ruleset>
3 changes: 1 addition & 2 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Inspirum\Balikobot\Client;

use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Method;
use Inspirum\Balikobot\Client\Request\Version;

Expand All @@ -21,7 +20,7 @@ interface Client
*/
public function call(
Version $version,
?Carrier $carrier,
?string $carrier,
Method $request,
array $data = [],
?string $path = null,
Expand Down
5 changes: 2 additions & 3 deletions src/Client/DefaultClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Inspirum\Balikobot\Client;

use GuzzleHttp\Psr7\InflateStream;
use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Method;
use Inspirum\Balikobot\Client\Request\Version;
use Inspirum\Balikobot\Client\Response\Validator;
Expand All @@ -30,14 +29,14 @@ public function __construct(
/** @inheritDoc */
public function call(
Version $version,
?Carrier $carrier,
?string $carrier,
Method $request,
array $data = [],
?string $path = null,
bool $shouldHaveStatus = true,
bool $gzip = false,
): array {
$url = $this->resolveUrl($version->getValue(), $carrier?->getValue(), $request->getValue(), $path, $gzip);
$url = $this->resolveUrl($version->getValue(), $carrier, $request->getValue(), $path, $gzip);

$response = $this->requester->request($url, $data);

Expand Down
10 changes: 0 additions & 10 deletions src/Client/Request/Carrier.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Client/Request/Service.php

This file was deleted.

135 changes: 1 addition & 134 deletions src/Definitions/Shipper.php → src/Definitions/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,245 +4,174 @@

namespace Inspirum\Balikobot\Definitions;

use InvalidArgumentException;
use function in_array;

final class Shipper
final class Carrier
{
/**
* Česká pošta
*
* @var string
*/
public const CP = 'cp';

/**
* DPD
*
* @var string
*/
public const DPD = 'dpd';

/**
* DHL Express
*
* @var string
*/
public const DHL = 'dhl';

/**
* Geis Cargo - paletová přeprava
*
* @var string
*/
public const GEIS = 'geis';

/**
* GLS
*
* @var string
*/
public const GLS = 'gls';

/**
* WE DO
*
* @var string
*/
public const INTIME = 'intime';

/**
* Pošta bez hranic
*
* @var string
*/
public const PBH = 'pbh';

/**
* PPL + DHL Freight
*
* @var string
*/
public const PPL = 'ppl';

/**
* Slovenská pošta
*
* @var string
*/
public const SP = 'sp';

/**
* Slovak Parcel Service
*
* @var string
*/
public const SPS = 'sps';

/**
* Toptrans
*
* @var string
*/
public const TOPTRANS = 'toptrans';

/**
* WE DO - Uloženka
*
* @var string
*/
public const ULOZENKA = 'ulozenka';

/**
* UPS
*
* @var string
*/
public const UPS = 'ups';

/**
* Zásilkovna
*
* @var string
*/
public const ZASILKOVNA = 'zasilkovna';

/**
* TNT
*
* @var string
*/
public const TNT = 'tnt';

/**
* Gebrüder Weiss Slovensko
*
* @var string
*/
public const GW = 'gw';

/**
* Gebrüder Weiss Česká republika
*
* @var string
*/
public const GWCZ = 'gwcz';

/**
* Messenger
*
* @var string
*/
public const MESSENGER = 'messenger';

/**
* DHL DE
*
* @var string
*/
public const DHLDE = 'dhlde';

/**
* FedEx
*
* @var string
*/
public const FEDEX = 'fedex';

/**
* Fofr
*
* @var string
*/
public const FOFR = 'fofr';

/**
* Dachser
*
* @var string
*/
public const DACHSER = 'dachser';

/**
* DHL Parcel Europe - PPL Parcel Connect EU
*
* @var string
*/
public const DHLPARCEL = 'dhlparcel';

/**
* Raben
*
* @var string
*/
public const RABEN = 'raben';

/**
* Spring
*
* @var string
*/
public const SPRING = 'spring';

/**
* Spring
*
* @var string
*/
public const DSV = 'dsv';

/**
* DHL Freight Euroconnect
*
* @var string
*/
public const DHLFREIGHTEC = 'dhlfreightec';

/**
* 123kurier
*
* @var string
*/
public const KURIER = 'kurier';

/**
* DB Schenker
*
* @var string
*/
public const DBSCHENKER = 'dbschenker';

/**
* AIRWAY
*
* @var string
*/
public const AIRWAY = 'airway';

/**
* JAPO Transport
*
* @var string
*/
public const JAPO = 'japo';

/**
* Liftago
*
* @var string
*/
public const LIFTAGO = 'liftago';

/**
* Magyar posta
*
* @var string
*/
public const MAGYARPOSTA = 'magyarposta';

/**
* All supported shipper services.
*
* @return array<string>
*/
public static function all(): array
Expand Down Expand Up @@ -283,66 +212,4 @@ public static function all(): array
self::MAGYARPOSTA,
];
}

/**
* Validate shipper code.
*
* @param string $code
*
* @return void
*
* @throws \InvalidArgumentException
*/
public static function validateCode(string $code): void
{
if (in_array($code, self::all()) === false) {
throw new InvalidArgumentException('Unknown shipper "' . $code . '".');
}
}

/**
* Determine if shipper service support full branch API
*
* @param string $shipperCode
* @param string|null $serviceCode
*
* @return bool
*/
public static function hasFullBranchesSupport(string $shipperCode, ?string $serviceCode): bool
{
if ($shipperCode === self::ZASILKOVNA) {
return true;
}

if ($shipperCode === self::CP && $serviceCode === ServiceType::CP_NP) {
return true;
}

$services = [ServiceType::PBH_MP, ServiceType::PBH_FAN_KURIER];

return $shipperCode === self::PBH && in_array($serviceCode, $services);
}

/**
* Determine if shipper has support to filter branches by country code.
*
* @param string $shipperCode
* @param string|null $serviceCode
*
* @return bool
*/
public static function hasBranchCountryFilterSupport(string $shipperCode, ?string $serviceCode): bool
{
if ($serviceCode === null) {
return true;
}

$supportedShippers = [
self::PPL,
self::DPD,
self::GLS,
];

return in_array($shipperCode, $supportedShippers);
}
}
Loading

0 comments on commit def2fbf

Please sign in to comment.