Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Composer
uses: php-actions/composer@v6
with:
Expand All @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Composer
uses: php-actions/composer@v6
with:
Expand All @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Composer
uses: php-actions/composer@v6
with:
Expand All @@ -50,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Composer
uses: php-actions/composer@v6
with:
Expand All @@ -61,3 +61,18 @@ jobs:
version: 9
php_version: 8.3
configuration: phpunit.xml
php84:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.4
- name: PHPUnit
uses: php-actions/phpunit@v4
with:
version: 9
php_version: 8.4
configuration: phpunit.xml
26 changes: 14 additions & 12 deletions src/MyParcelComApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class MyParcelComApi implements MyParcelComApiInterface
public static function createSingleton(
AuthenticatorInterface $authenticator,
string $apiUri = 'https://api.sandbox.myparcel.com',
ClientInterface $httpClient = null,
CacheInterface $cache = null,
ResourceFactoryInterface $resourceFactory = null,
?ClientInterface $httpClient = null,
?CacheInterface $cache = null,
?ResourceFactoryInterface $resourceFactory = null,
): self {
return self::$singleton = (new self($apiUri, $httpClient, $cache, $resourceFactory))
->authenticate($authenticator);
Expand All @@ -91,9 +91,9 @@ public static function getSingleton(): ?self
*/
public function __construct(
string $apiUri = 'https://api.sandbox.myparcel.com',
ClientInterface $httpClient = null,
CacheInterface $cache = null,
ResourceFactoryInterface $resourceFactory = null,
?ClientInterface $httpClient = null,
?CacheInterface $cache = null,
?ResourceFactoryInterface $resourceFactory = null,
) {
if ($httpClient === null) {
$httpClient = HttpClientDiscovery::find();
Expand Down Expand Up @@ -154,7 +154,7 @@ public function getPickUpDropOffLocations(
string $postalCode,
?string $streetName = null,
?string $streetNumber = null,
CarrierInterface $specificCarrier = null,
?CarrierInterface $specificCarrier = null,
bool $onlyActiveContracts = true,
int $ttl = self::TTL_10MIN,
?array $filters = null,
Expand Down Expand Up @@ -242,7 +242,7 @@ public function getDefaultShop(int $ttl = self::TTL_10MIN): ShopInterface
}

public function getServices(
ShipmentInterface $shipment = null,
?ShipmentInterface $shipment = null,
array $filters = ['has_active_contract' => 'true'],
int $ttl = self::TTL_10MIN,
): ResourceCollectionInterface {
Expand Down Expand Up @@ -453,8 +453,10 @@ public function resolveDynamicServiceRates(
return $this->jsonToResources($json['data'], $included);
}

public function getShipments(ShopInterface $shop = null, int $ttl = self::TTL_NO_CACHE): ResourceCollectionInterface
{
public function getShipments(
?ShopInterface $shop = null,
int $ttl = self::TTL_NO_CACHE
): ResourceCollectionInterface {
$url = new UrlBuilder($this->apiUri . self::PATH_SHIPMENTS);

$url->addQuery([
Expand Down Expand Up @@ -1337,7 +1339,7 @@ protected function sendResource(
return reset($resources);
}

protected function getResourceUri(string $resourceType, string $id = null): string
protected function getResourceUri(string $resourceType, ?string $id = null): string
{
return implode(
'/',
Expand Down Expand Up @@ -1384,7 +1386,7 @@ private function arrayToFilter(array &$filters, array $keys, mixed $value): void
*/
private function determineCarriersForPudoLocations(
bool $onlyActiveContracts,
CarrierInterface $specificCarrier = null,
?CarrierInterface $specificCarrier = null,
): array {
// If we're looking for a specific carrier but it doesn't
// matter if it has active contracts, just return it immediately.
Expand Down
6 changes: 3 additions & 3 deletions src/MyParcelComApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getPickUpDropOffLocations(
string $postalCode,
?string $streetName = null,
?string $streetNumber = null,
CarrierInterface $specificCarrier = null,
?CarrierInterface $specificCarrier = null,
bool $onlyActiveContracts = true,
int $ttl = self::TTL_10MIN,
?array $filters = null,
Expand Down Expand Up @@ -106,7 +106,7 @@ public function getDefaultShop(int $ttl = self::TTL_10MIN): ShopInterface;
* @throws MyParcelComException
*/
public function getServices(
ShipmentInterface $shipment = null,
?ShipmentInterface $shipment = null,
array $filters = ['has_active_contract' => 'true'],
int $ttl = self::TTL_10MIN,
): ResourceCollectionInterface;
Expand Down Expand Up @@ -158,7 +158,7 @@ public function resolveDynamicServiceRates(
* @throws MyParcelComException
*/
public function getShipments(
ShopInterface $shop = null,
?ShopInterface $shop = null,
int $ttl = self::TTL_NO_CACHE,
): ResourceCollectionInterface;

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Interfaces/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function addFile(FileInterface $file): self;
/**
* @return FileInterface[]
*/
public function getFiles(string $type = null): array;
public function getFiles(?string $type = null): array;

public function setShipmentStatus(ShipmentStatusInterface $status): self;

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Proxy/ShipmentProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function addFile(FileInterface $file): self
return $this;
}

public function getFiles(string $type = null): array
public function getFiles(?string $type = null): array
{
return $this->getResource()->getFiles($type);
}
Expand Down
29 changes: 29 additions & 0 deletions src/Resources/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MyParcelCom\ApiSdk\Resources\Interfaces\CarrierInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\ResourceInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\ServiceInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\ServiceOptionInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\ServiceRateInterface;
use MyParcelCom\ApiSdk\Resources\Traits\JsonSerializable;
use MyParcelCom\ApiSdk\Resources\Traits\ProcessIncludes;
Expand All @@ -33,9 +34,11 @@ class Service implements ServiceInterface
const ATTRIBUTE_VOLUMETRIC_WEIGHT_DIVISOR = 'volumetric_weight_divisor';

const RELATIONSHIP_CARRIER = 'carrier';
const RELATIONSHIP_SERVICE_OPTIONS = 'service_options';

const INCLUDES = [
ResourceInterface::TYPE_CARRIER => self::RELATIONSHIP_CARRIER,
ResourceInterface::TYPE_SERVICE_OPTION => self::RELATIONSHIP_SERVICE_OPTIONS,
];

private ?string $id = null;
Expand Down Expand Up @@ -63,6 +66,9 @@ class Service implements ServiceInterface
self::RELATIONSHIP_CARRIER => [
'data' => null,
],
self::RELATIONSHIP_SERVICE_OPTIONS => [
'data' => [],
],
];

/** @var ServiceRateInterface[] */
Expand Down Expand Up @@ -143,6 +149,29 @@ public function getCarrier(): CarrierInterface
return $this->relationships[self::RELATIONSHIP_CARRIER]['data'];
}

public function setServiceOptions(array $serviceOptions): self
{
$this->relationships[self::RELATIONSHIP_SERVICE_OPTIONS]['data'] = [];

foreach ($serviceOptions as $serviceOption) {
$this->addServiceOption($serviceOption);
}

return $this;
}

public function addServiceOption(ServiceOptionInterface $serviceOption): self
{
$this->relationships[self::RELATIONSHIP_SERVICE_OPTIONS]['data'][] = $serviceOption;

return $this;
}

public function getServiceOptions(): array
{
return $this->relationships[self::RELATIONSHIP_SERVICE_OPTIONS]['data'];
}

public function setHandoverMethod(string $handoverMethod): self
{
$this->attributes[self::ATTRIBUTE_HANDOVER_METHOD] = $handoverMethod;
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public function addFile(FileInterface $file): self
return $this;
}

public function getFiles(string $type = null): array
public function getFiles(?string $type = null): array
{
// For multi-colli `master` shipments we make this function return all files from the related `colli` shipments.
if (!empty($this->getColli())) {
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UrlBuilder
protected ?string $fragment = null;
protected array $query = [];

public function __construct(string $url = null)
public function __construct(?string $url = null)
{
if ($url !== null) {
$this->setUrl($url);
Expand Down
5 changes: 4 additions & 1 deletion tests/Feature/ResourceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,15 @@ public function testCreateService()
'uses_volumetric_weight' => true,
],
'relationships' => [
'carrier' => [
'carrier' => [
'data' => [
'id' => 'carrier-id-1',
'type' => 'carriers',
],
],
'service_options' => [
'data' => [],
],
],
];

Expand Down
10 changes: 8 additions & 2 deletions tests/Unit/Resources/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function testName()
public function testPackageType()
{
$service = new Service();
$this->assertEquals(Service::PACKAGE_TYPE_PARCEL, $service->setPackageType(Service::PACKAGE_TYPE_PARCEL)->getPackageType());
$this->assertEquals(
Service::PACKAGE_TYPE_PARCEL,
$service->setPackageType(Service::PACKAGE_TYPE_PARCEL)->getPackageType(),
);
}

/** @test */
Expand Down Expand Up @@ -199,12 +202,15 @@ public function testJsonSerialize()
'uses_volumetric_weight' => true,
],
'relationships' => [
'carrier' => [
'carrier' => [
'data' => [
'id' => 'carrier-id-1',
'type' => 'carriers',
],
],
'service_options' => [
'data' => [],
],
],
], $service->jsonSerialize());
}
Expand Down