| 1 | <?php |
||
| 2 | |||
| 3 | namespace Turahe\LaravelInstaller\Middleware; |
||
| 4 | |||
| 5 | use Closure; |
||
| 6 | use Illuminate\Http\Request; |
||
| 7 | use Illuminate\Http\RedirectResponse; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Class CanInstall. |
||
| 11 | */ |
||
| 12 | class CanInstall |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Handle an incoming request. |
||
| 16 | * |
||
| 17 | * @param Request $request |
||
| 18 | * @param Closure $next |
||
| 19 | * @return mixed|RedirectResponse |
||
| 20 | */ |
||
| 21 | public function handle($request, Closure $next): RedirectResponse |
||
| 22 | { |
||
| 23 | if ($this->alreadyInstalled()) { |
||
| 24 | $installedRedirect = config('installer.installedAlreadyAction'); |
||
| 25 | |||
| 26 | switch ($installedRedirect) { |
||
| 27 | |||
| 28 | case 'route': |
||
| 29 | $routeName = config('installer.installed.redirectOptions.route.name'); |
||
| 30 | $data = config('installer.installed.redirectOptions.route.message'); |
||
| 31 | |||
| 32 | return redirect()->route($routeName)->with(['data' => $data]); |
||
| 33 | break; |
||
|
0 ignored issues
–
show
|
|||
| 34 | |||
| 35 | case 'abort': |
||
| 36 | abort(config('installer.installed.redirectOptions.abort.type')); |
||
| 37 | break; |
||
| 38 | |||
| 39 | case 'dump': |
||
| 40 | $dump = config('installer.installed.redirectOptions.dump.data'); |
||
| 41 | dd($dump); |
||
| 42 | break; |
||
| 43 | |||
| 44 | case '404': |
||
| 45 | case 'default': |
||
| 46 | default: |
||
| 47 | abort(404); |
||
| 48 | break; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | return $next($request); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * If application is already installed. |
||
| 57 | * |
||
| 58 | * @return bool |
||
| 59 | */ |
||
| 60 | public function alreadyInstalled(): bool |
||
| 61 | { |
||
| 62 | return file_exists(storage_path('installed')); |
||
| 63 | } |
||
| 64 | } |
||
| 65 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.