Completed
Push — master ( 7b1812...72843d )
by CodexShaper
05:03
created

DatabaseAdmin::findComposer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 6
rs 10
ccs 0
cts 6
cp 0
crap 6
1
<?php
2
namespace CodexShaper\DBM\Commands;
3
4
use CodexShaper\DBM\Facades\Manager;
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Symfony\Component\Console\Input\InputOption;
8
9
class DatabaseAdmin extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'dbm:admin {email} {action=create} {--c|column=email}';
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Make Database Admin';
23
    /**
24
     * Get Option
25
     *
26
     * @return array
27
     */
28
    protected function getOptions()
29
    {
30
        return [
31
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null],
32
        ];
33
    }
34
35
    /**
36
     * Get the composer command for the environment.
37
     *
38
     * @return string
39
     */
40
    protected function findComposer()
41
    {
42
        if (file_exists(getcwd() . '/composer.phar')) {
43
            return '"' . PHP_BINARY . '" ' . getcwd() . '/composer.phar';
44
        }
45
        return 'composer';
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @param \Illuminate\Filesystem\Filesystem $filesystem
52
     *
53
     * @return void
54
     */
55
    public function handle(Filesystem $filesystem)
0 ignored issues
show
Unused Code introduced by
The parameter $filesystem is not used and could be removed. ( Ignorable by Annotation )

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

55
    public function handle(/** @scrutinizer ignore-unused */ Filesystem $filesystem)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        $email          = $this->argument('email');
58
        $column         = $this->option('column');
59
        $permissions    = Manager::Permission()->all();
60
        $successMessage = "Admin Created successfully";
61
62
        if ($this->argument('action') == 'drop') {
63
            $permissions    = [];
64
            $successMessage = "Admin Deleted successfully";
65
        }
66
67
        $userModel   = config('dbm.user.model');
68
        $userTable   = config('dbm.user.table');
69
        $localObject = Manager::model($userModel, $userTable)
70
            ->where($column, $email)
71
            ->first();
72
        Manager::Object()
73
            ->setManyToManyRelation(
74
                $localObject,
75
                Manager::Permission(),
76
                'dbm_user_permissions',
77
                'user_id',
78
                'dbm_permission_id'
79
            )
80
            ->belongs_to_many()
81
            ->sync($permissions);
82
        $this->info($successMessage);
83
    }
84
}
85