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.
Passed
Push — master ( f67280...55edf1 )
by Carsten
04:22 queued 11s
created

IpstackClientPsr6CacheDecorator::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 10
cts 11
cp 0.9091
rs 9.456
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.003
1
<?php
2
namespace Germania\IpstackClient;
3
4
use Germania\IpstackClient\IpstackClientInterface;
5
use Psr\Cache\CacheItemPoolInterface;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
use Psr\Log\LoggerAwareTrait;
9
10
class IpstackClientPsr6CacheDecorator implements IpstackClientInterface
11
{
12
	use LoggerAwareTrait;
13
14
15
	/**
16
	 * @var CacheItemPoolInterface
17
	 */
18
	public $cache;
19
20
21
	/**
22
	 * @param IpstackClientInterface $ipstack_client
23
	 * @param CacheItemPoolInterface $cache           PSR-6 Cache ItemPool
24
	 */
25 4
	public function __construct( IpstackClientInterface $ipstack_client, CacheItemPoolInterface $cache, LoggerInterface $logger = null )
26
	{
27 4
		$this->ipstack_client = $ipstack_client;
0 ignored issues
show
Bug introduced by
The property ipstack_client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28 4
		$this->cache = $cache;
29 4
		$this->setLogger( $logger ?: new NullLogger );
30 4
	}
31
32
33
34 4
	public function get( string $client_ip, array $custom_query = array() ) : array
35
    {
36
37 4
        $item = $this->cache->getItem( $client_ip );
38
39 4
        $ipstack = $item->get();
40
41
        // No valid item?
42 4
        if($item->isMiss()):
43 4
            $this->logger->debug("No ipstack info in cache");
44
45
            // Let other processes know that this one is rebuilding the data.
46 4
            $item->lock();
47
48
            // Run intensive code: Ask ipstack directly
49 4
            $ipstack = $this->ipstack_client->get( $client_ip, $custom_query );
50
51
            // Store data for future use.
52 4
            $this->logger->info("Write ipstack info to cache", $ipstack);
53 4
            $this->cache->save($item->set($ipstack));
54
55
        // Valid cache item found
56
        else:
57
            $this->logger->notice("Found ipstack info in cache", $ipstack);
58
        endif;
59
60 4
        return $ipstack;
61
62
	}	
63
64
}