findAllUsersResultDataForList()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 3
nop 0
dl 0
loc 29
ccs 19
cts 19
cp 1
crap 3
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Module\User\ListPage\Service;
4
5
use App\Infrastructure\Database\Hydrator;
6
use App\Module\User\Authorization\Service\UserPrivilegeDeterminer;
0 ignored issues
show
Bug introduced by
The type App\Module\User\Authoriz...UserPrivilegeDeterminer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use App\Module\User\Data\UserResultData;
8
use App\Module\User\FindDropdownOptions\Service\AuthorizedUserRoleFilterer;
0 ignored issues
show
Bug introduced by
The type App\Module\User\FindDrop...horizedUserRoleFilterer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use App\Module\User\FindList\Repository\UserListFinderRepository;
10
use App\Module\User\Read\Service\UserReadAuthorizationChecker;
11
12
// Class cannot be readonly as it's mocked (doubled) in tests
13
class UserListPageFinder
14
{
15 4
    public function __construct(
16
        private readonly UserListFinderRepository $userListFinderRepository,
17
        private readonly UserPrivilegeDeterminer $userPrivilegeDeterminer,
18
        private readonly AuthorizedUserRoleFilterer $authorizedUserRoleFilterer,
19
        private readonly UserReadAuthorizationChecker $userReadAuthorizationChecker,
20
        private readonly Hydrator $hydrator,
21
    ) {
22 4
    }
23
24
    /**
25
     * @return UserResultData[]
26
     */
27 4
    public function findAllUsersResultDataForList(): array
28
    {
29 4
        $userResultArray = $this->hydrator->hydrate(
30 4
            $this->userListFinderRepository->findAllUserRows(),
31 4
            UserResultData::class
32 4
        );
33
34 4
        foreach ($userResultArray as $key => $userResultData) {
35
            // Check if authenticated user is allowed to read user
36 4
            if ($this->userReadAuthorizationChecker->isGrantedToRead($userResultData->id)) {
37
                // Authorization limits which entries are in the user role dropdown
38 4
                $userResultData->availableUserRoles = $this->authorizedUserRoleFilterer->filterAuthorizedUserRoles(
39 4
                    $userResultData->userRoleId
40 4
                );
41 4
                $userResultData->userRolePrivilege = $this->userPrivilegeDeterminer->getUserRoleAssignmentPrivilege(
42 4
                    $userResultData->availableUserRoles
43 4
                );
44
45
                // Check if user is allowed to change status
46 4
                $userResultData->statusPrivilege = $this->userPrivilegeDeterminer->getMutationPrivilege(
47 4
                    (int)$userResultData->id,
48 4
                    'status',
49 4
                );
50
            } else {
51 1
                unset($userResultArray[$key]);
52
            }
53
        }
54
55 4
        return $userResultArray;
56
    }
57
}
58