CachingCitiesRepository   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 72
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getByProvinceAndRegion() 0 8 1
A getByProvince() 0 8 1
A getByRegion() 0 8 1
1
<?php
2
3
namespace Yajra\Address\Repositories\Cities;
4
5
use Illuminate\Contracts\Cache\Repository as Cache;
6
7
class CachingCitiesRepository extends CitiesRepositoryEloquent implements CitiesRepository
8
{
9
    /**
10
     * @var CitiesRepository
11
     */
12
    protected $repository;
13
14
    /**
15
     * @var \Illuminate\Contracts\Cache\Repository
16
     */
17
    protected $cache;
18
19
    /**
20
     * CachingCitiesRepository constructor.
21
     *
22
     * @param CitiesRepository $repository
23
     * @param Cache            $cache
24
     */
25
    public function __construct(CitiesRepository $repository, Cache $cache)
26
    {
27
        $this->repository = $repository;
28
        $this->cache      = $cache;
29
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Get cities by region ID and province ID.
35
     *
36
     * @param int $regionId
37
     * @param int $provinceId
38
     * @return \Illuminate\Database\Eloquent\Collection
39
     */
40
    public function getByProvinceAndRegion($regionId, $provinceId)
41
    {
42
        $key = "cities.{$regionId}.{$provinceId}";
43
44
        return $this->cache->rememberForever($key, function () use ($regionId, $provinceId) {
45
            return $this->repository->getByProvinceAndRegion($regionId, $provinceId);
46
        });
47
    }
48
49
    /**
50
     * Get cities by province.
51
     *
52
     * @param int $provinceId
53
     * @return \Illuminate\Database\Eloquent\Collection
54
     */
55
    public function getByProvince($provinceId)
56
    {
57
        $key = "cities.{$provinceId}";
58
59
        return $this->cache->rememberForever($key, function () use ($provinceId) {
60
            return $this->repository->getByProvince($provinceId);
61
        });
62
    }
63
64
    /**
65
     * Get cities by region.
66
     *
67
     * @param int $regionId
68
     * @return \Illuminate\Database\Eloquent\Collection
69
     */
70
    public function getByRegion($regionId)
71
    {
72
        $key = "cities.region.{$regionId}";
73
74
        return $this->cache->rememberForever($key, function () use ($regionId) {
75
            return $this->repository->getByRegion($regionId);
76
        });
77
    }
78
}
79