| Total Complexity | 9 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | final class CacheMemory implements Server |
||
| 21 | { |
||
| 22 | private $server; |
||
| 23 | private $clock; |
||
| 24 | private $threshold; |
||
| 25 | private $cachedAt; |
||
| 26 | private $data; |
||
| 27 | |||
| 28 | public function __construct( |
||
| 29 | Server $server, |
||
| 30 | TimeContinuumInterface $clock, |
||
| 31 | ElapsedPeriod $threshold |
||
| 32 | ) { |
||
| 33 | $this->server = $server; |
||
| 34 | $this->clock = $clock; |
||
| 35 | $this->threshold = $threshold; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function cpu(): Cpu |
||
| 41 | } |
||
| 42 | |||
| 43 | public function memory(): Memory |
||
| 44 | { |
||
| 45 | $now = $this->clock->now(); |
||
| 46 | |||
| 47 | if ( |
||
| 48 | $this->cachedAt && |
||
| 49 | $this->threshold->longerThan( |
||
| 50 | $now->elapsedSince($this->cachedAt) |
||
| 51 | ) |
||
| 52 | ) { |
||
| 53 | return $this->data; |
||
| 54 | } |
||
| 55 | |||
| 56 | $this->data = $this->server->memory(); |
||
| 57 | $this->cachedAt = $now; |
||
| 58 | |||
| 59 | return $this->data; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function processes(): Processes |
||
| 63 | { |
||
| 64 | return $this->server->processes(); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function loadAverage(): LoadAverage |
||
| 68 | { |
||
| 69 | return $this->server->loadAverage(); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function disk(): Disk |
||
| 73 | { |
||
| 74 | return $this->server->disk(); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function tmp(): PathInterface |
||
| 80 | } |
||
| 81 | } |
||
| 82 |