Passed
Pull Request — master (#1218)
by butschster
11:03
created

FileLoaderRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 3
A __construct() 0 4 1
A getLoader() 0 3 1
A getExtensions() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Config\Loader;
6
7
use Spiral\Core\Attribute\Singleton;
8
9
/**
10
 * @internal
11
 */
12
#[Singleton]
13
final class FileLoaderRegistry
14
{
15 575
    public function __construct(
16
        /**@var array<non-empty-string, FileLoaderInterface> */
17
        private array $loaders = [],
18 575
    ) {}
19
20
    /**
21
     * @param non-empty-string $ext
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
22
     */
23 29
    public function register(string $ext, FileLoaderInterface $loader): void
24
    {
25 29
        if (!isset($this->loaders[$ext]) || $this->loaders[$ext]::class !== $loader::class) {
26 29
            $this->loaders[$ext] = $loader;
27
        }
28
    }
29
30 517
    public function getExtensions(): array
31
    {
32 517
        return \array_keys($this->loaders);
33
    }
34
35 470
    public function getLoader(string $ext): FileLoaderInterface
36
    {
37 470
        return $this->loaders[$ext];
38
    }
39
}