• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prooph / event-store-client / 9555551525

17 Jun 2024 10:16PM UTC coverage: 70.262% (-1.1%) from 71.395%
9555551525

push

github

prolic
update coveralls repo token

3466 of 4933 relevant lines covered (70.26%)

67.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.85
/src/UserManagement/UsersManager.php
1
<?php
2

3
/**
4
 * This file is part of `prooph/event-store-client`.
5
 * (c) 2018-2024 Alexander Miertsch <kontakt@codeliner.ws>
6
 * (c) 2018-2024 Sascha-Oliver Prolic <saschaprolic@googlemail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Prooph\EventStoreClient\UserManagement;
15

16
use Prooph\EventStore\EndPoint;
17
use Prooph\EventStore\Exception\InvalidArgumentException;
18
use Prooph\EventStore\UserCredentials;
19
use Prooph\EventStore\UserManagement\ChangePasswordDetails;
20
use Prooph\EventStore\UserManagement\ResetPasswordDetails;
21
use Prooph\EventStore\UserManagement\UserCreationInformation;
22
use Prooph\EventStore\UserManagement\UserDetails;
23
use Prooph\EventStore\UserManagement\UsersManager as UsersManagerInterface;
24
use Prooph\EventStore\UserManagement\UserUpdateInformation;
25

26
class UsersManager implements UsersManagerInterface
27
{
28
    private readonly UsersClient $client;
29

30
    private readonly EndPoint $endPoint;
31

32
    private readonly ?UserCredentials $defaultCredentials;
33

34
    public function __construct(
35
        EndPoint $endPoint,
36
        int $operationTimeout,
37
        bool $tlsTerminatedEndpoint = false,
38
        bool $verifyPeer = true,
39
        ?UserCredentials $userCredentials = null
40
    ) {
41
        $this->client = new UsersClient($operationTimeout, $tlsTerminatedEndpoint, $verifyPeer);
161✔
42
        $this->endPoint = $endPoint;
161✔
43
        $this->defaultCredentials = $userCredentials;
161✔
44
    }
45

46
    public function enable(string $login, ?UserCredentials $userCredentials = null): void
47
    {
48
        if (empty($login)) {
2✔
49
            throw new InvalidArgumentException('Login cannot be empty');
1✔
50
        }
51

52
        $this->client->enable(
1✔
53
            $this->endPoint,
1✔
54
            $login,
1✔
55
            $userCredentials ?? $this->defaultCredentials
1✔
56
        );
1✔
57
    }
58

59
    public function disable(string $login, ?UserCredentials $userCredentials = null): void
60
    {
61
        if (empty($login)) {
2✔
62
            throw new InvalidArgumentException('Login cannot be empty');
1✔
63
        }
64

65
        $this->client->disable(
1✔
66
            $this->endPoint,
1✔
67
            $login,
1✔
68
            $userCredentials ?? $this->defaultCredentials
1✔
69
        );
1✔
70
    }
71

72
    /** @inheritdoc */
73
    public function deleteUser(string $login, ?UserCredentials $userCredentials = null): void
74
    {
75
        if (empty($login)) {
139✔
76
            throw new InvalidArgumentException('Login cannot be empty');
1✔
77
        }
78

79
        $this->client->delete(
138✔
80
            $this->endPoint,
138✔
81
            $login,
138✔
82
            $userCredentials ?? $this->defaultCredentials
138✔
83
        );
138✔
84
    }
85

86
    /** @inheritdoc */
87
    public function listAll(?UserCredentials $userCredentials = null): array
88
    {
89
        return $this->client->listAll(
2✔
90
            $this->endPoint,
2✔
91
            $userCredentials ?? $this->defaultCredentials
2✔
92
        );
2✔
93
    }
94

95
    public function getCurrentUser(?UserCredentials $userCredentials = null): UserDetails
96
    {
97
        return $this->client->getCurrentUser(
2✔
98
            $this->endPoint,
2✔
99
            $userCredentials ?? $this->defaultCredentials
2✔
100
        );
2✔
101
    }
102

103
    public function getUser(string $login, ?UserCredentials $userCredentials = null): UserDetails
