From 194f3f4c1621b207b9a6146600f45949b4adc6c0 Mon Sep 17 00:00:00 2001 From: Simon Erkelens Date: Sat, 20 Jul 2019 15:02:15 +1200 Subject: [PATCH] Extract shouldContinue check. --- src/View/CSPBackend.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/View/CSPBackend.php b/src/View/CSPBackend.php index abfe31d..df3b5cc 100644 --- a/src/View/CSPBackend.php +++ b/src/View/CSPBackend.php @@ -222,14 +222,9 @@ public function includeInHTML($content): string } // Skip if content isn't injectable, or there is nothing to inject - $tagsAvailable = preg_match('#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 = ''; @@ -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('#css) || + count($this->javascript) || + count($this->customCSS) || + count($this->customScript) || + count($this->customHeadTags); + + return $tagsAvailable && $hasFiles; + } }