Passed
Push — master ( ab35ba...c83602 )
by Nicolas
02:05
created

ConfigurationManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 88
ccs 12
cts 14
cp 0.8571
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A createConfiguration() 0 11 1
B findConfigurationsByType() 0 27 1
1
<?php
2
3
namespace Cp\Manager;
4
5
use Cp\DomainObject\Configuration;
6
use Cp\Parser\ConfigurationParser;
7
use Cp\Provider\TypeProvider;
8
use Doctrine\Common\Cache\MemcachedCache;
9
10
/**
11
 * Class ConfigurationManager
12
 */
13
class ConfigurationManager
14
{
15
    const CACHE_KEY = 'configuration.list';
16
17
    /**
18
     * @var TypeProvider
19
     */
20
    private $typeProvider;
21
22
    /**
23
     * @var ConfigurationParser
24
     */
25
    protected $configurationParser;
26
27
    /**
28
     * @var MemcachedCache
29
     */
30
    protected $memcache;
31
32
    /**
33
     * ConfigurationManager constructor.
34
     *
35
     * @param TypeProvider        $typeProvider
36
     * @param ConfigurationParser $configurationParser
37
     * @param MemcachedCache      $memcachedCache
38
     */
39 1
    public function __construct(
40
        TypeProvider $typeProvider,
41
        ConfigurationParser $configurationParser,
42
        MemcachedCache $memcachedCache
43
    ) {
44 1
        $this->typeProvider = $typeProvider;
45 1
        $this->configurationParser = $configurationParser;
46 1
        $this->memcache = $memcachedCache;
47 1
    }
48
49
    /**
50
     * @param string $typeName
51
     * @param int    $week
52
     * @param int    $seance
53
     *
54
     * @return Configuration
55
     */
56 1
    public function createConfiguration($typeName, $week, $seance)
57
    {
58 1
        $type = $this->typeProvider->getTypeByName($typeName);
59
60 1
        $configuration = new Configuration();
61 1
        $configuration->setType($type);
62 1
        $configuration->setNumberOfWeek($week);
63 1
        $configuration->setNumberOfSeance($seance);
64
65 1
        return $configuration;
66
    }
67
68
    /**
69
     * @param string $typeName
70
     *
71
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
72
     */
73
    public function findConfigurationsByType($typeName)
0 ignored issues
show
Unused Code introduced by
The parameter $typeName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
        $configurationForType = $this->memcache->fetch(self::CACHE_KEY.$typeName);
77
78
        if (false === $configurationForType) {
79
            $configurationForType = json_decode(
80
                $this
81
                    ->configurationParser
82
                    ->parseToJson('/Users/perso/Workspace/cap-sniffer-api/web/mock/plan-10-home.html')
83
                , true);
84
            $this->memcache->save(self::CACHE_KEY.$typeName, $configurationForType, 3600);
85
        }
86
87
        $configurationList = [];
88
        foreach ($configurationForType as $conf) {
89
            $configuration = new Configuration();
90
            $configuration->setType($typeName);
91
            $configuration->setNumberOfSeance($conf['seance']);
92
            $configuration->setNumberOfWeek($conf['week']);
93
94
            $configurationList[] = $configuration;
95
        }
96
97
        return $configurationList;
98
        */
99
    }
100
}
101