Passed
Branch beta (1b8e35)
by Jon
07:16
created

PassThrough::handle()   F

Complexity

Conditions 15
Paths 16384

Size

Total Lines 35
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 2.7451
c 0
b 0
f 0
cc 15
eloc 22
nc 16384
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Response;
7
use sfContext;
1 ignored issue
show
Bug introduced by
The type sfContext 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...
8
9
class PassThrough
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request $request
15
     * @param  \Closure $next
16
     *
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next)
1 ignored issue
show
Unused Code introduced by
The parameter $next is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

19
    public function handle($request, /** @scrutinizer ignore-unused */ Closure $next)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        // fire up symfony
22
        if (! defined('SF_APP')) {
23
            define('SF_APP', 'frontend');
24
            define('SF_ENVIRONMENT', env('SF_ENVIRONMENT', 'prod'));
25
            define('SF_DEBUG', env('SF_DEBUG', 'false'));
26
        }
27
        if (! defined('SF_ROOT_DIR')) {
28
            define('SF_ROOT_DIR', env('SF_ROOT_DIR'));
29
        }
30
31
        $_SERVER['HTTP_HOST']       = (empty($_SERVER['HTTP_HOST'])) ? $request->getHost() : $_SERVER['HTTP_HOST'];
32
        $_SERVER['SERVER_NAME']     = (empty($_SERVER['SERVER_NAME'])) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
33
        $_SERVER['SERVER_PORT']     = (empty($_SERVER['SERVER_PORT'])) ? 80 : $_SERVER['SERVER_PORT'];
34
        $_SERVER['HTTP_USER_AGENT'] = (empty($_SERVER['HTTP_USER_AGENT'])) ? 'PHP5/CLI' : $_SERVER['HTTP_USER_AGENT'];
35
        $_SERVER['REMOTE_ADDR']     = (empty($_SERVER['REMOTE_ADDR'])) ? '127.0.0.1' : $_SERVER['REMOTE_ADDR'];
36
        $_SERVER['REQUEST_METHOD']  = (empty($_SERVER['REQUEST_METHOD'])) ? strtoupper($request->getMethod()) : $_SERVER['REQUEST_METHOD'];
37
        $_SERVER['PATH_INFO']       = (empty($_SERVER['PATH_INFO'])) ? $request->getPathInfo() : $_SERVER['PATH_INFO'];
38
        $_SERVER['REQUEST_URI']     = (empty($_SERVER['REQUEST_URI'])) ? $request->getUri() : $_SERVER['REQUEST_URI'];
39
        $_SERVER['SCRIPT_NAME']     = (empty($_SERVER['SCRIPT_NAME'])) ? '/index.php' : $_SERVER['SCRIPT_NAME'];
40
        $_SERVER['SCRIPT_FILENAME'] = (empty($_SERVER['SCRIPT_FILENAME'])) ? '/index.php' : $_SERVER['SCRIPT_FILENAME'];
41
        $_SERVER['QUERY_STRING']    = (empty($_SERVER['QUERY_STRING'])) ? $request->getQueryString() : $_SERVER['QUERY_STRING'];
42
        require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
43
        //let symfony handle/render the request
44
45
        /** @var \sfWebResponse $symfonyResponse */
46
        $symfonyResponse = sfContext::getInstance()->getController()->dispatch();
47
        //throw away the symfony rendered buffer
48
        while (ob_get_level()) {
49
            ob_end_clean();
50
        }
51
52
        //make a new laravel response object and assign the content generated from symfony
53
        return new Response($symfonyResponse->getContent());
54
    }
55
}
56