Completed
Pull Request — master (#823)
by Burak
02:27
created

GivePermissionUser::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Permission\Commands;
4
5
use App\User;
6
use Illuminate\Console\Command;
7
use Spatie\Permission\Contracts\Permission as PermissionContract;
8
9 View Code Duplication
class GivePermissionUser extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    protected $signature = 'permission:give-user
12
        {user : User ID}
13
        {name : The name of the permission}
14
        {guard? : The name of the guard}';
15
16
    protected $description = 'Give user a permission';
17
18
    /**
19
     * User model.
20
     *
21
     * @var User $user
22
     */
23
    protected $user;
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @param  User  $user
29
     * @return void
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...
30
     */
31
    public function __construct(User $user)
32
    {
33
        parent::__construct();
34
35
        $this->user = $user;
36
    }
37
38
    public function handle()
39
    {
40
        $permissionClass = app(PermissionContract::class);
41
42
        $user       = $this->user->find($this->argument('user'));
43
        $permission = $permissionClass::findByName($this->argument('name'), $this->argument('guard'));
44
45
        $user->givePermissionTo($permission->name);
46
        $this->info("Permission `{$permission->name}` given to `{$user->name}` (ID:{$user->name})");
47
    }
48
}
49