| Total Lines | 51 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 18 | return function (array $context) { |
||
| 19 | $classLoader = require __DIR__ . '/../vendor/autoload.php'; |
||
| 20 | |||
| 21 | if (!file_exists(dirname(__DIR__) . '/install.lock')) { |
||
| 22 | $baseURL = str_replace(basename(__FILE__), '', $_SERVER['SCRIPT_NAME']); |
||
| 23 | $baseURL = rtrim($baseURL, '/'); |
||
| 24 | |||
| 25 | if (!str_contains($_SERVER['REQUEST_URI'], '/installer')) { |
||
| 26 | header('Location: ' . $baseURL . '/installer'); |
||
| 27 | exit; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | $appEnv = $context['APP_ENV'] ?? 'dev'; |
||
| 32 | $debug = (bool) ($context['APP_DEBUG'] ?? ($appEnv !== 'prod')); |
||
| 33 | |||
| 34 | $trustedProxies = $context['TRUSTED_PROXIES'] ?? false; |
||
| 35 | if ($trustedProxies) { |
||
| 36 | Request::setTrustedProxies( |
||
| 37 | explode(',', $trustedProxies), |
||
| 38 | Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | $trustedHosts = $context['TRUSTED_HOSTS'] ?? false; |
||
| 43 | if ($trustedHosts) { |
||
| 44 | Request::setTrustedHosts(explode(',', $trustedHosts)); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!file_exists(dirname(__DIR__) . '/install.lock')) { |
||
| 48 | return new InstallerKernel($appEnv, $debug); |
||
| 49 | } |
||
| 50 | |||
| 51 | $shopwareHttpKernel = new HttpKernel($appEnv, $debug, $classLoader); |
||
| 52 | |||
| 53 | return new class($shopwareHttpKernel) implements HttpKernelInterface, TerminableInterface { |
||
| 54 | private HttpKernel $httpKernel; |
||
| 55 | |||
| 56 | public function __construct(HttpKernel $httpKernel) |
||
| 57 | { |
||
| 58 | $this->httpKernel = $httpKernel; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response |
||
| 62 | { |
||
| 63 | return $this->httpKernel->handle($request, $type, $catch)->getResponse(); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function terminate(Request $request, Response $response): void |
||
| 67 | { |
||
| 68 | $this->httpKernel->terminate($request, $response); |
||
| 69 | } |
||
| 72 |