Calendar::getData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 12
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Toiba\FullCalendarBundle\Service;
4
5
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
6
use Toiba\FullCalendarBundle\Event\CalendarEvent;
7
8
class Calendar
9
{
10
    /**
11
     * @var SerializerInterface
12
     */
13
    protected $serializer;
14
15
    /**
16
     * @var EventDispatcherInterface
17
     */
18
    protected $dispatcher;
19
20
    /**
21
     * @param SerializerInterface      $serializer
22
     * @param EventDispatcherInterface $dispatcher
23
     */
24 2
    public function __construct(
25
        SerializerInterface $serializer,
26
        EventDispatcherInterface $dispatcher
27
    ) {
28 2
        $this->serializer = $serializer;
29 2
        $this->dispatcher = $dispatcher;
30 2
    }
31
32
    /**
33
     * @param \DateTimeInterface $startDate
34
     * @param \DateTimeInterface $endDate
35
     * @param array              $filters
36
     *
37
     * @return string json
38
     */
39 1
    public function getData(
40
        \DateTimeInterface $startDate,
41
        \DateTimeInterface $endDate,
42
        array $filters = []
43
    ): string {
44
        /** @var CalendarEvent $event */
45 1
        $event = $this->dispatcher->dispatch(
46 1
            CalendarEvent::SET_DATA,
47 1
            new CalendarEvent($startDate, $endDate, $filters)
48
        );
49
50 1
        return $this->serializer->serialize($event->getEvents());
51
    }
52
}
53