CreateTaskCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 15 4
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Task;
6
use Illuminate\Console\Command;
7
use Mockery\Exception;
8
9
class CreateTaskCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    //nom de la comanda quan s'executa.
17
    //També es definieix el format de la comanda, entre {} s'ha de posar els noms dels paràmetres
18
    protected $signature = 'task:create {name? : The Task name} {user_id? : The user id }';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Command description.';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    //aqui s'ha de posar que ha de passar quan s'executa la comanda.
43
    public function handle()
44
    {
45
        //todo fer que aparegui l'error!
46
47
        try {
48
            Task::create([
49
                'name'    => $this->argument('name') ? $this->argument('name') : $this->ask('Task name?'),
50
                'user_id' => $this->argument('user_id') ? $this->argument('user_id') : $this->ask('User id?'),
51
52
            ]);
53
        } catch (Exception $e) {
54
            $this->error('error'.$e);
55
        }
56
57
        $this->info('Task has been added to database succesfully');
58
    }
59
}
60