Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nieuwe parameters aan entry toegevoegd voor Environment, ActivationBefore en AdditionalLicenseOptions #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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;
}
}
21 changes: 21 additions & 0 deletions src/Mapper/ArrayToAdditionalLicenseOptionsMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);

namespace Kennisnet\ECK\Mapper;

use Kennisnet\ECK\Model\AdditionalLicenseOptions;

final class ArrayToAdditionalLicenseOptionsMapper
{
public static function mapArrayToAdditionalLicenseOptions(?array $additionalLicenseOptionsArray): ?AdditionalLicenseOptions
{
if (null === $additionalLicenseOptionsArray) {
return null;
}

$additionalLicenseOptions = new AdditionalLicenseOptions();
$additionalLicenseOptions->setAdditionalLicenseOption(ArrayToStringArrayMapper::mapArrayToStringArray($additionalLicenseOptionsArray ?? []));
return $additionalLicenseOptions;

}
}
3 changes: 3 additions & 0 deletions 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->setAdditionalLicenseOptions(ArrayToAdditionalLicenseOptionsMapper::mapArrayToAdditionalLicenseOptions($recordArray['AdditionalLicenseOptions'] ?? null));
$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;
}
}
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;
}
}
26 changes: 26 additions & 0 deletions src/Model/AdditionalLicenseOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

namespace Kennisnet\ECK\Model;

final class AdditionalLicenseOptions
{
/** @var string[] */
private $additionalLicenseOption = [];

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

/**
* @param string[] $additionalLicenseOption
*/
public function setAdditionalLicenseOption(array $additionalLicenseOption): void
{
$this->additionalLicenseOption = $additionalLicenseOption;
}
}
48 changes: 36 additions & 12 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 @@ -161,10 +157,8 @@ class Entry
/** @var int */
private $licenseCount = 0;

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

/** @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 @@ -625,6 +639,16 @@ public function setLicenseCount(int $licenseCount): void
$this->licenseCount = $licenseCount;
}

public function getAdditionalLicenseOptions(): ?AdditionalLicenseOptions
{
return $this->additionalLicenseOptions;
}

public function setAdditionalLicenseOptions(?AdditionalLicenseOptions $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;
}
}
55 changes: 55 additions & 0 deletions tests/Mapper/ArrayToActivationBeforeMapperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);


namespace Kennisnet\ECK\Tests\Mapper;


use DateTimeImmutable;
use Kennisnet\ECK\Mapper\ArrayToActivationBeforeMapper;
use Kennisnet\ECK\Model\ActivationBefore;
use Kennisnet\ECK\Tests\builder\ActivationBeforeBuilder;
use PHPUnit\Framework\TestCase;

final class ArrayToActivationBeforeMapperTest extends TestCase
{

/**
* @dataProvider activationBeforeDataProvider
*/
public function test_it_maps_an_array_to_activation_before(?array $input, ?ActivationBefore $expectedResult, string $scenario): void
{
self::assertEquals($expectedResult, ArrayToActivationBeforeMapper::mapArrayToActivationBefore($input), $scenario);
}

public function activationBeforeDataProvider(): \Generator
{
yield [
[
'ActivationBeforeDays' => '30'
],
(new ActivationBeforeBuilder())
->withActivationBeforeDays(30)
->build()
,
'Creates an activation before object with ActivationBeforeDays set to 30 and date not there.'
];

yield [
[
'ActivationBeforeDate' => '2021-07-16T23:59:59+01:00'
],
(new ActivationBeforeBuilder())
->withActivationBeforeDate(new DateTimeImmutable('2021-07-16T23:59:59+01:00'))
->build()
,
'Creates an activation before object with ActivationBeforeDate set to july 16th 2021 and no activation before days.'
];

yield [
null,
null,
'No activation before data returns null'
];
}
}
Loading