Passed
Push — master ( a86818...d6b808 )
by Michele
02:00
created
src/Http/Middleware/LaravelCookieConsent.php 2 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -8,27 +8,27 @@  discard block
 block discarded – undo
8 8
 
9 9
 class LaravelCookieConsent
10 10
 {
11
-	/**
12
-	 * Handle an incoming request.
13
-	 * @param $request
14
-	 * @param Closure $next
15
-	 *
16
-	 * @return LaravelCookieConsent|mixed
17
-	 * @throws Throwable
18
-	 */
19
-	public function handle($request, Closure $next)
20
-	{
21
-		$alreadyAccepted = array_key_exists(config('laravel-cookie-consent.cookie_name'), $request->cookie());
11
+    /**
12
+     * Handle an incoming request.
13
+     * @param $request
14
+     * @param Closure $next
15
+     *
16
+     * @return LaravelCookieConsent|mixed
17
+     * @throws Throwable
18
+     */
19
+    public function handle($request, Closure $next)
20
+    {
21
+        $alreadyAccepted = array_key_exists(config('laravel-cookie-consent.cookie_name'), $request->cookie());
22 22
         $cookieTypesAccepted = $this->getCookieTypesConsent($request);
23
-		$response = $next($request);
24
-		if (! $response instanceof Response) {
25
-			return $response;
26
-		}
27
-		if (! $this->containsBodyTag($response)) {
28
-			return $response;
29
-		}
30
-		return $this->addCookieConsentScriptToResponse($response, $alreadyAccepted, $cookieTypesAccepted);
31
-	}
23
+        $response = $next($request);
24
+        if (! $response instanceof Response) {
25
+            return $response;
26
+        }
27
+        if (! $this->containsBodyTag($response)) {
28
+            return $response;
29
+        }
30
+        return $this->addCookieConsentScriptToResponse($response, $alreadyAccepted, $cookieTypesAccepted);
31
+    }
32 32
 
33 33
     /**
34 34
      * Get the cookie preference for the user
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
         return $cookieTypesConsent;
46 46
     }
47 47
 
48
-	/**
49
-	 * Check if the application contains body tag
50
-	 * @param Response $response
51
-	 *
52
-	 * @return bool
53
-	 */
54
-	protected function containsBodyTag(Response $response): bool
48
+    /**
49
+     * Check if the application contains body tag
50
+     * @param Response $response
51
+     *
52
+     * @return bool
53
+     */
54
+    protected function containsBodyTag(Response $response): bool
55 55
     {
56
-		return $this->getLastClosingBodyTagPosition($response->getContent()) != false;
57
-	}
56
+        return $this->getLastClosingBodyTagPosition($response->getContent()) != false;
57
+    }
58 58
 
59 59
     /**
60 60
      * Add cookie consent container to the response
@@ -66,27 +66,27 @@  discard block
 block discarded – undo
66 66
      * @return Response
67 67
      * @throws Throwable
68 68
      */
69
-	protected function addCookieConsentScriptToResponse(Response $response, $alreadyAccepted, $cookieTypesAccepted): Response
69
+    protected function addCookieConsentScriptToResponse(Response $response, $alreadyAccepted, $cookieTypesAccepted): Response
70 70
     {
71
-		$content = $response->getContent();
72
-		//if(!$alreadyAccepted) {
73
-			$closingBodyTagPosition = $this->getLastClosingBodyTagPosition($content);
74
-			$content = ''
75
-			           .substr($content, 0, $closingBodyTagPosition)
76
-			           .view('laravel-cookie-consent::_banner', ['alreadyAccepted' => $alreadyAccepted, 'cookieTypesAccepted' => $cookieTypesAccepted])->render()
77
-			           .substr($content, $closingBodyTagPosition);
78
-		//}
79
-		return $response->setContent($content);
80
-	}
71
+        $content = $response->getContent();
72
+        //if(!$alreadyAccepted) {
73
+            $closingBodyTagPosition = $this->getLastClosingBodyTagPosition($content);
74
+            $content = ''
75
+                        .substr($content, 0, $closingBodyTagPosition)
76
+                        .view('laravel-cookie-consent::_banner', ['alreadyAccepted' => $alreadyAccepted, 'cookieTypesAccepted' => $cookieTypesAccepted])->render()
77
+                        .substr($content, $closingBodyTagPosition);
78
+        //}
79
+        return $response->setContent($content);
80
+    }
81 81
 
82
-	/**
83
-	 * Get last closing body tag position
84
-	 * @param string $content
85
-	 *
86
-	 * @return int
87
-	 */
88
-	protected function getLastClosingBodyTagPosition(string $content = ''): int|false
82
+    /**
83
+     * Get last closing body tag position
84
+     * @param string $content
85
+     *
86
+     * @return int
87
+     */
88
+    protected function getLastClosingBodyTagPosition(string $content = ''): int|false
89 89
     {
90
-		return strripos($content, '</body>');
91
-	}
90
+        return strripos($content, '</body>');
91
+    }
92 92
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 		$alreadyAccepted = array_key_exists(config('laravel-cookie-consent.cookie_name'), $request->cookie());
22 22
         $cookieTypesAccepted = $this->getCookieTypesConsent($request);
23 23
 		$response = $next($request);
24
-		if (! $response instanceof Response) {
24
+		if (!$response instanceof Response) {
25 25
 			return $response;
26 26
 		}
27
-		if (! $this->containsBodyTag($response)) {
27
+		if (!$this->containsBodyTag($response)) {
28 28
 			return $response;
29 29
 		}
30 30
 		return $this->addCookieConsentScriptToResponse($response, $alreadyAccepted, $cookieTypesAccepted);
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function getCookieTypesConsent($request): array
40 40
     {
41
-        $cookieTypesConsent = [];
42
-        foreach(config('laravel-cookie-consent.cookie_types') as $type => $cookie_name) {
43
-            if(array_key_exists($cookie_name, $request->cookie())) $cookieTypesConsent[] = $cookie_name;
41
+        $cookieTypesConsent = [ ];
42
+        foreach (config('laravel-cookie-consent.cookie_types') as $type => $cookie_name) {
43
+            if (array_key_exists($cookie_name, $request->cookie())) $cookieTypesConsent[ ] = $cookie_name;
44 44
         }
45 45
         return $cookieTypesConsent;
46 46
     }
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 			$closingBodyTagPosition = $this->getLastClosingBodyTagPosition($content);
74 74
 			$content = ''
75 75
 			           .substr($content, 0, $closingBodyTagPosition)
76
-			           .view('laravel-cookie-consent::_banner', ['alreadyAccepted' => $alreadyAccepted, 'cookieTypesAccepted' => $cookieTypesAccepted])->render()
76
+			           .view('laravel-cookie-consent::_banner', [ 'alreadyAccepted' => $alreadyAccepted, 'cookieTypesAccepted' => $cookieTypesAccepted ])->render()
77 77
 			           .substr($content, $closingBodyTagPosition);
78 78
 		//}
79 79
 		return $response->setContent($content);
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @return int
87 87
 	 */
88
-	protected function getLastClosingBodyTagPosition(string $content = ''): int|false
88
+	protected function getLastClosingBodyTagPosition(string $content = ''): int | false
89 89
     {
90 90
 		return strripos($content, '</body>');
91 91
 	}
Please login to merge, or discard this patch.