Passed
Branch master (a96d1e)
by Nicolas
02:44
created

CapSniffer::createConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 2
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 2
    public function __construct(
52
        TypeProvider $typeProvider,
53
        PlanProvider $planProvider,
54
        CalendarBuilder $calendarBuilder,
55
        Slugify $slug,
56
        ConfigurationManager $configurationManager
57
    ) {
58 2
        $this->typeProvider = $typeProvider;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
59 2
        $this->planProvider = $planProvider;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
60 2
        $this->calendarBuilder = $calendarBuilder;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
61 2
        $this->slug = $slug;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 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...
62 2
        $this->configurationManager = $configurationManager;
63 2
    }
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
        $plan = $this->getPlan($typeName, $week, $seance);
85 1
        file_put_contents(
86 1
            __DIR__.'/../../'.$this->slug->slugify($plan->getName()).'.ics',
87 1
            $this->generateCalendar($typeName, $week, $seance)
88 1
        );
89 1
    }
90
91
    /**
92
     * @param string $typeName
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 2
    public function getPlan($typeName, $week, $seance)
99
    {
100 2
        $configuration = $this->configurationManager->createConfiguration($typeName, $week, $seance);
101 2
        $plan = $this->planProvider->getPlanByConfiguration($configuration);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
102 2
        $plan->setConfiguration($configuration);
103
104 2
        return $plan;
105
    }
106
}
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...
107