CachingBarangaysRepository::getByCity()   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 1
1
<?php
2
3
namespace Yajra\Address\Repositories\Barangays;
4
5
use Illuminate\Contracts\Cache\Repository as Cache;
6
7
class CachingBarangaysRepository extends BarangaysRepositoryEloquent implements BarangaysRepository
8
{
9
    /**
10
     * @var \App\Repositories\Utilities\BarangaysRepository
11
     */
12
    protected $repository;
13
14
    /**
15
     * @var \Illuminate\Contracts\Cache\Repository
16
     */
17
    protected $cache;
18
19
    /**
20
     * CachingBarangaysRepository constructor.
21
     *
22
     * @param BarangaysRepository $repository
23
     * @param Cache               $cache
24
     */
25
    public function __construct(BarangaysRepository $repository, Cache $cache)
26
    {
27
        $this->repository = $repository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $repository of type object<Yajra\Address\Rep...ys\BarangaysRepository> is incompatible with the declared type object<App\Repositories\...es\BarangaysRepository> of property $repository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
        $this->cache      = $cache;
29
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Get barangays by region, province and city ID.
35
     *
36
     * @param int $regionId
37
     * @param int $provinceId
38
     * @param int $cityId
39
     * @return \Illuminate\Database\Eloquent\Collection
40
     */
41
    public function getByProvinceRegionAndCityId($regionId, $provinceId, $cityId)
42
    {
43
        $key = "barangays.{$regionId}.{$provinceId}.{$cityId}";
44
45
        return $this->cache->rememberForever($key, function () use ($provinceId, $regionId, $cityId) {
46
            return $this->repository->getByProvinceRegionAndCityId($regionId, $provinceId, $cityId);
47
        });
48
    }
49
50
    /**
51
     * Get barangays by region, province and city ID.
52
     *
53
     * @param int $cityId
54
     * @return \Illuminate\Database\Eloquent\Collection
55
     */
56
    public function getByCity($cityId)
57
    {
58
        return $this->cache->rememberForever("barangays.{$cityId}", function () use ($cityId) {
59
            return $this->repository->getByCity($cityId);
60
        });
61
    }
62
}
63