ShowArticleCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 56
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 22 4
1
<?php
2
3
namespace Ergare17\Articles\Console\Commands;
4
5
use App\User;
6
use Ergare17\Articles\Console\Commands\Traits\AsksForArticles;
7
use Ergare17\Articles\Models\Article;
8
use Illuminate\Console\Command;
9
use Mockery\Exception;
10
11
class ShowArticleCommand extends Command
12
{
13
    use AsksForArticles;
14
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'article:show {id? : The article id to show}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Show an articl';
28
29
    /**
30
     * Create a new command instance.
31
     *
32
     * @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...
33
     */
34
    public function __construct()
35
    {
36
        parent::__construct();
37
    }
38
39
    /**
40
     * Execute the console command.
41
     *
42
     * @return mixed
43
     */
44
    public function handle()
45
    {
46
        $id = $this->argument('id') ? $this->argument('id') : $this->askForArticles();
47
        $article = Article::findOrFail($id);
48
        $user = User::findOrFail($article->user_id);
49
50
        try {
51
            $headers = ['Key', 'Value'];
52
53
            $fields = [
54
                ['Title:', $article->title],
55
                ['Description', $article->description],
56
                ['Read:', $article->read ? 'Yes' : 'No'],
57
                ['User id:', $article->user_id],
58
                ['User name:', $user->name],
59
            ];
60
61
            $this->table($headers, $fields);
62
        } catch (Exception $e) {
63
            $this->error('Error');
64
        }
65
    }
66
}
67