Completed
Push — master ( 9abbc7...a687e5 )
by Fabrizio
03:03
created

DeleteCategory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 4 Features 1
Metric Value
wmc 6
c 5
b 4
f 1
lcom 1
cbo 1
dl 0
loc 73
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getArguments() 0 6 1
A isIntegerValue() 0 4 1
A fire() 0 17 3
1
<?php
2
3
namespace Fenos\Notifynder\Artisan;
4
5
use Fenos\Notifynder\Contracts\NotifynderCategory;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class DeleteCategory extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'notifynder:delete:category';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Delete a notifynder category by ID or Name given';
24
25
    /**
26
     * @var \\Fenos\Notifynder\Contracts\NotifynderCategory
27
     */
28
    private $notifynderCategory;
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @param  NotifynderCategory                       $notifynderCategory
34
     * @return \Fenos\Notifynder\Artisan\DeleteCategory
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...
35
     */
36
    public function __construct(NotifynderCategory $notifynderCategory)
37
    {
38
        parent::__construct();
39
        $this->notifynderCategory = $notifynderCategory;
0 ignored issues
show
Documentation Bug introduced by
It seems like $notifynderCategory of type object<Fenos\Notifynder\...cts\NotifynderCategory> is incompatible with the declared type object<\Fenos\Notifynder...cts\NotifynderCategory> of property $notifynderCategory.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return mixed
46
     */
47
    public function fire()
48
    {
49
        $identifier = $this->argument('identifier');
50
51
        if ($this->isIntegerValue($identifier)) {
52
            $delete = $this->notifynderCategory->delete($identifier);
53
        } else {
54
            $delete = $this->notifynderCategory->deleteByName($identifier);
55
        }
56
57
        if (! $delete) {
58
            $this->error('Category Not found');
59
60
            return false;
61
        }
62
        $this->info('Category has been deleted');
63
    }
64
65
    public function isIntegerValue($identifier)
66
    {
67
        return preg_match('/[0-9]/', $identifier);
68
    }
69
70
    /**
71
     * Get the console command arguments.
72
     *
73
     * @return array
74
     */
75
    protected function getArguments()
76
    {
77
        return [
78
            ['identifier', InputArgument::REQUIRED, '1 - nameCategory'],
79
        ];
80
    }
81
}
82