UserResultData::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Module\User\Data;
4
5
class UserResultData extends UserData
6
{
7
    public ?string $generalPrivilege = null;
8
    // If the authenticated user is allowed to change status
9
    public ?string $statusPrivilege = null;
10
    // If the authenticated user is allowed to change the password without having to type in the old password
11
    public ?string $passwordWithoutVerificationPrivilege = null;
12
13
    // If the authenticated user is allowed to change role
14
    public ?string $userRolePrivilege = null;
15
16
    // Authorization limits which entries are in the user role dropdown
17
    public array $availableUserRoles = [];
18
19
    /**
20
     * Not all object attributes should be passed to view.
21
     * This function like the toArrayForDatabase returns only
22
     * the relevant attributes.
23
     * Private attributes could also be used as they are not
24
     * serialized by json_encode, but it's a harder to hydrate a
25
     * collection of results.
26
     * It has also an added benefit of exactly controlling what and how its serialized.
27
     */
28 4
    public function jsonSerialize(): array
29
    {
30 4
        return array_merge(parent::jsonSerialize(), [
31 4
            'statusPrivilege' => $this->statusPrivilege,
32 4
            'userRolePrivilege' => $this->userRolePrivilege,
33 4
            'availableUserRoles' => $this->availableUserRoles,
34 4
        ]);
35
    }
36
}
37