GeocodeCache   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 5 1
1
<?php
2
3
4
namespace talismanfr\geocode\decorators;
5
6
7
use talismanfr\geocode\contracts\Geocode;
8
use yii\caching\CacheInterface;
9
10
class GeocodeCache implements Geocode
11
{
12
    /** @var Geocode  */
13
    private $geocode;
14
15
    /** @var \yii\caching\CacheInterface */
16
    private $cache;
17
18
    public $duration=null;
19
20
    public $dependency=null;
21
22
    public function __construct(Geocode $geocode,CacheInterface $cache)
23
    {
24
        $this->geocode=$geocode;
25
        $this->cache=$cache;
26
    }
27
28
    public function get($query, $params = [])
29
    {
30
        return $this->cache->getOrSet($query,function ()use($query){
31
            return $this->geocode->get($query);
32
        },$this->duration,$this->dependency);
33
    }
34
}