Test Failed
Pull Request — master (#228)
by Guilherme
03:49
created

StatisticsController::getDeliveryAverageAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\PhoneVerificationBundle\Controller;
12
13
use LoginCidadao\PhoneVerificationBundle\Service\SmsStatusService;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
17
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
18
use Symfony\Component\HttpFoundation\JsonResponse;
19
use Symfony\Component\HttpFoundation\Request;
20
21
/**
22
 * @codeCoverageIgnore
23
 */
24
class StatisticsController extends Controller
25
{
26
    /**
27
     * @Route("/api/v1/phone-verification/update-status.{_format}",
28
     *     name="api_v1_phone_verification_update_status",
29
     *     defaults={"_format"="json"}
30
     * )
31
     * @Template()
32
     */
33
    public function updateAction()
34
    {
35
        /** @var SmsStatusService $smsUpdater */
36
        $smsUpdater = $this->get('phone_verification.sms_status');
37
        $transactionsUpdated = $smsUpdater->updateSentVerificationStatus();
38
39
        return new JsonResponse([
40
            'transactions_updated' => $transactionsUpdated,
41
            'count' => count($transactionsUpdated),
42
        ]);
43
    }
44
45
    /**
46
     * @Route("/api/v1/phone-verification/average-delivery-time.{_format}",
47
     *     name="api_v1_phone_verification_average_delivery_time",
48
     *     defaults={"_format"="json"}
49
     * )
50
     * @Method("GET")
51
     * @Template()
52
     */
53
    public function getDeliveryAverageAction(Request $request)
54
    {
55
        $amount = $request->get('amount', 10);
56
57
        /** @var SmsStatusService $smsUpdater */
58
        $smsUpdater = $this->get('phone_verification.sms_status');
59
        $average = $smsUpdater->getAverageDeliveryTime($amount);
60
61
        return new JsonResponse(['average_delivery_time' => $average, 'unit' => 'seconds']);
62
    }
63
64
    /**
65
     * @Route("/api/v1/phone-verification/not-delivered.{_format}",
66
     *     name="api_v1_phone_verification_not_delivered",
67
     *     defaults={"_format"="json"}
68
     * )
69
     * @Method("GET")
70
     * @Template()
71
     */
72
    public function getNotDeliveredAction(Request $request)
73
    {
74
        $seconds = $request->get('seconds', null);
75
        $seconds = is_numeric($seconds) ? (int)$seconds : null;
76
77
        /** @var SmsStatusService $smsUpdater */
78
        $smsUpdater = $this->get('phone_verification.sms_status');
79
80
        if ($seconds === null) {
81
            $seconds = $smsUpdater->getAverageDeliveryTime(10);
82
        }
83
84
        $notDelivered = $smsUpdater->getDelayedDeliveryTransactions($seconds);
0 ignored issues
show
Bug introduced by
It seems like $seconds can also be of type double; however, parameter $maxDeliverySeconds of LoginCidadao\PhoneVerifi...dDeliveryTransactions() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

84
        $notDelivered = $smsUpdater->getDelayedDeliveryTransactions(/** @scrutinizer ignore-type */ $seconds);
Loading history...
85
86
        return new JsonResponse([
87
            'delayed_transactions' => $notDelivered,
88
            'count' => count($notDelivered),
89
            'max_delay' => $seconds,
90
        ]);
91
    }
92
}
93