Test Failed
Push — master ( fa8c20...ab35ba )
by Nicolas
02:05
created

CapSniffer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 109
ccs 22
cts 22
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A generateCalendar() 0 4 1
A writeCalendar() 0 7 1
A getPlan() 0 8 1
A getFileName() 0 4 1
A testConfigurationParse() 0 5 1
1
<?php
2
3
namespace Cp;
4
5
use Cocur\Slugify\Slugify;
6
use Cp\Calendar\Builder\CalendarBuilder;
7
use Cp\DomainObject\Configuration;
8
use Cp\Manager\ConfigurationManager;
9
use Cp\Provider\PlanProvider;
10
use Cp\Provider\TypeProvider;
11
12
/**
13
 * Class CapSniffer
14
 */
15
class CapSniffer
16
{
17
    /**
18
     * @var TypeProvider
19
     */
20
    private $typeProvider;
21
22
    /**
23
     * @var PlanProvider
24
     */
25
    private $planProvider;
26
27
    /**
28
     * @var Slugify
29
     */
30
    private $slug;
31
32
    /**
33
     * @var CalendarBuilder
34
     */
35
    private $calendarBuilder;
36
37
    /**
38
     * @var ConfigurationManager
39
     */
40
    private $configurationManager;
41
42
    /**
43
     * CapSniffer constructor.
44
     *
45
     * @param TypeProvider         $typeProvider
46
     * @param PlanProvider         $planProvider
47
     * @param CalendarBuilder      $calendarBuilder
48
     * @param Slugify              $slug
49
     * @param ConfigurationManager $configurationManager
50
     */
51 3
    public function __construct(
52
        TypeProvider $typeProvider,
53
        PlanProvider $planProvider,
54
        CalendarBuilder $calendarBuilder,
55
        Slugify $slug,
56
        ConfigurationManager $configurationManager
57
    ) {
58 3
        $this->typeProvider = $typeProvider;
59 3
        $this->planProvider = $planProvider;
60 3
        $this->calendarBuilder = $calendarBuilder;
61 3
        $this->slug = $slug;
62 3
        $this->configurationManager = $configurationManager;
63 3
    }
64
65
    /**
66
     * @param string $typeName
67
     * @param string $week
68
     * @param string $seance
69
     *
70
     * @return string
71
     */
72 2
    public function generateCalendar($typeName, $week, $seance)
73
    {
74 2
        return $this->calendarBuilder->exportCalendar($this->getPlan($typeName, $week, $seance));
75
    }
76
77
    /**
78
     * @param string $typeName
79
     * @param string $week
80
     * @param string $seance
81
     */
82 1
    public function writeCalendar($typeName, $week, $seance)
83
    {
84 1
        file_put_contents(
85 1
            __DIR__.'/../../'.$this->getFileName($typeName, $week, $seance),
86 1
            $this->generateCalendar($typeName, $week, $seance)
87 1
        );
88 1
    }
89
90
    /**
91
     * @param string $typeName
92
     * @param string $week
93
     * @param string $seance
94
     *
95
     * @return Plan
0 ignored issues
show
Documentation introduced by
Should the return type not be DomainObject\Plan?

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...
96
     */
97 3
    public function getPlan($typeName, $week, $seance)
98
    {
99 3
        $configuration = $this->configurationManager->createConfiguration($typeName, $week, $seance);
100 3
        $plan = $this->planProvider->getPlanByConfiguration($configuration);
101 3
        $plan->setConfiguration($configuration);
102
103 3
        return $plan;
104
    }
105
106
    /**
107
     * @param string $typeName
108
     * @param string $week
109
     * @param string $seance
110
     *
111
     * @return string
112
     */
113 2
    public function getFileName($typeName, $week, $seance)
114
    {
115 2
        return $this->slug->slugify($this->getPlan($typeName, $week, $seance)->getName()).'.ics';
116
    }
117
118
    public function testConfigurationParse()
119
    {
120
        $result = $this->configurationManager->findConfigurationsByType('plan-entrainement-10km');
121
        var_dump($result); die;
0 ignored issues
show
Security Debugging Code introduced by
var_dump($result); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
Coding Style Compatibility introduced by
The method testConfigurationParse() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
122
    }
123
}
124