LoggerPool::createNewLogger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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