Skip to content

Commit

Permalink
map UGC contact options (#297)
Browse files Browse the repository at this point in the history
* add UGC type to ContactMediumEnum
* use UGC const from enum in OptionsMapper
  • Loading branch information
gmarinov authored Oct 4, 2019
1 parent 821963b commit 5f79661
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Domain/Enumeration/ContactMediumEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class ContactMediumEnum
public const STUMBLEUPON = 'stumbleupon';
public const INSTAGRAM = 'instagram';
public const OTHER = 'other';
public const UGC = 'ugc';
}
33 changes: 33 additions & 0 deletions src/Domain/ValueObject/UGCContactDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace BBC\ProgrammesPagesService\Domain\ValueObject;

class UGCContactDetails extends ContactDetails
{
/**
* @var bool
*/
protected $topNav;

/**
* @var string
*/
protected $title;

public function __construct($data)
{
parent::__construct($data['type'], $data['value'], $data['freetext']);
$this->topNav = ($data['top_nav'] ?? false) === true;
$this->title = $data['title'] ?? '';
}

public function isInTopNav() : bool
{
return $this->topNav;
}

public function getTitle() : string
{
return $this->title;
}
}
21 changes: 15 additions & 6 deletions src/Mapper/ProgrammesDbToDomain/OptionsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain;

use BBC\ProgrammesPagesService\Domain\Entity\Options;
use BBC\ProgrammesPagesService\Domain\Enumeration\ContactMediumEnum;
use BBC\ProgrammesPagesService\Domain\ValueObject\ContactDetails;
use BBC\ProgrammesPagesService\Domain\ValueObject\UGCContactDetails;

class OptionsMapper extends AbstractMapper
{
Expand Down Expand Up @@ -77,12 +79,19 @@ public function getDomainModel(array $options, array ...$parentEntities)
$contacts = [];

foreach ($options['contact_details'] as $contactDetails) {
if ($this->isValidContactDetails($contactDetails)) {
$contacts[] = new ContactDetails(
$contactDetails['type'],
$contactDetails['value'],
$contactDetails['freetext']
);
if (!$this->isValidContactDetails($contactDetails)) {
continue;
}
switch (strtolower($contactDetails['type'])) {
case ContactMediumEnum::UGC:
$contacts[] = new UGCContactDetails($contactDetails);
break;
default:
$contacts[] = new ContactDetails(
$contactDetails['type'],
$contactDetails['value'],
$contactDetails['freetext']
);
}
}

Expand Down

0 comments on commit 5f79661

Please sign in to comment.