Skip to content

Commit

Permalink
Normalizing options (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeparaujo authored Oct 17, 2017
1 parent a51059d commit 46ff7d3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
19 changes: 0 additions & 19 deletions src/Mapper/ProgrammesDbToDomain/OptionsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,12 @@ class OptionsMapper extends AbstractMapper

public function getDomainModel(array $options, array ...$parentEntities)
{
// Transform options
$options = $this->transformOptions($options);

// $parentEntities must start from the bottom of the hierarchy

// now loop through parents and apply the data
// ONLY if the key is allowed to cascade AND
// the key doesn't already exist lower down.
foreach ($parentEntities as $parentOptions) {
$parentOptions = $this->transformOptions($parentOptions);

foreach ($parentOptions as $key => $value) {
if (!isset($options[$key]) && (self::OPTIONS_DEFAULT_SCHEMA[$key]['cascades'] ?? false)) {
$options[$key] = $value;
Expand Down Expand Up @@ -86,18 +81,4 @@ private function getDefaultValues()

return self::$defaults;
}

private function transformOptions(array $options): array
{
// If brand_2016_layout is null (inherit), these options that can only be
// set when brand_2016_layout is true should also be inherited
if (array_key_exists('brand_2016_layout', $options) && is_null($options['brand_2016_layout'])) {
$options['brand_2016_layout_use_minimap'] = null;
$options['double_width_first_promo'] = null;
$options['show_gallery_cards'] = null;
$options['show_clip_cards'] = null;
}

return $options;
}
}
26 changes: 0 additions & 26 deletions tests/Mapper/ProgrammesDbToDomain/OptionsMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,6 @@ public function testInheritanceOfOptions()
);
}

public function testInheritDependentProperties()
{
$options = [
'brand_2016_layout' => null,
'brand_2016_layout_use_minimap' => false,
];

$parentOptions = [
'brand_2016_layout' => true,
'brand_2016_layout_use_minimap' => true,
];

$expectedOptions = [
'brand_2016_layout' => true,
'brand_2016_layout_use_minimap' => true,
];

$result = $this->getMapper()->getDomainModel($options, $parentOptions);
$relevantResult = [
'brand_2016_layout' => $result->getOption('brand_2016_layout'),
'brand_2016_layout_use_minimap' => $result->getOption('brand_2016_layout_use_minimap'),
];

$this->assertEquals(new Options($expectedOptions), new Options($relevantResult));
}

private function getMapper(): OptionsMapper
{
return new OptionsMapper($this->getMapperFactory());
Expand Down

0 comments on commit 46ff7d3

Please sign in to comment.