Passed
Pull Request — development (#682)
by Nick
08:06
created

GeoCacheLogService   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

6 Methods

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