Completed
Push — master ( e7ed50...ceaca0 )
by Ryan
02:06
created

PermissionFormHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 1
c 4
b 0
f 0
lcom 0
cbo 1
dl 0
loc 42
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 1
1
<?php namespace Anomaly\UsersModule\User\Permission;
2
3
use Anomaly\UsersModule\User\Contract\UserInterface;
4
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
5
use Illuminate\Routing\Redirector;
6
7
/**
8
 * Class PermissionFormHandler
9
 *
10
 * @link          http://anomaly.is/streams-platform
11
 * @author        AnomalyLabs, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 * @package       Anomaly\UsersModule\User\Permission
14
 */
15
class PermissionFormHandler
16
{
17
18
    /**
19
     * Handle the form.
20
     *
21
     * @param PermissionFormBuilder   $builder
22
     * @param UserRepositoryInterface $users
23
     * @param Redirector              $redirect
24
     */
25
    public function handle(PermissionFormBuilder $builder, UserRepositoryInterface $users, Redirector $redirect)
26
    {
27
        /* @var UserInterface $user */
28
        $user = $builder->getEntry();
29
dd(array_keys(
30
    array_dot(
31
        array_map(
32
            function ($values) {
33
                return array_combine(array_values($values), array_pad([], count($values), true));
34
            },
35
            array_filter($builder->getFormInput())
36
        )
37
    )
38
));
39
        $users->save(
40
            $user->setPermissions(
41
                array_keys(
42
                    array_dot(
43
                        array_map(
44
                            function ($values) {
45
                                return array_combine(array_values($values), array_pad([], count($values), true));
46
                            },
47
                            array_filter($builder->getFormInput())
48
                        )
49
                    )
50
                )
51
            )
52
        );
53
54
        $builder->setFormResponse($redirect->refresh());
55
    }
56
}
57