Completed
Push — master ( ac7d60...f9cacf )
by Denis
04:30
created

Report::getUsersVisitsSatistics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1.0028

Importance

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