AssociateActivationRoles   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 3
1
<?php namespace Anomaly\UsersModule\User\Register\Command;
2
3
use Anomaly\UsersModule\Role\Command\GetRole;
4
use Anomaly\UsersModule\User\Contract\UserInterface;
5
use Anomaly\UsersModule\User\Register\RegisterFormBuilder;
6
use Illuminate\Foundation\Bus\DispatchesJobs;
7
8
/**
9
 * Class AssociateActivationRoles
10
 *
11
 * @link          http://pyrocms.com/
12
 * @author        PyroCMS, Inc. <[email protected]>
13
 * @author        Ryan Thompson <[email protected]>
14
 */
15
class AssociateActivationRoles
16
{
17
18
    use DispatchesJobs;
19
20
    /**
21
     * The form builder.
22
     *
23
     * @var RegisterFormBuilder
24
     */
25
    protected $builder;
26
27
    /**
28
     * Create a new AssociateActivationRoles instance.
29
     *
30
     * @param RegisterFormBuilder $builder
31
     */
32
    public function __construct(RegisterFormBuilder $builder)
33
    {
34
        $this->builder = $builder;
35
    }
36
37
    /**
38
     * Handle the command.
39
     */
40
    public function handle()
41
    {
42
        /* @var UserInterface $user */
43
        $user = $this->builder->getFormEntry();
44
45
        foreach ($this->builder->getRoles() as $role) {
46
            if ($role = $this->dispatch(new GetRole($role))) {
47
                $user->attachRole($role);
48
            }
49
        }
50
    }
51
}
52