DeleteUser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 23 5
1
<?php
2
/*
3
 * Copyright (C) 2016 Paul Heinrichs <[email protected]>
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 * DeleteUser.php
20
 *
21
 * @package    LibreNMS
22
 * @author     Paul Heinrichs <[email protected]>
23
 * @copyright  2016 Paul Heinrichs
24
 * @license    @license http://opensource.org/licenses/GPL-3.0 GNU Public License v3 or later
25
 */
26
27
namespace App\Console\Commands;
28
29
use App\Models\User;
30
use Illuminate\Console\Command;
31
32
class DeleteUser extends Command
33
{
34
    /**
35
     * The name and signature of the console command.
36
     *
37
     * @var string
38
     */
39
    protected $signature = 'user:delete
40
                            {user : The user to search}';
41
42
    /**
43
     * The console command description.
44
     *
45
     * @var string
46
     */
47
    protected $description = 'Remove a user';
48
49
    /**
50
     * Create a new command instance.
51
     */
52 87
    public function __construct()
53
    {
54 87
        parent::__construct();
55 87
    }
56
57
    /**
58
     * Execute the console command.
59
     *
60
     * @return mixed
61
     */
62 3
    public function handle()
63
    {
64 3
        $user = $this->argument('user');
65 3
        $user_list = User::select('username')->where('username', 'like', '%'.$user.'%')->orWhere('realname', 'like', '%'.$user.'%')->get();
66 3
        $names = [];
67
68 3
        if (count($user_list) < 1) {
69 1
            $this->info('No user found.');
70 1
            return;
71
        }
72 2
        foreach ($user_list as $i) {
73 2
            array_push($names, $i->username);
74
        }
75 2
        if (count($names) > 1) {
76 1
            $name = $this->choice('Who would you like to remove?', $names);
77
        } else {
78 1
            $name = $names[0];
79
        }
80 2
        if ($this->confirm('Do you wish to remove '.$name.'?')) {
81 2
            User::where('username', $name)->delete();
82 2
            $this->info('User deleted.');
83
        }
84 2
    }
85
}
86