Conditions | 2 |
Paths | 2 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 2.003 |
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( $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 | } |
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: