Completed
Push — master ( fe4c38...cc65b4 )
by Eric
06:25
created

ShowArticleCommand::__construct()   A

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 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) {
0 ignored issues
show
Bug introduced by
The class Mockery\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
63
            $this->error('Error');
64
        }
65
    }
66
}
67