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