| Total Complexity | 8 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class CacheProxy extends Psr16Cache |
||
| 8 | { |
||
| 9 | protected static $data = []; |
||
| 10 | |||
| 11 | public function set($key, $value, $ttl = null): bool |
||
| 12 | { |
||
| 13 | self::$data[__FUNCTION__ . $key] = [ |
||
| 14 | "key" => $key, |
||
| 15 | "type" => __FUNCTION__, |
||
| 16 | "value" => $value, |
||
| 17 | "ttl" => $ttl, |
||
| 18 | "caller" => $this->getCaller(), |
||
| 19 | ]; |
||
| 20 | return parent::set($key, $value, $ttl); |
||
| 21 | } |
||
| 22 | |||
| 23 | public function get($key, $default = null): mixed |
||
| 24 | { |
||
| 25 | $value = parent::get($key, $default); |
||
| 26 | self::$data[__FUNCTION__ . $key] = [ |
||
| 27 | "key" => $key, |
||
| 28 | "type" => __FUNCTION__, |
||
| 29 | "value" => $value, |
||
| 30 | "caller" => $this->getCaller(), |
||
| 31 | ]; |
||
| 32 | return $value; |
||
| 33 | } |
||
| 34 | |||
| 35 | private function getCaller(): string |
||
| 36 | { |
||
| 37 | $trace = debug_backtrace(); |
||
| 38 | $caller = ""; |
||
| 39 | $ignore = ["set", "get", "setCacheValue", "getCacheValue", "getCaller"]; |
||
| 40 | foreach ($trace as $t) { |
||
| 41 | if (in_array($t['function'], $ignore)) { |
||
| 42 | continue; |
||
| 43 | } |
||
| 44 | if (isset($t['file'])) { |
||
| 45 | $caller = basename($t['file']) . ':' . $t['line']; |
||
| 46 | } elseif (isset($t['class'])) { |
||
| 47 | $caller = $t['class']; |
||
| 48 | } |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | return $caller; |
||
| 52 | } |
||
| 53 | |||
| 54 | public static function getData(): array |
||
| 57 | } |
||
| 58 | } |
||
| 59 |