Skip to content
Open
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: 23 additions & 0 deletions src/Mapper/ArrayToActivationBeforeMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Kennisnet\ECK\Mapper;

use Kennisnet\ECK\Model\ActivationBefore;

final class ArrayToActivationBeforeMapper
{

public static function mapArrayToActivationBefore(?array $activationBeforeArray): ?ActivationBefore
{
if (null === $activationBeforeArray) {
return null;
}

$activationBefore = new ActivationBefore();
$activationBefore->setActivationBeforeDays(StringToIntMapper::mapStringToNullableInt($activationBeforeArray['ActivationBeforeDays'] ?? null));
$activationBefore->setActivationBeforeDate(StringToDateMapper::mapStringToDate($activationBeforeArray['ActivationBeforeDate'] ?? null));

return $activationBefore;
}
}
5 changes: 4 additions & 1 deletion src/Mapper/ArrayToEckRecordMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static function mapArrayToEckRecord(array $recordArray): EckRecord
$eckRecord = new EckRecord($recordArray['RecordId'], $recordArray['Title']);
$eckRecord->setLastModifiedDate(StringToDateMapper::mapStringToDate($recordArray['LastModifiedDate'] ?? null));
$eckRecord->setDescription($recordArray['Description'] ?? '');
$eckRecord->setEnvironments(ArrayToEnvironmentsMapper::mapArrayToEnvironments($recordArray['Environments'] ?? null));
$eckRecord->setPublisher($recordArray['Publisher'] ?? null);
$eckRecord->setAuthors(ArrayToStringArrayMapper::mapArrayToStringArray($recordArray['Authors'] ?? []));
$eckRecord->setInformationLocation($recordArray['InformationLocation'] ?? null);
Expand Down Expand Up @@ -47,11 +48,13 @@ public static function mapArrayToEckRecord(array $recordArray): EckRecord
$eckRecord->setPrices(ArrayToPricesMapper::mapArrayToPrices($recordArray['Prices'] ?? []));
$eckRecord->setPriceIsIndicative(StringToBoolMapper::mapStringToBool($recordArray['PriceIsIndicative'] ?? null));
$eckRecord->setIsLicensed(StringToBoolMapper::mapStringToBool($recordArray['IsLicensed'] ?? null));
$eckRecord->setActivationBefore(ArrayToActivationBeforeMapper::mapArrayToActivationBefore($recordArray['ActivationBefore'] ?? null));
$eckRecord->setLicenseAvailabilityOptions($recordArray['LicenseAvailabilityOptions'] ?? null);
$eckRecord->setLicenseStartDate(StringToDateMapper::mapStringToDate($recordArray['LicenseStartDate'] ?? null));
$eckRecord->setLicenseEndDate(StringToDateMapper::mapStringToDate($recordArray['LicenseEndDate'] ?? null));
$eckRecord->setLicenseDuration($recordArray['LicenseDuration'] ?? null);
$eckRecord->setLicenseCount(StringToIntMapper::mapStringToInt($recordArray['LicenseCount'] ?? null));
$eckRecord->setLicenseCount(StringToIntMapper::mapStringToNullableInt($recordArray['LicenseCount'] ?? null));
$eckRecord->setAdditionalLicenseOptions(ArrayToStringArrayMapper::mapArrayToStringArray($recordArray['AdditionalLicenseOptions'] ?? []));
$eckRecord->setIsCatalogItem(StringToBoolMapper::mapStringToBool($recordArray['IsCatalogItem'] ?? null));
$eckRecord->setCopyright($recordArray['Copyright'] ?? null);
return $eckRecord;
Expand Down
22 changes: 22 additions & 0 deletions src/Mapper/ArrayToEnvironmentsMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);

namespace Kennisnet\ECK\Mapper;

use Kennisnet\ECK\Model\Environments;

final class ArrayToEnvironmentsMapper
{
public static function mapArrayToEnvironments(?array $environmentsArray): ?Environments
{
if (null === $environmentsArray) {
return null;
}

$environments = new Environments();
$environments->setPlatform(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Platform'] ?? null));
$environments->setDevice(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Device'] ?? null));
$environments->setBrowser(ArrayToStringArrayMapper::mapValueToStringArray($environmentsArray['Browser'] ?? null));
return $environments;
}
}
44 changes: 39 additions & 5 deletions src/Mapper/ArrayToPriceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ final class ArrayToPriceMapper
*/
public static function mapArrayToPrices(array $pricesArray): array
{
$keys = array_keys($pricesArray);
if (in_array(array_shift($keys), ['Amount', 'VAT'], true)) {
if (self::isSinglePriceArray($pricesArray)) {
return [ArrayToPriceMapper::mapArrayToSinglePrice($pricesArray)];
}
return array_map(function (array $singlePriceArray) {
return ArrayToPriceMapper::mapArrayToSinglePrice($singlePriceArray);
}, $pricesArray);

$combinedAmountAndPricesArrays = self::createPricesArraysFromAmountAndVatArrays(
array_values($pricesArray['Amount'] ?? []),
array_values($pricesArray['VAT'] ?? [])
);

return array_map(
function (array $priceArray) {
return self::mapArrayToSinglePrice($priceArray);
}, $combinedAmountAndPricesArrays
);

}

private static function mapArrayToSinglePrice(array $priceArray): Price
Expand All @@ -29,4 +37,30 @@ private static function mapArrayToSinglePrice(array $priceArray): Price
return $price;
}

private static function createPricesArraysFromAmountAndVatArrays(array $amountArray, array $vatArray): array
{
$combinedAmountAndPricesArrays = [];
for ($i = 0; $i < sizeof($amountArray); $i++) {
$combinedAmountAndPricesArrays[] = [
'Amount' => $amountArray[$i],
'VAT' => $vatArray[$i],
];
}
return $combinedAmountAndPricesArrays;
}

private static function isSinglePriceArray(array $pricesArray): bool
{
/*
* The serializer returns some strange results. It casts a 0 to a null for example
* which makes it hard to differentiate between a set value and a not-set
* value. We only look at the VAT therefore, because that contains a not-0 value
* for the VAT, which does not cast to null in the serializer..
*/
return sizeof($pricesArray) === 2
&& isset($pricesArray['VAT'])
&& !is_array($pricesArray['VAT']);

}

}
15 changes: 12 additions & 3 deletions src/Mapper/ArrayToStringArrayMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ public static function mapArrayToStringArray(array $arrayWithValues): array
{
$valueArray = array_values($arrayWithValues);
$propertyValue = array_shift($valueArray);
if (is_array($propertyValue)){
return $propertyValue;
return self::mapValueToStringArray($propertyValue);
}

/**
* @param string[]|string|null $value
* @return string[]
*/
public static function mapValueToStringArray($value): array
{
if (is_array($value)) {
return $value;
}
return null !== $propertyValue ? [$propertyValue] : [];
return null !== $value ? [$value] : [];
}
}
47 changes: 47 additions & 0 deletions src/Model/ActivationBefore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);

namespace Kennisnet\ECK\Model;

use DateTimeImmutable;

final class ActivationBefore
{
/** @var int|null */
private $activationBeforeDays = null;

/** @var DateTimeImmutable|null */
private $activationBeforeDate = null;

/**
* @return int|null
*/
public function getActivationBeforeDays(): ?int
{
return $this->activationBeforeDays;
}

/**
* @param int|null $activationBeforeDays
*/
public function setActivationBeforeDays(?int $activationBeforeDays): void
{
$this->activationBeforeDays = $activationBeforeDays;
}

/**
* @return DateTimeImmutable|null
*/
public function getActivationBeforeDate(): ?DateTimeImmutable
{
return $this->activationBeforeDate;
}

/**
* @param DateTimeImmutable|null $activationBeforeDate
*/
public function setActivationBeforeDate(?DateTimeImmutable $activationBeforeDate): void
{
$this->activationBeforeDate = $activationBeforeDate;
}
}
62 changes: 46 additions & 16 deletions src/Model/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ class Entry
/** @var string */
private $description = '';

