CreateTaskCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 8 1
A getDetails() 0 9 1
A display() 0 14 1
1
<?php
2
3
namespace Chriscreates\Projects\Commands;
4
5
use Chriscreates\Projects\Models\Task;
6
use Illuminate\Console\Command;
7
8
class CreateTaskCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'projects:create-task';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Laravel Artisan Command to create a new task.';
23
24
    /**
25
     * Task model.
26
     *
27
     * @var object
28
     */
29
    private $task;
30
31
    /**
32
     * Create a new command instance.
33
     *
34
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
     */
36
    public function __construct(Task $task)
37
    {
38
        parent::__construct();
39
40
        $this->task = $task;
41
    }
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * @return mixed
47
     */
48
    public function handle()
49
    {
50
        $details = $this->getDetails();
51
52
        $task = $this->task->create($details);
53
54
        $this->display($task);
55
    }
56
57
    /**
58
     * Ask for task details.
59
     *
60
     * @return array
61
     */
62
    private function getDetails() : array
63
    {
64
        return [
65
            'title' => $this->ask('Title'),
66
            'description' => $this->ask('Description'),
67
            'notes' => $this->ask('Notes'),
68
            'complete' => $this->ask('Complete'),
69
        ];
70
    }
71
72
    /**
73
     * Display created task.
74
     *
75
     * @param array $task
76
     * @return void
77
     */
78
    private function display(Task $task) : void
79
    {
80
        $headers = ['Title', 'Description', 'Notes', 'Complete'];
81
82
        $fields = [
83
            'title' => $task->title,
84
            'description' => $task->description,
85
            'notes' => $task->notes,
86
            'complete' => $task->complete,
87
        ];
88
89
        $this->info('Task created!');
90
        $this->table($headers, [$fields]);
91
    }
92
}
93