| Total Complexity | 14 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class Memory |
||
| 8 | { |
||
| 9 | private const MEMORY_SIZE = 12; // one hour if every 5 minutes taken |
||
| 10 | |||
| 11 | private static ?Memory $instance = null; |
||
| 12 | |||
| 13 | private array $data = []; |
||
| 14 | |||
| 15 | static public function getInstance(): Memory |
||
| 22 | } |
||
| 23 | |||
| 24 | private function __construct() |
||
| 26 | } |
||
| 27 | |||
| 28 | public function addData(string $key, float $value): void |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getData(string $key): float |
||
| 42 | { |
||
| 43 | return $this->data[$key] ?? -1; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function addDataSet(array $dataset): void |
||
| 47 | { |
||
| 48 | foreach ($dataset as $key => $value) { |
||
| 49 | $this->addData($key, $value); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getNumberOfGreaterThan(string $key, int $threshold): int |
||
| 54 | { |
||
| 55 | if (!array_key_exists($key, $this->data)) return 0; |
||
| 56 | |||
| 57 | $count = 0; |
||
| 58 | |||
| 59 | foreach ($this->data[$key] as $value) { |
||
| 60 | if ($value >= $threshold) $count++; |
||
| 61 | } |
||
| 62 | |||
| 63 | return $count; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function getDataSet(): array |
||
| 69 | } |
||
| 70 | } |