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