GroupsRecord   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 78
ccs 12
cts 39
cp 0.3076
rs 10
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getGroupDesc() 0 3 1
A getGroupParents() 0 3 1
A getGroupStatus() 0 3 1
A getGroupId() 0 3 1
A setGroupData() 0 14 4
A getGroupAuthorId() 0 3 1
A addEntries() 0 12 1
A getGroupExtra() 0 3 1
A getGroupName() 0 3 1
1
<?php
2
3
namespace kalanis\kw_auth_sources\Sources\Mapper\Database;
4
5
6
use kalanis\kw_accounts\AccountsException;
7
use kalanis\kw_accounts\Interfaces\IGroup;
8
use kalanis\kw_auth_sources\Traits\TSeparated;
9
use kalanis\kw_mapper\Interfaces\IEntryType;
10
use kalanis\kw_mapper\MapperException;
11
use kalanis\kw_mapper\Records\ASimpleRecord;
12
13
14
/**
15
 * Class GroupsRecord
16
 * @package kalanis\kw_auth_sources\Sources\Mapper\Database
17
 * @property string $id
18
 * @property string $name
19
 * @property string $desc
20
 * @property string $authorId
21
 * @property string $parents
22
 * @property int $status
23
 * @property array<string|int, string|int|float|bool> $extra
24
 * @property UsersRecord[] $authors
25
 * @property UsersRecord[] $members
26
 * @codeCoverageIgnore remote source
27
 */
28
class GroupsRecord extends ASimpleRecord implements IGroup
29
{
30
    use TSeparated;
31
32 1
    public function addEntries(): void
33
    {
34 1
        $this->addEntry('id', IEntryType::TYPE_STRING, 2048);
35 1
        $this->addEntry('name', IEntryType::TYPE_STRING, 512);
36 1
        $this->addEntry('desc', IEntryType::TYPE_STRING, 512);
37 1
        $this->addEntry('authorId', IEntryType::TYPE_STRING, 128);
38 1
        $this->addEntry('parents', IEntryType::TYPE_STRING, 2048);
39 1
        $this->addEntry('status', IEntryType::TYPE_INTEGER, 4);
40 1
        $this->addEntry('extra', IEntryType::TYPE_ARRAY, []);
41 1
        $this->addEntry('authors', IEntryType::TYPE_ARRAY, []);
42 1
        $this->addEntry('members', IEntryType::TYPE_ARRAY, []);
43 1
        $this->setMapper(GroupsMapper::class);
44 1
    }
45
46
    /**
47
     * @param string|null $id
48
     * @param string|null $name
49
     * @param string|null $desc
50
     * @param string|null $authorId
51
     * @param int|null $status
52
     * @param string[]|null $parents
53
     * @param array<string|int, string|int|float|bool>|null $extra
54
     * @throws AccountsException
55
     * @throws MapperException
56
     */
57
    public function setGroupData(?string $id, ?string $name, ?string $desc, ?string $authorId, ?int $status, ?array $parents = [], ?array $extra = []): void
58
    {
59
        if (empty($id)) {
60
            throw new AccountsException('No user ID');
61
        }
62
        $this->id = $id;
63
        $this->load();
64
        $this->name = $name ?? $this->name;
65
        $this->desc = $desc ?? $this->desc;
66
        $this->authorId = $authorId ?? $this->authorId;
67
        $this->status = $status ?? $this->status;
68
        $this->parents = $parents ? $this->compactStr($parents) : $this->parents;
69
        $this->extra = !is_null($extra) ? array_merge($this->extra, $extra) : $this->extra;
0 ignored issues
show
introduced by
The condition is_null($extra) is always false.
Loading history...
70
        $this->save();
71
    }
72
73
    public function getGroupId(): string
74
    {
75
        return strval($this->id);
76
    }
77
78
    public function getGroupName(): string
79
    {
80
        return strval($this->name);
81
    }
82
83
    public function getGroupDesc(): string
84
    {
85
        return strval($this->desc);
86
    }
87
88
    public function getGroupAuthorId(): string
89
    {
90
        return strval($this->authorId);
91
    }
92
93
    public function getGroupStatus(): int
94
    {
95
        return intval($this->status);
96
    }
97
98
    public function getGroupParents(): array
99
    {
100
        return $this->separateStr($this->parents);
101
    }
102
103
    public function getGroupExtra(): array
104
    {
105
        return (array) $this->extra;
106
    }
107
}
108