Completed
Branch v2.0.0 (887ffb)
by Alexander
05:43
created

UserClientService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 7
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createUser() 0 24 3
A deleteUser() 0 3 1
A usersList() 0 4 1
A retrieveUserById() 0 6 1
1
<?php
2
3
namespace Domain\User;
4
5
use Core\Domain\DomainClientService;
6
use Domain\User\Exceptions\UserException;
7
use Domain\User\Factories\UserFactory;
8
use Phalcon\Db\Adapter\Pdo\Postgresql;
9
use stdClass;
10
11
class UserClientService extends DomainClientService
12
{
13
    public function createUser(stdClass $data): int
14
    {
15
        /** @var Postgresql */
16
        $db = $this->getDI()->get('db');
17
        $db->begin();
18
19
        try {
20
            $user = UserFactory::create($data);
21
            $repository = new UserRepository();
22
23
            $id = $repository->insertUserIntoDb($user);
24
            $db->commit();
25
26
            $user->setId($id);
27
28
            return $user->getId();
29
        } catch (UserException $e) {
30
            if ($db->isUnderTransaction()) {
31
                $db->rollback();
32
            }
33
34
            throw $e;
35
        }
36
    }
37
38
    public function retrieveUserById(int $id): stdClass
39
    {
40
        $user = UserFactory::retrieveById($id);
41
42
        return UserPresenter::singleUserObject($user);
43
    }
44
45
    public function deleteUser(array $params = [])
46
    {
47
    }
48
49
    public function usersList(array $params = [])
50
    {
51
        // Build and return users list
52
    }
53
}
54