Skip to content

Commit

Permalink
Minor abstraction for cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
Firesphere committed Jul 20, 2019
1 parent 194f3f4 commit b45c9ad
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/View/CSPBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,7 @@ public function includeInHTML($content): string
}

$requirements = $this->createHeadTags($requirements);

// Inject CSS into body
$content = $this->insertTagsIntoHead($requirements, $content);

// Inject scripts
if ($this->getForceJSToBottom()) {
$content = $this->insertScriptsAtBottom($jsRequirements, $content);
} elseif ($this->getWriteJavascriptToBody()) {
$content = $this->insertScriptsIntoBody($jsRequirements, $content);
} else {
$content = $this->insertTagsIntoHead($jsRequirements, $content);
}
$content = $this->insertContent($content, $requirements, $jsRequirements);

return $content;
}
Expand Down Expand Up @@ -331,4 +320,27 @@ protected function shouldContinue($content): bool

return $tagsAvailable && $hasFiles;
}

/**
* @param $content
* @param string $requirements
* @param string $jsRequirements
* @return string
*/
protected function insertContent($content, string $requirements, string $jsRequirements): string
{
// Inject CSS into head
$content = $this->insertTagsIntoHead($requirements, $content);

// Inject scripts
if ($this->getForceJSToBottom()) {
$content = $this->insertScriptsAtBottom($jsRequirements, $content);
} elseif ($this->getWriteJavascriptToBody()) {
$content = $this->insertScriptsIntoBody($jsRequirements, $content);
} else {
$content = $this->insertTagsIntoHead($jsRequirements, $content);
}

return $content;
}
}

0 comments on commit b45c9ad

Please sign in to comment.