Total Complexity | 9 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 91.67% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 | |||
28 | 18 | public function __construct( |
|
29 | Server $server, |
||
30 | TimeContinuumInterface $clock, |
||
31 | ElapsedPeriod $threshold |
||
32 | ) { |
||
33 | 18 | $this->server = $server; |
|
34 | 18 | $this->clock = $clock; |
|
35 | 18 | $this->threshold = $threshold; |
|
36 | 18 | } |
|
37 | |||
38 | 3 | public function cpu(): Cpu |
|
39 | { |
||
40 | 3 | return $this->server->cpu(); |
|
41 | } |
||
42 | |||
43 | 3 | public function memory(): Memory |
|
44 | { |
||
45 | 3 | return $this->server->memory(); |
|
46 | } |
||
47 | |||
48 | 3 | public function processes(): Processes |
|
49 | { |
||
50 | 3 | return $this->server->processes(); |
|
51 | } |
||
52 | |||
53 | 3 | public function loadAverage(): LoadAverage |
|
54 | { |
||
55 | 3 | $now = $this->clock->now(); |
|
56 | |||
57 | if ( |
||
58 | 3 | $this->cachedAt && |
|
59 | 3 | $this->threshold->longerThan( |
|
60 | 3 | $now->elapsedSince($this->cachedAt) |
|
61 | ) |
||
62 | ) { |
||
63 | 3 | return $this->data; |
|
64 | } |
||
65 | |||
66 | 3 | $this->data = $this->server->loadAverage(); |
|
67 | 3 | $this->cachedAt = $now; |
|
68 | |||
69 | 3 | return $this->data; |
|
70 | } |
||
71 | |||
72 | 3 | public function disk(): Disk |
|
73 | { |
||
74 | 3 | return $this->server->disk(); |
|
75 | } |
||
76 | |||
77 | public function tmp(): PathInterface |
||
80 | } |
||
81 | } |
||
82 |