BrowseEventController::trackAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 3
1
<?php
2
3
namespace Victoire\Bundle\AnalyticsBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
use Victoire\Bundle\AnalyticsBundle\Entity\BrowseEvent;
10
use Victoire\Bundle\UserBundle\Entity\User;
11
12
/**
13
 * @Route("/browseEvent")
14
 */
15
class BrowseEventController extends Controller
16
{
17
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$viewReferenceId" missing
Loading history...
introduced by
Doc comment for parameter "$referer" missing
Loading history...
18
     * @Route("/track/{viewReferenceId}/{referer}", name="victoire_analytics_track")
19
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
20
    public function trackAction(Request $request, $viewReferenceId, $referer = null)
21
    {
22
        $browseEvent = new BrowseEvent();
23
        $browseEvent->setViewReferenceId($viewReferenceId);
24
        $browseEvent->setIp($request->getClientIp());
25
        $browseEvent->setReferer($referer);
26
        if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
27
            $browseEvent->setAuthor($this->getUser());
0 ignored issues
show
Documentation introduced by
$this->getUser() is of type null|object, but the function expects a object<Victoire\Bundle\UserBundle\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
        }
29
        $entityManager = $this->get('doctrine.orm.entity_manager');
30
        $entityManager->persist($browseEvent);
31
        $entityManager->flush();
32
33
        return new Response();
34
    }
35
36
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$id" missing
Loading history...
37
     * @Route("/heartbeat/{id}", name="victoire_analytics_heartbeat")
38
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
39
    public function heartbeatAction($id)
40
    {
41
        $entityManager = $this->get('doctrine.orm.entity_manager');
42
        /** @var User $user */
43
        $user = $entityManager->getRepository($this->getParameter('victoire_core.user_class'))->find($id);
44
        $user->setHeartbeat(new \DateTime());
45
        $entityManager->flush();
46
        $this->get('logger')->info('victoire.analytics.user_heartbeat');
47
48
        return new Response(null, 202);
49
    }
50
}
51