RestoreTenant   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 16 3
1
<?php
2
3
namespace Slides\Saml2\Commands;
4
5
use Slides\Saml2\Repositories\TenantRepository;
6
7
/**
8
 * Class RestoreTenant
9
 *
10
 * @package Slides\Saml2\Commands
11
 */
12
class RestoreTenant extends \Illuminate\Console\Command
13
{
14
    use RendersTenants;
0 ignored issues
show
introduced by
The trait Slides\Saml2\Commands\RendersTenants requires some properties which are not provided by Slides\Saml2\Commands\RestoreTenant: $uuid, $relay_state_url, $idp_x509_cert, $key, $idp_entity_id, $id, $name_id_format, $metadata, $created_at, $idp_logout_url, $idp_login_url, $updated_at, $deleted_at
Loading history...
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'saml2:restore-tenant {id}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Restore a tenant by ID';
29
30
    /**
31
     * @var TenantRepository
32
     */
33
    protected $tenants;
34
35
    /**
36
     * DeleteTenant constructor.
37
     *
38
     * @param TenantRepository $tenants
39
     */
40
    public function __construct(TenantRepository $tenants)
41
    {
42
        $this->tenants = $tenants;
43
44
        parent::__construct();
45
    }
46
47
    /**
48
     * Execute the console command.
49
     *
50
     * @return void
51
     */
52
    public function handle()
53
    {
54
        if(!$tenant = $this->tenants->findById($this->argument('id'))) {
0 ignored issues
show
Bug introduced by
$this->argument('id') of type array|null|string is incompatible with the type integer expected by parameter $id of Slides\Saml2\Repositorie...tRepository::findById(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

54
        if(!$tenant = $this->tenants->findById(/** @scrutinizer ignore-type */ $this->argument('id'))) {
Loading history...
55
            $this->error('Cannot find a tenant #' . $this->argument('id'));
0 ignored issues
show
Bug introduced by
Are you sure $this->argument('id') of type array|null|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
            $this->error('Cannot find a tenant #' . /** @scrutinizer ignore-type */ $this->argument('id'));
Loading history...
56
            return;
57
        }
58
59
        $this->renderTenants($tenant, 'Found a deleted tenant');
60
61
        if(!$this->confirm('Would you like to restore it?')) {
62
            return;
63
        }
64
65
        $tenant->restore();
66
67
        $this->info('The tenant #' . $tenant->id . ' successfully restored.');
68
    }
69
}