Completed
Push — master ( 5ba59a...5157fd )
by Denis
02:04
created

Report::getUrl()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 49
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 0
cts 18
cp 0
rs 6.1403
c 0
b 0
f 0
cc 8
eloc 39
nc 8
nop 2
crap 72
1
<?php
2
3
namespace Lan\Ebs\Sdk;
4
5
use Exception;
6
7
final class Report implements Common
8
{
9
    private $client;
10
11
    /**
12
     * Security constructor.
13
     *
14
     * @param  Client $client
15
     * @throws Exception
16
     */
17
    public function __construct(Client $client)
18
    {
19
        if (!$client) {
20
            throw new Exception('Client not defined');
21
        }
22
23
        $this->client = $client;
24
    }
25
26
    /**
27
     * @param null $groupBy
28
     * @param null $periodFrom
29
     * @param null $periodTo
30
     * @return mixed
31
     * @throws Exception
32
     */
33 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...
34
    {
35
        return $this->client->getResponse(
36
            $this->getUrl(__FUNCTION__),
37
            [
38
                'group_by' => $groupBy,
39
                'period_range_from' => $periodFrom,
40
                'period_range_to' => $periodTo,
41
            ]
42
        )['data'];
43
    }
44
45
    /**
46
     * @param $method
47
     * @param array $params
48
     * @return array
49
     * @throws Exception
50
     */
51
    public function getUrl($method, array $params = [])
52
    {
53
        switch ($method) {
54
            case 'getBooksViewsStatistics':
55
                return [
56
                    'url' => '/1.0/report/stat/book',
57
                    'method' => 'GET',
58
                    'code' => 200
59
                ];
60
            case 'getJournalsViewsStatistics':
61
                return [
62
                    'url' => '/1.0/report/stat/journal',
63
                    'method' => 'GET',
64
                    'code' => 200
65
                ];
66
            case 'getUsersVisitsSatistics':
67
                return [
68
                    'url' => '/1.0/report/stat/visit',
69
                    'method' => 'GET',
70
                    'code' => 200
71
                ];
72
            case 'getAvailablePackets':
73
                return [
74
                    'url' => '/1.0/report/available/packet',
75
                    'method' => 'GET',
76
                    'code' => 200
77
                ];
78
            case 'getAvailableBooks':
79
                return [
80
                    'url' => vsprintf('/1.0/report/available/book/%d', $params),
81
                    'method' => 'GET',
82
                    'code' => 200
83
                ];
84
            case 'getAvailableJournals':
85
                return [
86
                    'url' => '/1.0/report/available/journal',
87
                    'method' => 'GET',
88
                    'code' => 200
89
                ];
90
            case 'getFormReportEBooks':
91
                return [
92
                    'url' => '/1.0/report/form/eBooks',
93
                    'method' => 'GET',
94
                    'code' => 200
95
                ];
96
            default:
97
                throw new Exception('Route for ' . $method . ' not found');
98
        }
99
    }
100
101
    /**
102
     * @param null $groupBy
103
     * @param null $periodFrom
104
     * @param null $periodTo
105
     * @return mixed
106
     * @throws Exception
107
     */
108 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...
109
    {
110
        return $this->client->getResponse(
111
            $this->getUrl(__FUNCTION__),
112
            [
113
                'group_by' => $groupBy,
114
                'period_range_from' => $periodFrom,
115
                'period_range_to' => $periodTo,
116
            ]
117
        )['data'];
118
    }
119
120
    /**
121
     * @param null $groupBy
122
     * @param null $periodFrom
123
     * @param null $periodTo
124
     * @return mixed
125
     * @throws Exception
126
     */
127 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...
128
    {
129
        return $this->client->getResponse(
130
            $this->getUrl(__FUNCTION__),
131
            [
132
                'group_by' => $groupBy,
133
                'period_range_from' => $periodFrom,
134
                'period_range_to' => $periodTo,
135
            ]
136
        )['data'];
137
    }
138
139
    /**
140
     * @return mixed
141
     * @throws Exception
142
     */
143
    public function getAvailablePackets()
144
    {
145
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
146
    }
147
148
    /**
149
     * @param $pdKey
150
     * @return mixed
151
     * @throws Exception
152
     */
153
    public function getAvailableBooks($pdKey)
154
    {
155
        return $this->client->getResponse($this->getUrl(__FUNCTION__, ['pdKey' => $pdKey]))['data'];
156
    }
157
158
    /**
159
     * @return mixed
160
     * @throws Exception
161
     */
162
    public function getAvailableJournals()
163
    {
164
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
165
    }
166
167
    /**
168
     * @return mixed
169
     * @throws Exception
170
     */
171
    public function getFormReportEBooks()
172
    {
173
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
174
    }
175
}