Store   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 27 4
1
<?php
2
3
namespace App\Http\Controllers\Gedcom;
4
5
use App\Event;
6
use App\Family;
7
use App\Http\Controllers\Controller;
8
use App\Jobs\ImportGedcom;
9
use App\Note;
10
use App\Person;
11
use App\Source;
12
use App\Traits\ConnectionTrait;
13
use Auth;
14
use Illuminate\Http\Request;
15
use Illuminate\Support\Facades\Artisan;
16
use LaravelEnso\Multitenancy\Enums\Connections;
17
use ModularSoftware\LaravelGedcom\Facades\GedcomParserFacade;
18
use ModularSoftware\LaravelGedcom\Utils\GedcomParser;
19
20
class Store extends Controller
21
{
22
    use ConnectionTrait;
23
    /*
24
    * Api end-point for Gedcom api/gedcom/store
25
    * Saving uploaded file to storage and starting to read
26
    */
27
28
    public function __invoke(Request $request)
29
    {
30
        $slug = $request->get('slug');
31
        if ($request->hasFile('file')) {
32
            if ($request->file('file')->isValid()) {
33
                try {
34
                    $conn = $this->getConnection();
35
                    $db = $this->getDB();
36
                    $currentUser = Auth::user();
37
                    $_name = uniqid().'.ged';
38
                    $request->file->storeAs('gedcom', $_name);
39
                    define('STDIN', fopen('php://stdin', 'r'));
40
                    // $parser = new GedcomParser();
41
                    // $parser->parse($request->file('file'), $slug, true);
42
                    $filename = 'app/gedcom/'.$_name;
43
                    ImportGedcom::dispatch($filename, $slug, $currentUser->id, $conn, $db);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
44
                    // Artisan::call('queue:work');
45
                    return ['File uploaded'];
46
                } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Gedcom\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
47
                    return ['Not uploaded'];
48
                }
49
            }
50
51
            return ['File corrupted'];
52
        }
53
54
        return ['Not uploaded'];
55
    }
56
}
57