Test Failed
Pull Request — master (#14)
by Marek
02:09
created

CalendarController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CalendarBundle\Controller;
6
7
use CalendarBundle\CalendarEvents;
8
use CalendarBundle\Event\CalendarEvent;
9
use CalendarBundle\Serializer\SerializerInterface;
10
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
15
class CalendarController extends AbstractController
16
{
17
    /**
18
     * @var SerializerInterface
19
     */
20
    protected $serializer;
21
22
    /**
23
     * @var EventDispatcherInterface
24
     */
25
    protected $eventDispatcher;
26
27
    public function __construct(
28
        EventDispatcherInterface $eventDispatcher,
29
        SerializerInterface $serializer
30
    ) {
31
        $this->eventDispatcher = $eventDispatcher;
32
        $this->serializer = $serializer;
33
    }
34
35
    public function loadAction(Request $request): Response
36
    {
37
        $start = new \DateTime($request->get('start'));
38
        $end = new \DateTime($request->get('end'));
39
        $filters = $request->get('filters', '{}');
40
        $filters = \is_array($filters) ? $filters : json_decode($filters, true);
41
        $timezone = $request->get('timeZone');
42
43
        $event = $this->eventDispatcher->dispatch(
44
            CalendarEvents::SET_DATA,
0 ignored issues
show
Bug introduced by
CalendarBundle\CalendarEvents::SET_DATA of type string is incompatible with the type object expected by parameter $event of Symfony\Contracts\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            /** @scrutinizer ignore-type */ CalendarEvents::SET_DATA,
Loading history...
45
            new CalendarEvent($start, $end, $filters, $timezone)
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with new CalendarBundle\Event...d, $filters, $timezone). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        /** @scrutinizer ignore-call */ 
46
        $event = $this->eventDispatcher->dispatch(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
46
        );
47
        $content = $this->serializer->serialize($event->getEvents());
48
49
        $response = new Response();
50
        $response->headers->set('Content-Type', 'application/json');
51
        $response->setContent($content);
52
        $response->setStatusCode(empty($content) ? Response::HTTP_NO_CONTENT : Response::HTTP_OK);
53
54
        return $response;
55
    }
56
}
57