GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AnalyticsSessionEvents   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 27
c 1
b 0
f 0
dl 0
loc 55
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B search() 0 32 6
A cast() 0 8 4
1
<?php
2
3
4
namespace ApiVideo\Client\Api;
5
6
7
use ApiVideo\Client\Model\Analytic\PlayerSessionEvent;
8
use DateTime;
9
use Exception;
10
11
class AnalyticsSessionEvents extends BaseApi
12
{
13
14
    /**
15
     * @param       $sessionId
16
     * @param array $parameters
17
     * @return PlayerSessionEvent[]|null
18
     */
19
    public function search($sessionId, array $parameters = array())
20
    {
21
        $currentPage            = isset($parameters['currentPage']) ? $parameters['currentPage'] : 1;
22
        $parameters['pageSize'] = isset($parameters['pageSize']) ? $parameters['pageSize'] : 100;
23
        $analyticSessionEvent   = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $analyticSessionEvent is dead and can be removed.
Loading history...
24
        $items                  = array();
25
26
        do {
27
            $parameters['currentPage'] = $currentPage;
28
            $response                  = $this->browser->get("/analytics/sessions/$sessionId/events?".http_build_query($parameters));
29
30
            if (!$response->isSuccessful()) {
31
                $this->registerLastError($response);
32
33
                return null;
34
            }
35
36
            $json      = json_decode($response->getContent(), true);
37
            $analytics = $json['data'];
38
            $items[]   = $this->castAll($analytics);
39
40
            if (isset($parameters['currentPage'])) {
41
                break;
42
            }
43
44
            $pagination = $json['pagination'];
45
            $pagination['currentPage']++;
46
        } while ($pagination['pagesTotal'] >= $pagination['currentPage']);
47
48
        $items = call_user_func_array('array_merge', $items);
49
50
        return $items;
51
    }
52
53
    /**
54
     * @param array $data
55
     * @return PlayerSessionEvent
56
     * @throws Exception
57
     */
58
    protected function cast(array $data)
59
    {
60
        return new PlayerSessionEvent(
61
            $data['type'],
62
            new DateTime($data['emittedAt']),
63
            isset($data['at']) ? $data['at'] : null,
64
            isset($data['from']) ? $data['from'] : null,
65
            isset($data['to']) ? $data['to'] : null
66
        );
67
    }
68
}