CreateArticleCommand::handle()   B
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
nc 2
nop 0
dl 0
loc 14
rs 8.8571
c 1
b 0
f 0
1
<?php
2
3
namespace Ergare17\Articles\Console\Commands;
4
5
use Ergare17\Articles\Models\Article;
6
use Illuminate\Console\Command;
7
use Mockery\Exception;
8
use Ergare17\Articles\Console\Commands\Traits\AsksForUsers;
9
10
class CreateArticleCommand extends Command
11
{
12
    use AsksForUsers;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'article:create {title? : The article title} {description? : The article description} {user_id? : The user id}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create an article';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @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...
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return mixed
42
     */
43
    public function handle()
44
    {
45
        try {
46
            Article::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Ergare17\Articles\Models\Article. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
47
                'title' => $this->argument('title') ? $this->argument('title') : $this->ask('Article title?'),
48
                'user_id'     => $this->argument('user_id') ? $this->argument('user_id') : $this->askForUsers(),
49
                'description' => $this->argument('description') ? $this->argument('description') : $this->ask('Article description?'),
50
                'read' => false,
51
            ]);
52
        } catch (Exception $e) {
53
            $this->error('Error');
54
        }
55
        $this->info('Article has been added to database succesfully');
56
    }
57
}
58