Issues (1019)

src/Illuminate/Laravel.php (59 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace Hhxsv5\LaravelS\Illuminate;
4
5
use Illuminate\Container\Container;
0 ignored issues
show
The type Illuminate\Container\Container 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...
6
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
0 ignored issues
show
The type Illuminate\Contracts\Console\Kernel 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...
7
use Illuminate\Contracts\Http\Kernel as HttpKernel;
0 ignored issues
show
The type Illuminate\Contracts\Http\Kernel 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
use Illuminate\Http\Request as IlluminateRequest;
0 ignored issues
show
The type Illuminate\Http\Request 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...
9
use Symfony\Component\HttpFoundation\BinaryFileResponse;
0 ignored issues
show
The type Symfony\Component\HttpFo...tion\BinaryFileResponse 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...
10
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
0 ignored issues
show
The type Symfony\Component\HttpFoundation\Response 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...
11
use Symfony\Component\HttpFoundation\StreamedResponse;
0 ignored issues
show
The type Symfony\Component\HttpFoundation\StreamedResponse 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...
12
13
class Laravel
0 ignored issues
show
Missing doc comment for class Laravel
Loading history...
14
{
15
    /**@var Container */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
16
    protected $currentApp;
17
18
    /**@var Container */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
19
    protected $snapshotApp;
20
21
    /**@var ReflectionApp */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
22
    protected $reflectionApp;
23
24
    /**@var HttpKernel */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
25
    protected $kernel;
26
27
    /**@var array */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
28
    protected $conf = [];
29
30
    /**@var array */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
31
    protected static $staticBlackList = [
32
        '/index.php'  => true,
33
        '/.htaccess'  => true,
34
        '/web.config' => true,
35
    ];
36
    /**@var array */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
37
    protected static $staticIndexList = [
38
        'index.html',
39
    ];
40
41
    /**@var array */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
42
    private $rawGlobals = [];
0 ignored issues
show
Private member variable "rawGlobals" must be prefixed with an underscore
Loading history...
43
44
    /**@var CleanerManager */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
45
    protected $cleanerManager;
46
47
    public function __construct(array $conf = [])
0 ignored issues
show
Missing doc comment for function __construct()
Loading history...
48
    {
49
        $this->conf = $conf;
50
51
        // Merge $_ENV $_SERVER
52
        $this->rawGlobals['_SERVER'] = $_SERVER + $this->conf['_SERVER'];
53
        $this->rawGlobals['_ENV'] = $_ENV + $this->conf['_ENV'];
54
    }
55
56
    public function prepareLaravel()
0 ignored issues
show
Missing doc comment for function prepareLaravel()
Loading history...
57
    {
58
        list($this->currentApp, $this->kernel) = $this->createAppKernel();
59
60
        $this->reflectionApp = new ReflectionApp($this->currentApp);
61
62
        $this->saveSnapshot();
63
64
        // Create cleaner manager
65
        $this->cleanerManager = new CleanerManager($this->currentApp, $this->snapshotApp, $this->conf);
66
    }
67
68
    protected function saveSnapshot()
0 ignored issues
show
Missing doc comment for function saveSnapshot()
Loading history...
69
    {
70
        $this->snapshotApp = clone $this->currentApp;
71
72
        $instances = $this->reflectionApp->instances();
73
74
        foreach ($instances as $key => $value) {
75
            $this->snapshotApp->offsetSet($key, is_object($value) ? clone $value : $value);
76
        }
77
    }
78
79
    protected function createAppKernel()
0 ignored issues
show
Missing doc comment for function createAppKernel()
Loading history...
80
    {
81
        // Register autoload
82
        self::autoload($this->conf['root_path']);
83
84
        // Make kernel for Laravel
85
        $app = require $this->conf['root_path'] . '/bootstrap/app.php';
0 ignored issues
show
File is being conditionally included; use "include" instead
Loading history...
86
        $kernel = $this->conf['is_lumen'] ? null : $app->make(HttpKernel::class);
87
88
        // Boot
89
        if ($this->conf['is_lumen']) {
90
            $this->configureLumen($app);
91
            if (method_exists($app, 'boot')) {
92
                $app->boot();
93
            }
94
        } else {
95
            $app->make(ConsoleKernel::class)->bootstrap();
96
        }
97
98
        return [$app, $kernel];
99
    }
100
101
    protected function configureLumen(Container $app)
0 ignored issues
show
Missing doc comment for function configureLumen()
Loading history...
102
    {
103
        $cfgPaths = [
104
            // Framework default configuration
105
            $this->conf['root_path'] . '/vendor/laravel/lumen-framework/config/',
106
            // App configuration
107
            $this->conf['root_path'] . '/config/',
108
        ];
109
110
        $keys = [];
111
        foreach ($cfgPaths as $cfgPath) {
112
            $configs = (array)glob($cfgPath . '*.php');
113
            foreach ($configs as $config) {
114
                $config = substr(basename($config), 0, -4);
115
                $keys[$config] = $config;
116
            }
117
        }
118
119
        foreach ($keys as $key) {
120
            $app->configure($key);
121
        }
122
    }
123
124
    public static function autoload($rootPath)
0 ignored issues
show
Missing doc comment for function autoload()
Loading history...
125
    {
126
        $autoload = $rootPath . '/bootstrap/autoload.php';
127
        if (file_exists($autoload)) {
128
            require_once $autoload;
0 ignored issues
show
File is being conditionally included; use "include_once" instead
Loading history...
129
        } else {
130
            require_once $rootPath . '/vendor/autoload.php';
0 ignored issues
show
File is being conditionally included; use "include_once" instead
Loading history...
131
        }
132
    }
133
134
    public function getRawGlobals()
0 ignored issues
show
Missing doc comment for function getRawGlobals()
Loading history...
135
    {
136
        return $this->rawGlobals;
137
    }
138
139
    public function handleDynamic(IlluminateRequest $request)
0 ignored issues
show
Missing doc comment for function handleDynamic()
Loading history...
140
    {
141
        ob_start();
142
143
        if ($this->conf['is_lumen']) {
144
            $response = $this->currentApp->dispatch($request);
145
            if ($response instanceof SymfonyResponse) {
146
                $content = $response->getContent();
147
            } else {
148
                $content = $response;
149
            }
150
151
            $this->reflectionApp->callTerminableMiddleware($response);
152
        } else {
153
            $response = $this->kernel->handle($request);
154
            $content = $response->getContent();
155
            $this->kernel->terminate($request, $response);
156
        }
157
158
        // prefer content in response, secondly ob
159
        if (!($response instanceof StreamedResponse) && (string)$content === '' && ob_get_length() > 0) {
160
            $response->setContent(ob_get_contents());
161
        }
162
163
        ob_end_clean();
164
165
        return $response;
166
    }
167
168
    public function handleStatic(IlluminateRequest $request)
0 ignored issues
show
Missing doc comment for function handleStatic()
Loading history...
169
    {
170
        $uri = $request->getRequestUri();
171
        $uri = (string)str_replace("\0", '', urldecode($uri));
172
        if (isset(self::$staticBlackList[$uri]) || strpos($uri, '/..') !== false) {
173
            return false;
174
        }
175
176
        $requestFile = $this->conf['static_path'] . $uri;
177
        if (is_file($requestFile)) {
178
            return $this->createStaticResponse($requestFile, $request);
179
        }
180
        if (is_dir($requestFile)) {
181
            $indexFile = $this->lookupIndex($requestFile);
182
            if ($indexFile === false) {
183
                return false;
184
            }
185
            return $this->createStaticResponse($indexFile, $request);
186
        }
187
        return false;
188
    }
189
190
    protected function lookupIndex($folder)
0 ignored issues
show
Missing doc comment for function lookupIndex()
Loading history...
191
    {
192
        $folder = rtrim($folder, '/') . '/';
193
        foreach (self::$staticIndexList as $index) {
194
            $tmpFile = $folder . $index;
195
            if (is_file($tmpFile)) {
196
                return $tmpFile;
197
            }
198
        }
199
        return false;
200
    }
201
202
    public function createStaticResponse($requestFile, IlluminateRequest $request)
0 ignored issues
show
Missing doc comment for function createStaticResponse()
Loading history...
203
    {
204
        $response = new BinaryFileResponse($requestFile);
205
        $response->prepare($request);
206
        $response->isNotModified($request);
207
        return $response;
208
    }
209
210
    public function clean()
0 ignored issues
show
Missing doc comment for function clean()
Loading history...
211
    {
212
        $this->cleanerManager->clean();
213
        $this->cleanerManager->cleanControllers();
214
    }
215
216
    public function cleanProviders()
0 ignored issues
show
Missing doc comment for function cleanProviders()
Loading history...
217
    {
218
        $this->cleanerManager->cleanProviders();
219
    }
220
221
    public function fireEvent($name, array $params = [])
0 ignored issues
show
Missing doc comment for function fireEvent()
Loading history...
222
    {
223
        $params[] = $this->currentApp;
224
        return method_exists($this->currentApp['events'], 'dispatch') ?
225
            $this->currentApp['events']->dispatch($name, $params) : $this->currentApp['events']->fire($name, $params);
226
    }
227
228
    public function bindRequest(IlluminateRequest $request)
0 ignored issues
show
Missing doc comment for function bindRequest()
Loading history...
229
    {
230
        $this->currentApp->instance('request', $request);
231
    }
232
233
    public function bindSwoole($swoole)
0 ignored issues
show
Missing doc comment for function bindSwoole()
Loading history...
234
    {
235
        $this->currentApp->singleton('swoole', function () use ($swoole) {
0 ignored issues
show
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
236
            return $swoole;
237
        });
0 ignored issues
show
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
238
    }
239
240
    public function saveSession()
0 ignored issues
show
Missing doc comment for function saveSession()
Loading history...
241
    {
242
        if (isset($this->currentApp['session'])) {
243
            $this->currentApp['session']->save();
244
        }
245
    }
246
}
247