GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b0e03a...4af0c2 )
by Tobias
02:50
created

CachePlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handleQuery() 0 12 2
A getCacheKey() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Plugin\Plugin;
14
15
use Geocoder\Plugin\Plugin;
16
use Geocoder\Query\Query;
17
use Psr\SimpleCache\CacheInterface;
18
19
/**
20
 * Cache the result of a query.
21
 *
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
class CachePlugin implements Plugin
25
{
26
    /**
27
     * @var CacheInterface
28
     */
29
    private $cache;
30
31
    /**
32
     * How log a result is going to be cached.
33
     *
34
     * @var int|null
35
     */
36
    private $lifetime;
37
38
    /**
39
     * @param CacheInterface $cache
40
     * @param int            $lifetime
0 ignored issues
show
Documentation introduced by
Should the type for parameter $lifetime not be null|integer?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
41
     */
42
    public function __construct(CacheInterface $cache, int $lifetime = null)
43
    {
44
        $this->cache = $cache;
45
        $this->lifetime = $lifetime;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function handleQuery(Query $query, callable $next, callable $first)
52
    {
53
        $cacheKey = $this->getCacheKey($query);
54
        if (null !== $cachedResult = $this->cache->get($cacheKey)) {
55
            return $cachedResult;
56
        }
57
58
        $result = $next($query);
59
        $this->cache->set($cacheKey, $result, $this->lifetime);
60
61
        return $result;
62
    }
63
64
    /**
65
     * @param Query $query
66
     *
67
     * @return string
68
     */
69
    private function getCacheKey(Query $query): string
70
    {
71
        // Include the major version number of the geocoder to avoid issues unserializing.
72
        return 'v4'.sha1((string) $query);
73
    }
74
}
75