Completed
Push — master ( 359fe7...152344 )
by Sébastien
03:49
created

PresetLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 25
ccs 4
cts 8
cp 0.5
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPreset() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Preset;
6
7
use Psr\Container\ContainerInterface;
8
use Soluble\MediaTools\Cli\Exception\UnknownPresetException;
9
10
class PresetLoader
11
{
12
    /**
13
     * @var PresetLocator
14
     */
15
    private $locator;
16
17
    /**
18
     * @var ContainerInterface
19
     */
20
    private $container;
21
22 2
    public function __construct(PresetLocator $locator, ContainerInterface $container)
23
    {
24 2
        $this->locator   = $locator;
25 2
        $this->container = $container;
26 2
    }
27
28
    public function getPreset(string $presetName): PresetInterface
29
    {
30
        if (!$this->locator->isSupported($presetName)) {
31
            throw new UnknownPresetException(sprintf('Preset %s does not exists', $presetName));
32
        }
33
34
        return $this->container->get($presetName);
35
    }
36
}
37