Completed
Push — master ( 063bdc...995895 )
by Mahmoud
04:00
created

FindUserService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A byId() 0 7 1
A byVisitorId() 0 6 1
1
<?php
2
3
namespace App\Containers\User\Services;
4
5
use App\Containers\User\Contracts\UserRepositoryInterface;
6
use App\Port\Service\Abstracts\Service;
7
8
/**
9
 * Class FindUserService.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class FindUserService extends Service
14
{
15
16
    /**
17
     * @var \App\Containers\User\Contracts\UserRepositoryInterface
18
     */
19
    private $userRepository;
20
21
    /**
22
     * FindUserService constructor.
23
     *
24
     * @param \App\Containers\User\Contracts\UserRepositoryInterface $userRepository
25
     */
26
    public function __construct(UserRepositoryInterface $userRepository)
27
    {
28
        $this->userRepository = $userRepository;
29
    }
30
31
    /**
32
     * @param $id
33
     *
34
     * @return  mixed
35
     */
36
    public function byId($id)
37
    {
38
        // find the user by its id
39
        $user = $this->userRepository->find($id);
40
41
        return $user;
42
    }
43
44
    /**
45
     * @param $visitorId
46
     *
47
     * @return  mixed
48
     */
49
    public function byVisitorId($visitorId)
50
    {
51
        $user = $this->userRepository->findByField('visitor_id', $visitorId)->first();
52
53
        return $user;
54
    }
55
}
56