Conditions | 2 |
Paths | 2 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 2.004 |
Changes | 0 |
1 | <?php |
||
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 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: