CachingProvincesRepository::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Yajra\Address\Repositories\Provinces;
4
5
use Illuminate\Contracts\Cache\Repository as Cache;
6
7
class CachingProvincesRepository extends ProvincesRepositoryEloquent implements ProvincesRepository
8
{
9
    /**
10
     * @var ProvincesRepository
11
     */
12
    protected $repository;
13
14
    /**
15
     * @var Cache
16
     */
17
    protected $cache;
18
19
    /**
20
     * CachingProvincesRepository constructor.
21
     *
22
     * @param ProvincesRepository $repository
23
     * @param Cache               $cache
24
     */
25
    public function __construct(ProvincesRepository $repository, Cache $cache)
26
    {
27
        $this->repository = $repository;
28
        $this->cache      = $cache;
29
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Get province by region ID.
35
     *
36
     * @param int $regionId
37
     * @return \Illuminate\Database\Eloquent\Collection
38
     */
39
    public function getProvinceByRegion($regionId)
40
    {
41
        return $this->cache->rememberForever("provinces.{$regionId}", function () use ($regionId) {
42
            return $this->repository->getProvinceByRegion($regionId);
43
        });
44
    }
45
46
    /**
47
     * Get all provinces.
48
     *
49
     * @return \Illuminate\Database\Eloquent\Collection
50
     */
51
    public function all()
52
    {
53
        return $this->cache->rememberForever("provinces", function () {
54
            return $this->repository->all();
55
        });
56
    }
57
}
58