/**
* TODO: Add Environments
* Environments<complex>
*/
/** @var Environments|null */
private $environments = null;

/** @var string|null */
private $contentLocation = null;
Expand Down Expand Up @@ -141,10 +139,8 @@ class Entry
/** @var bool */
private $isLicensed = false;

/**
* @Todo: Add ActivationBefore complex object
* ActivationBefore<complex>
**/
/** @var ActivationBefore|null */
private $activationBefore = null;

/** @var string|null */
private $licenseAvailabilityOptions = null;
Expand All @@ -158,13 +154,11 @@ class Entry
/** @var string|null */
private $licenseDuration = null;

/** @var int */
private $licenseCount = 0;
/** @var int|null */
private $licenseCount = null;

/**
* @Todo: Add AdditionalLicenseOptions complex object
* AdditionalLicenseOptions<complex>
**/
/** @var string[] */
private $additionalLicenseOptions = [];

/** @var bool */
private $isCatalogItem = false;
Expand Down Expand Up @@ -212,6 +206,16 @@ public function getDescription(): string
return $this->description;
}

public function getEnvironments(): ?Environments
{
return $this->environments;
}

public function setEnvironments(?Environments $environments): void
{
$this->environments = $environments;
}

public function getPublisher(): string
{
return $this->publisher;
Expand Down Expand Up @@ -575,6 +579,16 @@ public function setIsLicensed(bool $isLicensed): void
$this->isLicensed = $isLicensed;
}

public function getActivationBefore(): ?ActivationBefore
{
return $this->activationBefore;
}

public function setActivationBefore(?ActivationBefore $activationBefore): void
{
$this->activationBefore = $activationBefore;
}

public function getLicenseAvailabilityOptions(): ?string
{
return $this->licenseAvailabilityOptions;
Expand Down Expand Up @@ -615,16 +629,32 @@ public function setLicenseDuration(?string $licenseDuration): void
$this->licenseDuration = $licenseDuration;
}

public function getLicenseCount(): int
public function getLicenseCount(): ?int
{
return $this->licenseCount;
}

public function setLicenseCount(int $licenseCount): void
public function setLicenseCount(?int $licenseCount): void
{
$this->licenseCount = $licenseCount;
}

/**
* @return string[]
*/
public function getAdditionalLicenseOptions(): array
{
return $this->additionalLicenseOptions;
}

/**
* @param string[] $additionalLicenseOptions
*/
public function setAdditionalLicenseOptions(array $additionalLicenseOptions): void
{
$this->additionalLicenseOptions = $additionalLicenseOptions;
}

public function isCatalogItem(): bool
{
return $this->isCatalogItem;
Expand Down
64 changes: 64 additions & 0 deletions src/Model/Environments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);

namespace Kennisnet\ECK\Model;

final class Environments
{
/** @var string[] */
private $platform = [];

/** @var string[] */
private $device = [];

/** @var string[] */
private $browser = [];

/**
* @return string[]
*/
public function getPlatform(): array
{
return $this->platform;
}

/**
* @param string[] $platform
*/
public function setPlatform(array $platform): void
{
$this->platform = $platform;
}

/**
* @return string[]
*/
public function getDevice(): array
{
return $this->device;
}

/**
* @param string[] $device
*/
public function setDevice(array $device): void
{
$this->device = $device;
}

/**
* @return string[]
*/
public function getBrowser(): array
{
return $this->browser;
}

/**
* @param string[] $browser
*/
public function setBrowser(array $browser): void
{
$this->browser = $browser;
}
}
14 changes: 7 additions & 7 deletions tests/Mapper/ArrayToPricesMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function pricesArrayDataProvider(): \Generator
[
'Currency' => 'EUR',
'Price' => [
[
'Amount' => '913',
'VAT' => '9',
'Amount' => [
'913',
'1002',
],
'VAT' => [
'9',
'21',
],
[
'Amount' => '1002',
'VAT' => '21',
]
]
],
(new PricesBuilder())
Expand Down