ImportWards   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 58
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 19 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace App\Console\Commands;
5
6
use App;
7
use App\Console\Commands\Interfaces\WithIntegerExitCode;
8
use App\Services\ImportService;
9
use Illuminate\Console\Command;
10
11
class ImportWards extends Command implements WithIntegerExitCode
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = "import:wards
19
                            {file_path : Path to file containing wards}";
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = "Import stage wards from file";
27
28
    /**
29
     * @var ImportService
30
     */
31
    protected $importService;
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @param ImportService $importService
37
     */
38
    public function __construct(ImportService $importService)
39
    {
40
        parent::__construct();
41
42
        $this->importService = $importService;
43
    }
44
45
    /**
46
     * Execute the console command.
47
     *
48
     * @return int exit code
49
     */
50
    public function handle() : int
51
    {
52
53
        $filePath = $this->argument("file_path");
54
55
        $errors = $this->importService->validate($filePath);
56
57
        if (empty($errors) === false) {
58
            foreach ($errors as $error) {
59
                $this->error($error);
60
            }
61
            return self::INVALID_INPUT;
62
        }
63
64
        $this->importService->import($filePath, App\Models\Ward::class);
65
66
        $this->info("Wards imported successfully");
67
68
        return self::SUCCESS;
69
70
    }
71
72
}
73