Skip to content

Commit

Permalink
Extract shouldContinue check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Firesphere committed Jul 20, 2019
1 parent 7d5ae91 commit 194f3f4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/View/CSPBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,9 @@ public function includeInHTML($content): string
}

// Skip if content isn't injectable, or there is nothing to inject
$tagsAvailable = preg_match('#</head\b#', $content);
$hasFiles = count($this->css) ||
count($this->javascript) ||
count($this->customCSS) ||
count($this->customScript) ||
count($this->customHeadTags);
$shouldContinue = $this->shouldContinue($content);

if (!$tagsAvailable || !$hasFiles) {
if ($shouldContinue) {
return $content;
}
$requirements = '';
Expand Down Expand Up @@ -320,4 +315,20 @@ public static function setUsesNonce(bool $usesNonce): void
{
self::$usesNonce = $usesNonce;
}

/**
* @param $content
* @return bool
*/
protected function shouldContinue($content): bool
{
$tagsAvailable = preg_match('#</head\b#', $content);
$hasFiles = count($this->css) ||
count($this->javascript) ||
count($this->customCSS) ||
count($this->customScript) ||
count($this->customHeadTags);

return $tagsAvailable && $hasFiles;
}
}

0 comments on commit 194f3f4

Please sign in to comment.