DeleteArticleCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 3
1
<?php
2
3
namespace Ergare17\Articles\Console\Commands;
4
5
use Ergare17\Articles\Console\Commands\Traits\AsksForArticles;
6
use Ergare17\Articles\Models\Article;
7
use http\Exception;
8
use Illuminate\Console\Command;
9
10
class DeleteArticleCommand extends Command
11
{
12
    use AsksForArticles;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'article:delete {id? : The article id}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Delete 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
            $id = $this->argument('id') ? $this->argument('id') : $this->askForArticles();
47
            $article = Article::findOrFail($id);
48
            $article->delete();
49
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class http\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...
50
            $this->error('Error');
51
        }
52
        $this->info('Article has been deleted to database succesfully');
53
    }
54
}
55