Completed
Push — master ( 4d6b90...85818a )
by Mahmoud
03:14
created

UpdateUserService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B run() 0 26 5
1
<?php
2
3
namespace App\Containers\User\Services;
4
5
use App\Containers\ApiAuthentication\Exceptions\UpdateResourceFailedException;
6
use App\Containers\User\Contracts\UserRepositoryInterface;
7
use App\Port\Service\Abstracts\Service;
8
9
/**
10
 * Class UpdateUserService.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class UpdateUserService extends Service
15
{
16
17
    /**
18
     * @var \App\Containers\User\Contracts\UserRepositoryInterface
19
     */
20
    private $userRepository;
21
22
    /**
23
     * UpdateUserAction constructor.
24
     *
25
     * @param \App\Containers\User\Contracts\UserRepositoryInterface $userRepository
26
     */
27
    public function __construct(UserRepositoryInterface $userRepository)
28
    {
29
        $this->userRepository = $userRepository;
30
    }
31
32
33
    /**
34
     * @param      $userId
35
     * @param null $password
36
     * @param null $name
37
     * @param null $email
38
     *
39
     * @return  mixed
40
     */
41
    public function run($userId, $password = null, $name = null, $email = null)
42
    {
43
        $attributes = [];
44
45
        if ($password) {
46
            $attributes['password'] = $password;
47
        }
48
49
        if ($name) {
50
            $attributes['name'] = $name;
51
        }
52
53
        if ($email) {
54
            $attributes['email'] = $email;
55
        }
56
57
        // check if data is empty
58
        if (!$attributes) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $attributes of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
59
            throw new UpdateResourceFailedException('Inputs are empty.');
60
        }
61
62
        // updating the attributes
63
        $user = $this->userRepository->update($attributes, $userId);
64
65
        return $user;
66
    }
67
68
69
}
70