Completed
Push — development ( daed94...13a157 )
by Thomas
18s
created

GeoCacheLogService::getLatestUserLog()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\GeoCache\Persistence\GeoCacheLog;
4
5
use Oc\Repository\Exception\RecordNotFoundException;
6
use Oc\Repository\Exception\RecordsNotFoundException;
7
8
class GeoCacheLogService
9
{
10
    /**
11
     * @var GeoCacheLogRepository
0 ignored issues
show
introduced by
GeoCacheLogRepository => \Array\GeoCacheLogRepository
Loading history...
12
     */
13
    private $geoCacheRepository;
14
15
    /**
16
     * @param GeoCacheLogRepository $geoCacheRepository
0 ignored issues
show
introduced by
GeoCacheLogRepository => \Array\GeoCacheLogRepository
Loading history...
17
     */
18
    public function __construct(GeoCacheLogRepository $geoCacheRepository)
19
    {
20
        $this->geoCacheRepository = $geoCacheRepository;
21
    }
22
23
    /**
24
     * Fetches all GeoCacheLogs.
25
     *
26
     * @return GeoCacheLogEntity[]
0 ignored issues
show
introduced by
GeoCacheLogEntity[] => \Array\GeoCacheLogEntity[]
Loading history...
27
     */
28
    public function fetchAll()
29
    {
30
        try {
31
            $result = $this->geoCacheRepository->fetchAll();
32
        } catch (RecordsNotFoundException $e) {
33
            $result = [];
34
        }
35
36
        return $result;
37
    }
38
39
    /**
40
     * Fetches the latest geo cache log for given user id.
41
     *
42
     * @param int $userId
43
     *
44
     * @return GeoCacheLogEntity|null
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
45
     */
46
    public function getLatestUserLog($userId)
47
    {
48
        try {
49
            $result = $this->geoCacheRepository->getLatestUserLog($userId);
50
        } catch (RecordNotFoundException $e) {
51
            $result = null;
52
        }
53
54
        return $result;
55
    }
56
57
    /**
58
     * Creates a GeoCacheLog in the database.
59
     *
60
     * @param GeoCacheLogEntity $entity
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
61
     *
62
     * @return GeoCacheLogEntity
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
63
     */
64
    public function create(GeoCacheLogEntity $entity)
65
    {
66
        return $this->geoCacheRepository->create($entity);
67
    }
68
69
    /**
70
     * Update a GeoCacheLog in the database.
71
     *
72
     * @param GeoCacheLogEntity $entity
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
73
     *
74
     * @return GeoCacheLogEntity
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
75
     */
76
    public function update(GeoCacheLogEntity $entity)
77
    {
78
        return $this->geoCacheRepository->update($entity);
79
    }
80
81
    /**
82
     * Removes a GeoCacheLog from the database.
83
     *
84
     * @param GeoCacheLogEntity $entity
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
85
     *
86
     * @return GeoCacheLogEntity
0 ignored issues
show
introduced by
GeoCacheLogEntity => \Array\GeoCacheLogEntity
Loading history...
87
     */
88
    public function remove(GeoCacheLogEntity $entity)
89
    {
90
        return $this->geoCacheRepository->remove($entity);
91
    }
92
}
93