104
    {
105
        if (empty($login)) {
4✔
106
            throw new InvalidArgumentException('Login cannot be empty');
1✔
107
        }
108

109
        return $this->client->getUser(
3✔
110
            $this->endPoint,
3✔
111
            $login,
3✔
112
            $userCredentials ?? $this->defaultCredentials
3✔
113
        );
3✔
114
    }
115

116
    /** @inheritdoc */
117
    public function createUser(
118
        string $login,
119
        string $fullName,
120
        array $groups,
121
        string $password,
122
        ?UserCredentials $userCredentials = null
123
    ): void {
124
        if (empty($login)) {
154✔
125
            throw new InvalidArgumentException('Login cannot be empty');
1✔
126
        }
127

128
        if (empty($fullName)) {
153✔
129
            throw new InvalidArgumentException('FullName cannot be empty');
1✔
130
        }
131

132
        if (empty($password)) {
152✔
133
            throw new InvalidArgumentException('Password cannot be empty');
1✔
134
        }
135

136
        foreach ($groups as $group) {
151✔
137
            if (empty($group)) {
151✔
138
                throw new InvalidArgumentException('Expected an array of non empty strings for group');
×
139
            }
140
        }
141

142
        $this->client->createUser(
151✔
143
            $this->endPoint,
151✔
144
            new UserCreationInformation(
151✔
145
                $login,
151✔
146
                $fullName,
151✔
147
                $groups,
151✔
148
                $password
151✔
149
            ),
151✔
150
            $userCredentials ?? $this->defaultCredentials
151✔
151
        );
151✔
152
    }
153

154
    /** @inheritdoc */
155
    public function updateUser(
156
        string $login,
157
        string $fullName,
158
        array $groups,
159
        ?UserCredentials $userCredentials = null
160
    ): void {
161
        if (empty($login)) {
4✔
162
            throw new InvalidArgumentException('Login cannot be empty');
1✔
163
        }
164

165
        if (empty($fullName)) {
3✔
166
            throw new InvalidArgumentException('FullName cannot be empty');
1✔
167
        }
168

169
        foreach ($groups as $group) {
2✔
170
            if (empty($group)) {
2✔
171
                throw new InvalidArgumentException('Expected an array of non empty strings for group');
×
172
            }
173
        }
174

175
        $this->client->updateUser(
2✔
176
            $this->endPoint,
2✔
177
            $login,
2✔
178
            new UserUpdateInformation($fullName, $groups),
2✔
179
            $userCredentials ?? $this->defaultCredentials
2✔
180
        );
2✔
181
    }
182

183
    public function changePassword(
184
        string $login,
185
        string $oldPassword,
186
        string $newPassword,
187
        ?UserCredentials $userCredentials = null
188
    ): void {
189
        if (empty($login)) {
5✔
190
            throw new InvalidArgumentException('Login cannot be empty');
1✔
191
        }
192

193
        if (empty($oldPassword)) {
4✔
194
            throw new InvalidArgumentException('Old password cannot be empty');
1✔
195
        }
196

197
        if (empty($newPassword)) {
3✔
198
            throw new InvalidArgumentException('New password cannot be empty');
1✔
199
        }
200

201
        $this->client->changePassword(
2✔
202
            $this->endPoint,
2✔
203
            $login,
2✔
204
            new ChangePasswordDetails($oldPassword, $newPassword),
2✔
205
            $userCredentials ?? $this->defaultCredentials
2✔
206
        );
2✔
207
    }
208

209
    public function resetPassword(
210
        string $login,
211
        string $newPassword,
212
        ?UserCredentials $userCredentials = null
213
    ): void {
214
        if (empty($login)) {
3✔
215
            throw new InvalidArgumentException('Login cannot be empty');
1✔
216
        }
217

218
        if (empty($newPassword)) {
2✔
219
            throw new InvalidArgumentException('New password cannot be empty');
1✔
220
        }
221

222
        $this->client->resetPassword(
1✔
223
            $this->endPoint,
1✔
224
            $login,
1✔
225
            new ResetPasswordDetails($newPassword),
1✔
226
            $userCredentials ?? $this->defaultCredentials
1✔
227
        );
1✔
228
    }
229
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc