EditArticleCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Ergare17\Articles\Console\Commands;
4
5
use Ergare17\Articles\Console\Commands\Traits\AsksForArticles;
6
use Ergare17\Articles\Console\Commands\Traits\AsksForUsers;
7
use Ergare17\Articles\Models\Article;
8
use Illuminate\Console\Command;
9
use Mockery\Exception;
10
11
/**
12
 * Class EditArticleCommand.
13
 */
14
class EditArticleCommand extends Command
15
{
16
    use AsksForArticles;
17
    use AsksForUsers;
18
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature = 'article:edit {id? : The article id} {title? : The article title} {description? : The article description} {user_id? : The user id}';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Edit an article';
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @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...
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
    }
42
43
    /**
44
     * Execute the console command.
45
     *
46
     * @return mixed
47
     */
48
    public function handle()
49
    {
50
        try {
51
            $id = $this->argument('id') ? $this->argument('id') : $this->askForArticles();
52
            $article = Article::findOrFail($id);
53
            $article->update([
54
                'title'        => $this->argument('title') ? $this->argument('title') : $this->ask('Article title?', $article->title),
55
                'description'        => $this->argument('description') ? $this->argument('description') : $this->ask('Article description?', $article->description),
56
                'user_id'     => $this->argument('user_id') ? $this->argument('user_id') : $this->askForUsers(),
57
            ]);
58
        } catch (Exception $e) {
59
            $this->error('Error');
60
        }
61
        $this->info('Article has been edited to database succesfully');
62
    }
63
}
64