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 ( 7333fd...540f8b )
by Carsten
04:11
created

IpstackClientPsr6CacheDecorator::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 9
cts 10
cp 0.9
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.004
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( sha1($client_ip) );
38
39 4
        $ipstack = $item->get();
40
41
        // No valid item?
42 4
        if(!$item->isHit()):
43 4
            $this->logger->debug("No ipstack info in cache");
44
45
            // Run intensive code: Ask ipstack directly
46 4
            $ipstack = $this->ipstack_client->get( $client_ip, $custom_query );
47
48
            // Store data for future use.
49 4
            $this->logger->info("Write ipstack info to cache", $ipstack);
50 4
            $this->cache->save($item->set($ipstack));
51
52
        // Valid item found
53
        else:
54
            $this->logger->notice("Found ipstack info in cache", $ipstack);
55
        endif;
56
57 4
        return $ipstack;
58
59
	}	
60
61
}