ApiKeyUserManagementHelperTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A createUserGroups() 0 17 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Command/Traits/ApiKeyUserManagementHelperTrait.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Command\Traits;
10
11
use App\Security\RolesService;
12
use Symfony\Component\Console\Input\ArrayInput;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Throwable;
15
16
/**
17
 * Trait ApiKeyUserManagementHelperTrait
18
 *
19
 * @package App\Command\Traits
20
 * @author TLe, Tarmo Leppänen <[email protected]>
21
 */
22
trait ApiKeyUserManagementHelperTrait
23
{
24
    use GetApplicationTrait;
25
26
    abstract public function getRolesService(): RolesService;
27
28
    /**
29
     * Method to create user groups via existing 'user:create-group' command.
30
     *
31
     * @throws Throwable
32
     */
33
    protected function createUserGroups(OutputInterface $output): void
34
    {
35
        $command = $this->getApplication()->find('user:create-group');
36
37
        // Iterate roles and create user group for each one
38
        foreach ($this->getRolesService()->getRoles() as $role) {
39
            $arguments = [
40
                'command' => 'user:create-group',
41
                '--name' => $this->getRolesService()->getRoleLabel($role),
42
                '--role' => $role,
43
                '-n' => true,
44
            ];
45
46
            $input = new ArrayInput($arguments);
47
            $input->setInteractive(false);
48
49
            $command->run($input, $output);
50
        }
51
    }
52
}
53