Passed
Push — master ( 691608...9a7512 )
by Mike
02:23
created

LaravelCaffeineDripMiddleware::handle()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 12
nc 2
nop 2
1
<?php namespace GeneaLabs\LaravelCaffeine\Http\Middleware;
2
3
use GeneaLabs\LaravelCaffeine\Dripper;
0 ignored issues
show
Bug introduced by
The type GeneaLabs\LaravelCaffeine\Dripper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
4
use Illuminate\Http\Request;
5
use Closure;
6
7
class LaravelCaffeineDripMiddleware
8
{
9
    public function handle(Request $request, Closure $next)
10
    {
11
        $response = $next($request);
12
        $content = $response->getContent();
13
14
        if (is_string($content)
15
            && (strpos($content, '_token')
16
                || (preg_match("/\<meta name=[\"\']csrf[_-]token[\"\']/", $content)))
17
        ) {
18
            $dripper = (new Dripper);
19
            $content = str_replace(
20
                '</body>',
21
                "{$dripper->html}</body>",
22
                $content
23
            );
24
            $response->setContent($content);
25
        }
26
27
        return $response;
28
    }
29
}
30