UserGroupChoices   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getUserGroupChoices() 0 18 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Form/Type/Traits/UserGroupChoices.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Form\Type\Traits;
10
11
use App\Entity\UserGroup;
12
use App\Resource\UserGroupResource;
13
use Throwable;
14
use function array_map;
15
16
/**
17
 * Trait UserGroupChoices
18
 *
19
 * @package App\Form\Type\Traits
20
 * @author TLe, Tarmo Leppänen <[email protected]>
21
 *
22
 * @property UserGroupResource $userGroupResource
23
 */
24
trait UserGroupChoices
25
{
26
    /**
27
     * Method to create choices array for user groups.
28
     *
29
     * @return array<string, string>
30
     *
31
     * @throws Throwable
32
     */
33 2
    protected function getUserGroupChoices(): array
34
    {
35
        // Initialize output
36 2
        $choices = [];
37
38
        /**
39
         * Lambda function to iterate all user groups and to create necessary
40
         * choices array.
41
         */
42 2
        $iterator = static function (UserGroup $userGroup) use (&$choices): void {
43 2
            $name = $userGroup->getName() . ' [' . $userGroup->getRole()->getId() . ']';
44
45 2
            $choices[$name] = $userGroup->getId();
46 2
        };
47
48 2
        array_map($iterator, $this->userGroupResource->find());
49
50 2
        return $choices;
51
    }
52
}
53