Store   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 16
c 1
b 1
f 0
dl 0
loc 24
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 22 2
1
<?php
2
3
namespace App\Http\Controllers\Gedcom;
4
5
use App\Http\Controllers\Controller;
6
use App\Jobs\ImportGedcom;
7
use App\Tenant\Manager;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Response;
10
11
class Store extends Controller
12
{
13
    public function __invoke(Request $request): Response
14
    {
15
        if ($request->file('file')->getClientOriginalExtension() !== 'ged') {
16
            return response([
17
                'msg' => 'file type invalid',
18
            ], 422);
19
        }
20
21
        $request->validate([
22
            'slug' => 'required|string',
23
            'file' => 'required',
24
        ]);
25
        $slug = $request->slug;
26
        $file = $request->file('file');
27
        \Log::info(json_encode($request->user()->company(), JSON_THROW_ON_ERROR));
28
        $manager = Manager::fromModel($request->user()->company(), $request->user());
29
        $path = $manager->storage()->putFile('imports', $file);
30
31
        ImportGedcom::dispatch($request->user(), $manager->storagePath($path), $slug);
0 ignored issues
show
Bug introduced by
It seems like $path can also be of type false; however, parameter $path of App\Tenant\Manager::storagePath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        ImportGedcom::dispatch($request->user(), $manager->storagePath(/** @scrutinizer ignore-type */ $path), $slug);
Loading history...
32
33
        return response([
34
            'message' => 'Gedcom Import Dispatched',
35
        ]);
36
    }
37
}
38