Test Failed
Branch master (52949b)
by Artem
05:53
created

DeleteTenant::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Slides\Saml2\Commands;
4
5
use Slides\Saml2\Repositories\TenantRepository;
6
7
/**
8
 * Class DeleteTenant
9
 *
10
 * @package Slides\Saml2\Commands
11
 */
12
class DeleteTenant extends \Illuminate\Console\Command
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
    use RendersTenants;
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'saml2:delete-tenant {tenant}
22
                            { --safe : Safe deletion }';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Delete a tenant by ID, key or UUID';
30
31
    /**
32
     * @var TenantRepository
33
     */
34
    protected $tenants;
35
36
    /**
37
     * DeleteTenant constructor.
38
     *
39
     * @param TenantRepository $tenants
40
     */
41
    public function __construct(TenantRepository $tenants)
42
    {
43
        $this->tenants = $tenants;
44
45
        parent::__construct();
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @return void
52
     */
53
    public function handle()
54
    {
55
        $tenants = $this->tenants->findByAnyIdentifier($this->argument('tenant'), false);
56
57
        if($tenants->isEmpty()) {
58
            $this->error('Cannot find a matching tenant by "' . $this->argument('tenant') . '" identifier');
59
            return;
60
        }
61
62
        $this->renderTenants($tenants, 'Found tenant(s)');
63
64
        if($tenants->count() > 1) {
65
            $deletingId = $this->ask('We have found several tenants, which one would you like to delete? (enter its ID)');
66
        }
67
        else {
68
            $deletingId = $tenants->first()->id;
69
        }
70
71
        $tenant = $tenants->firstWhere('id', $deletingId);
72
73
        if($this->option('safe')) {
74
            $tenant->delete();
75
76
            $this->info('The tenant #' . $deletingId . ' safely deleted. To restore it, run:');
77
            $this->output->block('php artisan saml2:restore-tenant ' . $deletingId);
78
79
            return;
80
        }
81
82
        if(!$this->confirm('Would you like to forcely delete the tenant #' . $deletingId . '? It cannot be reverted.')) {
83
            return;
84
        }
85
86
        $tenant->forceDelete();
87
88
        $this->info('The tenant #' . $deletingId . ' safely deleted.');
89
    }
90
}