Issues (3627)

Controller/AppCallbackController.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2017 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\NotificationBundle\Controller;
13
14
use Mautic\CoreBundle\Controller\CommonController;
15
use Mautic\LeadBundle\Entity\Lead;
16
use Mautic\NotificationBundle\Entity\Notification;
17
use Symfony\Component\HttpFoundation\JsonResponse;
18
use Symfony\Component\HttpFoundation\Request;
19
20
class AppCallbackController extends CommonController
21
{
22
    public function indexAction(Request $request)
23
    {
24
        $requestBody = json_decode($request->getContent(), true);
25
        $em          = $this->get('doctrine.orm.entity_manager');
26
        $contactRepo = $em->getRepository(Lead::class);
27
        $matchData   = [
28
            'email' => $requestBody['email'],
29
        ];
30
31
        /** @var Lead $contact */
32
        $contact = $contactRepo->findOneBy($matchData);
33
34
        if (null === $contact) {
35
            $contact = new Lead();
36
            $contact->setEmail($requestBody['email']);
37
            $contact->setLastActive(new \DateTime());
38
        }
39
40
        $pushIdCreated = false;
41
42
        if (array_key_exists('push_id', $requestBody)) {
43
            $pushIdCreated = true;
44
            $contact->addPushIDEntry($requestBody['push_id'], $requestBody['enabled'], true);
45
            $contactRepo->saveEntity($contact);
46
        }
47
48
        $statCreated = false;
49
50
        if (array_key_exists('stat', $requestBody)) {
51
            $stat             = $requestBody['stat'];
52
            $notificationRepo = $em->getRepository(Notification::class);
53
            $notification     = $notificationRepo->getEntity($stat['notification_id']);
54
55
            if (null !== $notification) {
56
                $statCreated = true;
57
                $this->getModel('notification')->createStatEntry($notification, $contact, $stat['source'], $stat['source_id']);
0 ignored issues
show
The method createStatEntry() does not exist on Mautic\CoreBundle\Model\AbstractCommonModel. It seems like you code against a sub-type of Mautic\CoreBundle\Model\AbstractCommonModel such as Mautic\DynamicContentBun...del\DynamicContentModel or Mautic\NotificationBundle\Model\NotificationModel or Mautic\SmsBundle\Model\SmsModel. ( Ignorable by Annotation )

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

57
                $this->getModel('notification')->/** @scrutinizer ignore-call */ createStatEntry($notification, $contact, $stat['source'], $stat['source_id']);
Loading history...
58
            }
59
        }
60
61
        return new JsonResponse([
62
            'contact_id'       => $contact->getId(),
63
            'stat_recorded'    => $statCreated,
64
            'push_id_recorded' => $pushIdCreated ?: 'existing',
65
        ]);
66
    }
67
}
68