Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
neomerx committed Jun 25, 2015
1 parent be06091 commit 3146bb9
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/Document/Presenters/ElementPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,28 @@ public function addRelationshipTo(

// parent might be already added to included to it won't be in 'target' buffer
if ($parentExists === true) {
$parentAlias = &$target[$parentType][$parentId];

$name = $relation->getName();
$alreadyGotData = isset($target[$parentType][$parentId][Document::KEYWORD_RELATIONSHIPS][$name]);
if ($alreadyGotData === false) {
// ... add the first one
$alreadyGotRelation = isset($parentAlias[Document::KEYWORD_RELATIONSHIPS][$name]);

$linkage = null;
if ($relation->isShowData() === true) {
$linkage = $this->getLinkageRepresentation($resource);
}

if ($alreadyGotRelation === false) {
// ... add the first linkage
$representation = [];
if ($relation->isShowData() === true) {
$representation[Document::KEYWORD_LINKAGE_DATA][] = $this->getLinkageRepresentation($resource);
if ($linkage !== null) {
$representation[Document::KEYWORD_LINKAGE_DATA][] = $linkage;
}

$representation += $this->getRelationRepresentation($parent, $relation);

$target[$parentType][$parentId][Document::KEYWORD_RELATIONSHIPS][$name] = $representation;
} else {
// ... or add another relation
if ($relation->isShowData() === true) {
$target[$parentType][$parentId][Document::KEYWORD_RELATIONSHIPS]
[$name][Document::KEYWORD_LINKAGE_DATA][] = $this->getLinkageRepresentation($resource);
}
$parentAlias[Document::KEYWORD_RELATIONSHIPS][$name] = $representation;
} elseif ($alreadyGotRelation === true && $linkage !== null) {
// ... or add another linkage
$parentAlias[Document::KEYWORD_RELATIONSHIPS][$name][Document::KEYWORD_LINKAGE_DATA][] = $linkage;
}
}
}
Expand Down

0 comments on commit 3146bb9

Please sign in to comment.