AssociateActivationRoles::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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