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

FileLoaderRegistry::getLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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