CapSniffer::getFileName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Cp;
4
5
use Cocur\Slugify\Slugify;
6
use Cp\Calendar\Builder\CalendarBuilder;
7
use Cp\Provider\ConfigurationProvider;
8
use Cp\Provider\PlanProvider;
9
use Cp\Provider\TypeProvider;
10
11
/**
12
 * Class CapSniffer
13
 */
14
class CapSniffer
15
{
16
    /**
17
     * @var TypeProvider
18
     */
19
    private $typeProvider;
20
21
    /**
22
     * @var PlanProvider
23
     */
24
    private $planProvider;
25
26
    /**
27
     * @var Slugify
28
     */
29
    private $slug;
30
31
    /**
32
     * @var CalendarBuilder
33
     */
34
    private $calendarBuilder;
35
36
    /**
37
     * @var ConfigurationProvider
38
     */
39
    private $configProvider;
40
41
    /**
42
     * CapSniffer constructor.
43
     *
44
     * @param CalendarBuilder       $calendarBuilder
45
     * @param TypeProvider          $typeProvider
46
     * @param PlanProvider          $planProvider
47
     * @param ConfigurationProvider $configProvider
48
     * @param Slugify               $slug
49
     *
50
     * @internal param ConfigurationProvider $configurationManager
51
     */
52 3
    public function __construct(
53
        CalendarBuilder $calendarBuilder,
54
        TypeProvider $typeProvider,
55
        PlanProvider $planProvider,
56
        ConfigurationProvider $configProvider,
57
        Slugify $slug
58
    ) {
59 3
        $this->calendarBuilder = $calendarBuilder;
60 3
        $this->typeProvider = $typeProvider;
61 3
        $this->planProvider = $planProvider;
62 3
        $this->configProvider = $configProvider;
63 3
        $this->slug = $slug;
64 3
    }
65
66
    /**
67
     * @param string $type
68
     * @param string $week
69
     * @param string $seance
70
     *
71
     * @return string
72
     */
73 2
    public function generateCalendar($type, $week, $seance)
74
    {
75 2
        return $this->calendarBuilder->exportCalendar($this->getPlan($type, $week, $seance));
76
    }
77
78
    /**
79
     * @param string $type
80
     * @param string $week
81
     * @param string $seance
82
     */
83 1
    public function writeCalendar($type, $week, $seance)
84
    {
85 1
        file_put_contents(
86 1
            __DIR__.'/../../'.$this->getFileName($type, $week, $seance),
87 1
            $this->generateCalendar($type, $week, $seance)
88 1
        );
89 1
    }
90
91
    /**
92
     * @param string $type
93
     * @param string $week
94
     * @param string $seance
95
     *
96
     * @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...
97
     */
98 3
    public function getPlan($type, $week, $seance)
99
    {
100 3
        $configuration = $this->configProvider->getConfiguration($type, $week, $seance);
101 3
        $plan = $this->planProvider->getPlanByConfiguration($configuration);
102 3
        $plan->setConfiguration($configuration);
103
104 3
        return $plan;
105
    }
106
107
    /**
108
     * @param string $type
109
     * @param string $week
110
     * @param string $seance
111
     *
112
     * @return string
113
     */
114 2
    public function getFileName($type, $week, $seance)
115
    {
116 2
        return $this->slug->slugify($this->getPlan($type, $week, $seance)->getName()).'.ics';
117
    }
118
}
119