Skip to content

Commit

Permalink
More tests for setting service
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Jul 21, 2022
1 parent d4730a5 commit 23ae365
Show file tree
Hide file tree
Showing 64 changed files with 1,500 additions and 2,890 deletions.
2 changes: 1 addition & 1 deletion src/Definitions/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ final class Option
public const REC_CITY = 'rec_city';

/**
* Delivery address postcode
* Delivery address zipcode
*
* @var string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Attribute/DefaultAttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function create(array $data): Attribute
return new Attribute(
$data['name'],
$data['data_type'],
$data['max_length'],
(string) $data['max_length'],
);
}

Expand Down
26 changes: 26 additions & 0 deletions src/Model/ManipulationUnit/DefaultManipulationUnitFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\ManipulationUnit;

use Inspirum\Balikobot\Client\Request\Carrier;
use function array_map;

final class DefaultManipulationUnitFactory implements ManipulationUnitFactory
{
/** @inheritDoc */
public function create(array $data): ManipulationUnit
{
return new ManipulationUnit((string) $data['code'], $data['name']);
}

/** @inheritDoc */
public function createCollection(Carrier $carrierType, array $data): ManipulationUnitCollection
{
return new ManipulationUnitCollection(
$carrierType,
array_map(fn(array $unit): ManipulationUnit => $this->create($unit), $data['units'] ?? []),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\Unit;
namespace Inspirum\Balikobot\Model\ManipulationUnit;

use Inspirum\Arrayable\BaseModel;

/**
* @extends \Inspirum\Arrayable\BaseModel<string,mixed>
*/
final class Unit extends BaseModel
final class ManipulationUnit extends BaseModel
{
public function __construct(
public readonly string $code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\Unit;
namespace Inspirum\Balikobot\Model\ManipulationUnit;

use Inspirum\Arrayable\BaseCollection;
use Inspirum\Balikobot\Client\Request\Carrier;

/**
* @extends \Inspirum\Arrayable\BaseCollection<string,mixed,int,\Inspirum\Balikobot\Model\Unit\Unit>
* @extends \Inspirum\Arrayable\BaseCollection<string,mixed,int,\Inspirum\Balikobot\Model\ManipulationUnit\ManipulationUnit>
*/
final class UnitCollection extends BaseCollection
final class ManipulationUnitCollection extends BaseCollection
{
/**
* @param array<int,\Inspirum\Balikobot\Model\Unit\Unit> $items
* @param array<int,\Inspirum\Balikobot\Model\ManipulationUnit\ManipulationUnit> $items
*/
public function __construct(
private Carrier $carrier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\Unit;
namespace Inspirum\Balikobot\Model\ManipulationUnit;

use Inspirum\Balikobot\Client\Request\Carrier;

interface UnitFactory
interface ManipulationUnitFactory
{
/**
* @param array<string,mixed> $data
*/
public function create(array $data): Unit;
public function create(array $data): ManipulationUnit;

/**
* @param array<string,mixed> $data
*/
public function createCollection(Carrier $carrierType, array $data): UnitCollection;
public function createCollection(Carrier $carrierType, array $data): ManipulationUnitCollection;
}
12 changes: 4 additions & 8 deletions src/Model/Service/DefaultServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ public function __construct(
public function create(Carrier $carrier, array $data): Service
{
return new Service(
$data['service_type'],
(string) $data['service_type'],
$data['service_type_name'] ?? ($data['name'] ?? null),
$this->createOptionCollection($carrier, $data),
array_key_exists('countries', $data)
? $this->countryFactory->createCodeCollection($data)
: null,
array_key_exists('cod_countries', $data)
? $this->countryFactory->createCodCountryCollection($data)
: null,
array_key_exists('services', $data) ? $this->createOptionCollection($carrier, $data) : null,
array_key_exists('countries', $data) ? $this->countryFactory->createCodeCollection($data) : null,
array_key_exists('cod_countries', $data) ? $this->countryFactory->createCodCountryCollection($data) : null,
);
}

Expand Down
10 changes: 6 additions & 4 deletions src/Model/Service/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace Inspirum\Balikobot\Model\Service;

use Inspirum\Arrayable\BaseModel;
use Inspirum\Balikobot\Client\Request\Service;
use Inspirum\Balikobot\Client\Request\Service as RequestService;
use Inspirum\Balikobot\Model\Country\CodCountry;
use function array_map;

/**
* @extends \Inspirum\Arrayable\BaseModel<string,mixed>
*/
final class Service extends BaseModel implements Service
final class Service extends BaseModel implements RequestService
{
/**
* @param array<string>|null $countries
Expand Down Expand Up @@ -41,9 +43,9 @@ public function __toArray(): array
return [
'type' => $this->type,
'name' => $this->name,
'options' => $this->options?->toArray(),
'options' => $this->options?->__toArray(),
'countries' => $this->countries,
'codCountries' => $this->codCountries,
'codCountries' => $this->codCountries !== null ? array_map(static fn(CodCountry $country): array => $country->__toArray(), $this->codCountries) : null,
];
}
}
12 changes: 1 addition & 11 deletions src/Model/Service/ServiceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Inspirum\Arrayable\BaseCollection;
use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Service;
use function array_map;

/**
* @extends \Inspirum\Arrayable\BaseCollection<string,mixed,int,\Inspirum\Balikobot\Model\Service\Service>
Expand All @@ -19,7 +17,7 @@ final class ServiceCollection extends BaseCollection
*/
public function __construct(
private readonly Carrier $carrier,
private readonly array $services,
readonly array $services,
private readonly ?bool $parcel = null,
private readonly ?bool $cargo = null,
) {
Expand All @@ -31,14 +29,6 @@ public function getCarrier(): Carrier
return $this->carrier;
}

/**
* @return array<\Inspirum\Balikobot\Client\Request\Service>
*/
public function getServiceTypes(): array
{
return array_map(static fn(Service $service): Service => $service, $this->services);
}

public function supportsParcel(): ?bool
{
return $this->parcel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function is_array;
use function is_string;

final class DefaultPackageStatusFactory implements PackageStatusFactory
final class DefaultStatusFactory implements StatusFactory
{
public function __construct(
private Validator $validator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Inspirum\Balikobot\Client\Request\Carrier;

interface PackageStatusFactory
interface StatusFactory
{
/**
* @param array<string,string|int|float> $data
Expand Down
26 changes: 0 additions & 26 deletions src/Model/Unit/DefaultUnitFactory.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\PostCode;
namespace Inspirum\Balikobot\Model\ZipCode;

use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Service;
use Iterator;

final class DefaultPostCodeFactory implements PostCodeFactory
final class DefaultZipCodeFactory implements ZipCodeFactory
{
/** @inheritDoc */
public function create(Carrier $carrier, ?Service $service, array $data): PostCode
public function create(Carrier $carrier, ?Service $service, array $data): ZipCode
{
return new PostCode(
return new ZipCode(
$carrier,
$service,
$data['postcode'],
$data['postcode_end'] ?? null,
$data['zip'] ?? ($data['zip_start'] ?? null),
$data['zip_end'] ?? null,
$data['city'] ?? null,
$data['country'] ?? null,
(bool) ($data['1B'] ?? false),
);
}

/** @inheritDoc */
public function createIterator(Carrier $carrier, ?Service $service, ?string $country, array $data): iterable
public function createIterator(Carrier $carrier, ?Service $service, ?string $country, array $data): Iterator
{
$country = $data['country'] ?? $country;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\PostCode;
namespace Inspirum\Balikobot\Model\ZipCode;

use Inspirum\Arrayable\BaseModel;
use Inspirum\Balikobot\Client\Request\Carrier;
Expand All @@ -11,13 +11,13 @@
/**
* @extends \Inspirum\Arrayable\BaseModel<string,mixed>
*/
class PostCode extends BaseModel
class ZipCode extends BaseModel
{
public function __construct(
public readonly Carrier $carrier,
public readonly ?Service $service,
public readonly string $postcode,
public readonly ?string $postcodeEnd,
public readonly ?string $zipCode,
public readonly ?string $zipCodeEnd,
public readonly ?string $city,
public readonly ?string $country,
public readonly bool $morningDelivery
Expand All @@ -29,9 +29,9 @@ public function __toArray(): array
{
return [
'carrier' => $this->carrier->getValue(),
'service' => $this->service,
'postcode' => $this->postcode,
'postcodeEnd' => $this->postcodeEnd,
'service' => $this->service?->getValue(),
'zipCode' => $this->zipCode,
'zipCodeEnt' => $this->zipCodeEnd,
'city' => $this->city,
'country' => $this->country,
'morningDelivery' => $this->morningDelivery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

declare(strict_types=1);

namespace Inspirum\Balikobot\Model\PostCode;
namespace Inspirum\Balikobot\Model\ZipCode;

use Inspirum\Balikobot\Client\Request\Carrier;
use Inspirum\Balikobot\Client\Request\Service;
use Iterator;

interface PostCodeFactory
interface ZipCodeFactory
{
/**
* @param array<string,string> $data
*/
public function create(Carrier $carrier, ?Service $service, array $data): PostCode;
public function create(Carrier $carrier, ?Service $service, array $data): ZipCode;

/**
* @param array<string,mixed> $data
*
* @return iterable<\Inspirum\Balikobot\Model\PostCode\PostCode>
* @return \Iterator<\Inspirum\Balikobot\Model\ZipCode\ZipCode>
*/
public function createIterator(Carrier $carrier, ?Service $service, ?string $country, array $data): iterable;
public function createIterator(Carrier $carrier, ?Service $service, ?string $country, array $data): Iterator;
}
2 changes: 1 addition & 1 deletion src/Service/BranchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getBranchesForLocation(
Carrier $carrier,
string $country,
string $city,
?string $postcode = null,
?string $zipCode = null,
?string $street = null,
?int $maxResults = null,
?float $radius = null,
Expand Down
Loading

0 comments on commit 23ae365

Please sign in to comment.