Passed
Push — master ( 3fad3a...a50da5 )
by Nicolas
02:48
created

ConfigurationProvider::getConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Cp\Provider;
4
5
use Cp\DomainObject\Configuration;
6
use Cp\Exception\ConfigurationNotFoundException;
7
use Cp\Manager\ConfigurationManager;
8
9
/**
10
 * Class Type
11
 */
12
class ConfigurationProvider
13
{
14
    /**
15
     * @var ConfigurationManager
16
     */
17
    protected $configurationManager;
18
19
    /**
20
     * ConfigurationProvider constructor.
21
     *
22
     * @param ConfigurationManager $configurationManager
23
     */
24 3
    public function __construct(ConfigurationManager $configurationManager)
25
    {
26 3
        $this->configurationManager = $configurationManager;
27 3
    }
28
29
    /**
30
     * @param string $typeName
31
     *
32
     * @return array
33
     */
34 1
    public function getConfigurationByType($typeName)
35
    {
36 1
        return $this->configurationManager->findConfigurationsByType($typeName);
37
    }
38
39
    /**
40
     * @param string $typeName
41
     * @param string $week
42
     * @param string $seance
43
     *
44
     * @return Configuration
45
     * @throws ConfigurationNotFoundException
46
     */
47 2
    public function getConfiguration($typeName, $week, $seance)
48
    {
49 2
        $configuration = $this->configurationManager->findConfiguration($typeName, $week, $seance);
50 2
        if (null === $configuration) {
51 1
            throw new ConfigurationNotFoundException(
52 1
                sprintf(
53 1
                    'Configuration with week: %s, seance: %s and type:%s is not available',
54 1
                    $week,
55 1
                    $seance,
56
                    $typeName
57 1
                )
58 1
            );
59
        }
60
61 1
        return $configuration;
62
    }
63
}
64