LoggerPool   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 43
ccs 16
cts 17
cp 0.9412
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntriesFromAllLoggerInstances() 0 9 2
A hasEntriesInAnyLoggerInstance() 0 9 3
A getLogger() 0 7 2
A createNewLogger() 0 5 1
1
<?php
2
3
namespace sweetrdf\InMemoryStoreSqlite\Log;
4
5
use Exception;
6
7
class LoggerPool
8
{
9
    /**
10
     * @var array<int,\sweetrdf\InMemoryStoreSqlite\Log\Logger>
11
     */
12
    private array $logger = [];
13
14 106
    public function createNewLogger(string $id): Logger
15
    {
16 106
        $this->logger[$id] = new Logger();
17
18 106
        return $this->logger[$id];
19
    }
20
21 2
    public function getLogger(string $id): Logger
22
    {
23 2
        if (isset($this->logger[$id])) {
24 1
            return $this->logger[$id];
25
        }
26
27 1
        throw new Exception('Invalid ID given.');
28
    }
29
30 3
    public function getEntriesFromAllLoggerInstances(?string $level = null): iterable
31
    {
32 3
        $result = [];
33
34 3
        foreach ($this->logger as $logger) {
35 3
            $result = array_merge($result, $logger->getEntries($level));
36
        }
37
38 2
        return $result;
39
    }
40
41 2
    public function hasEntriesInAnyLoggerInstance(?string $level = null): bool
42
    {
43 2
        foreach ($this->logger as $logger) {
44 2
            if ($logger->hasEntries($level)) {
45 1
                return true;
46
            }
47
        }
48
49
        return false;
50
    }
51
}
52