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

ConfigurationProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 52
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConfigurationByType() 0 4 1
A getConfiguration() 0 16 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