I18nStringsBatchManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveBatch() 0 7 2
A __call() 0 8 2
A setDefaultDirectoryPrefix() 0 3 1
A batch() 0 3 1
1
<?php
2
3
namespace I18nStringsBatch;
4
5
class I18nStringsBatchManager
6
{
7
    public static string $defaultDirectory = '';
8
9
    protected array $instances = [];
10
11 2
    public static function setDefaultDirectoryPrefix(string $defaultDirectory)
12
    {
13 2
        static::$defaultDirectory = $defaultDirectory;
14
    }
15
16 6
    public function batch(?string $directory = null): I18nStringsBatch
17
    {
18 6
        return $this->resolveBatch($directory ?? static::$defaultDirectory);
19
    }
20
21 6
    protected function resolveBatch(string $directory): I18nStringsBatch
22
    {
23 6
        if (isset($this->instances[$directory])) {
24 2
            return $this->instances[$directory];
25
        }
26
27 6
        return $this->instances[$directory] = new I18nStringsBatch($directory);
28
    }
29
30 6
    public function __call(string $method, array $arguments)
31
    {
32 6
        $batch = $this->batch();
33 6
        if (method_exists($batch, $method)) {
34 5
            return $batch->{$method}(...$arguments);
35
        }
36
37 1
        throw new \BadMethodCallException("Method [{$method}] not exists");
38
    }
39
}
40