Passed
Push — master ( 3f26c1...e5a362 )
by Nicolas
04:09 queued 01:57
created

PlanManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 75
ccs 24
cts 24
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B findByType() 0 24 3
1
<?php
2
3
namespace Cp\Manager;
4
5
use Cp\DomainObject\Plan;
6
use Cp\Exception\ConfigurationException;
7
use Cp\Parser\PlanParser;
8
use Cp\Transformer\UrlTransformer;
9
use Doctrine\Common\Cache\MemcachedCache;
10
use JMS\Serializer\Serializer;
11
12
/**
13
 * Class PlanManager
14
 */
15
class PlanManager
16
{
17
    /**
18
     * @var PlanParser
19
     */
20
    private $planParser;
21
22
    /**
23
     * @var UrlTransformer
24
     */
25
    private $urlTransformer;
26
27
    /**
28
     * @var Serializer
29
     */
30
    private $serializer;
31
32
    /**
33
     * @var MemcachedCache
34
     */
35
    private $memcache;
36
37
    /**
38
     * TrainingManager constructor.
39
     *
40
     * @param PlanParser     $planParser
41
     * @param UrlTransformer $urlTransformer
42
     * @param Serializer     $serializer
43
     * @param MemcachedCache $memcached
44
     */
45 2
    public function __construct(
46
        PlanParser $planParser,
47
        UrlTransformer $urlTransformer,
48
        Serializer $serializer,
49
        MemcachedCache $memcached
50
    ) {
51 2
        $this->planParser = $planParser;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52 2
        $this->urlTransformer = $urlTransformer;
53 2
        $this->serializer = $serializer;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
54 2
        $this->memcache = $memcached;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
55 2
    }
56
57
    /**
58
     * @param int    $week
59
     * @param int    $seance
60
     * @param string $type
61
     *
62
     * @return Plan
63
     * @throws ConfigurationException
64
     */
65 2
    public function findByType($week, $seance, $type)
66
    {
67 2
        $plan = $this->memcache->fetch($week.$seance.$type);
68 2
        if (false === $plan) {
69
            try {
70 2
                $jsonString = $this->planParser->parseToJson(
71 2
                    $this->urlTransformer->transformPlan($week, $seance, $type)
72 2
                );
73 2
            } catch (\Exception $e) {
74 1
                throw new ConfigurationException(
75 1
                    sprintf(
76 1
                        'Configuration with week: %s, seance: %s and type:%s is not available',
77 1
                        $week,
78 1
                        $seance,
79
                        $type
80 1
                    )
81 1
                );
82
            }
83 1
            $plan = $this->serializer->deserialize($jsonString, Plan::class, 'json');
84 1
            $this->memcache->save($week.$seance.$type, $plan, 3600);
85 1
        }
86
87 1
        return $plan;
88
    }
89
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
90