Completed
Push — master ( c14aad...5ba59a )
by Denis
06:56
created

Report::getJournalsViewsStatistics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dp
5
 * Date: 16.08.17
6
 * Time: 13:09
7
 */
8
9
namespace Lan\Ebs\Sdk;
10
11
use Exception;
12
13
final class Report implements Common
14
{
15
    private $client;
16
17
    /**
18
     * Security constructor.
19
     *
20
     * @param  Client $client
21
     * @throws Exception
22
     */
23 7
    public function __construct(Client $client)
24
    {
25 7
        if (!$client) {
26
            throw new Exception('Client not defined');
27
        }
28
29 7
        $this->client = $client;
30 7
    }
31
32
    /**
33
     * @param $method
34
     * @param array $params
35
     * @return array
36
     * @throws Exception
37
     */
38 7
    public function getUrl($method, array $params = [])
39
    {
40
        switch ($method) {
41 7
            case 'getBooksViewsStatistics':
42
                return [
43 1
                    'url' => '/1.0/report/stat/book',
44 1
                    'method' => 'GET',
45
                    'code' => 200
46 1
                ];
47 6
            case 'getJournalsViewsStatistics':
48
                return [
49 1
                    'url' => '/1.0/report/stat/journal',
50 1
                    'method' => 'GET',
51
                    'code' => 200
52 1
                ];
53 5
            case 'getUsersVisitsSatistics':
54
                return [
55 1
                    'url' => '/1.0/report/stat/visit',
56 1
                    'method' => 'GET',
57
                    'code' => 200
58 1
                ];
59 4
            case 'getAvailablePackets':
60
                return [
61 1
                    'url' => '/1.0/report/available/packet',
62 1
                    'method' => 'GET',
63 1
                    'params' => [],
64
                    'code' => 200
65 1
                ];
66 3
            case 'getAvailableBooks':
67
                return [
68 1
                    'url' => vsprintf('/1.0/report/available/book/%d', $params),
69 1
                    'method' => 'GET',
70
                    'code' => 200
71 1
                ];
72 2
            case 'getAvailableJournals':
73
                return [
74 1
                    'url' => '/1.0/report/available/journal',
75 1
                    'params' => [],
76 1
                    'method' => 'GET',
77
                    'code' => 200
78 1
                ];
79 1
            case 'getFormReportEBooks':
80
                return [
81 1
                    'url' => '/1.0/report/form/eBooks',
82 1
                    'params' => [],
83 1
                    'method' => 'GET',
84
                    'code' => 200
85 1
                ];
86
            default:
87
                throw new Exception('Route for ' . $method . ' not found');
88
        }
89
    }
90
91
    /**
92
     * @param null $groupBy
93
     * @param null $periodFrom
94
     * @param null $periodTo
95
     * @return mixed
96
     * @throws Exception
97
     */
98 1 View Code Duplication
    public function getBooksViewsStatistics($groupBy = null, $periodFrom = null, $periodTo = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100 1
        return $this->client->getResponse(
101 1
            $this->getUrl(__FUNCTION__),
102
            [
103 1
                'group_by' => $groupBy,
104 1
                'period_range_from' => $periodFrom,
105 1
                'period_range_to' => $periodTo,
106
            ]
107 1
        )['data'];
108
    }
109
110
    /**
111
     * @param null $groupBy
112
     * @param null $periodFrom
113
     * @param null $periodTo
114
     * @return mixed
115
     * @throws Exception
116
     */
117 1 View Code Duplication
    public function getJournalsViewsStatistics($groupBy = null, $periodFrom = null, $periodTo = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
    {
119 1
        return $this->client->getResponse(
120 1
            $this->getUrl(__FUNCTION__),
121
            [
122 1
                'group_by' => $groupBy,
123 1
                'period_range_from' => $periodFrom,
124 1
                'period_range_to' => $periodTo,
125
            ]
126 1
        )['data'];
127
    }
128
129
    /**
130
     * @param null $groupBy
131
     * @param null $periodFrom
132
     * @param null $periodTo
133
     * @return mixed
134
     * @throws Exception
135
     */
136 1 View Code Duplication
    public function getUsersVisitsSatistics($groupBy = null, $periodFrom = null, $periodTo = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138 1
        return $this->client->getResponse(
139 1
            $this->getUrl(__FUNCTION__),
140
            [
141 1
                'group_by' => $groupBy,
142 1
                'period_range_from' => $periodFrom,
143 1
                'period_range_to' => $periodTo,
144
            ]
145 1
        )['data'];
146
    }
147
148
    /**
149
     * @return mixed
150
     * @throws Exception
151
     */
152 1
    public function getAvailablePackets()
153
    {
154 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
155
    }
156
157
    /**
158
     * @param $pdKey
159
     * @return mixed
160
     * @throws Exception
161
     */
162 1
    public function getAvailableBooks($pdKey)
163
    {
164 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__, ['pdKey' => $pdKey]))['data'];
165
    }
166
167
    /**
168
     * @return mixed
169
     * @throws Exception
170
     */
171 1
    public function getAvailableJournals()
172
    {
173 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
174
    }
175
176
    /**
177
     * @return mixed
178
     * @throws Exception
179
     */
180 1
    public function getFormReportEBooks()
181
    {
182 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
183
    }
184
}