Completed
Push — master ( db0246...91f80b )
by Denis
02:07
created

Report::getUrl()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 52
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8.0109

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 17
cts 18
cp 0.9444
rs 6.8493
c 0
b 0
f 0
cc 8
eloc 42
nc 8
nop 2
crap 8.0109

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 7
    public function getUrl($method, array $params = [])
33
    {
34
        switch ($method) {
35 7
            case 'getBooksViewsStatistics':
36
                return [
37 1
                    'url' => '/1.0/report/stat/book',
38
                    'method' => 'GET',
39
                    'code' => 200
40
                ];
41 6
            case 'getJournalsViewsStatistics':
42
                return [
43 1
                    'url' => '/1.0/report/stat/journal',
44
                    'method' => 'GET',
45
                    'code' => 200
46
                ];
47 5
            case 'getUsersVisitsSatistics':
48
                return [
49 1
                    'url' => '/1.0/report/stat/visit',
50
                    'method' => 'GET',
51
                    'code' => 200
52
                ];
53 4
            case 'getAvailablePackets':
54
                return [
55 1
                    'url' => '/1.0/report/available/packet',
56
                    'method' => 'GET',
57
                    'params' => [],
58
                    'code' => 200
59
                ];
60 3
            case 'getAvailableBooks':
61
                return [
62 1
                    'url' => vsprintf('/1.0/report/available/book/%d', $params),
63 1
                    'method' => 'GET',
64 1
                    'code' => 200
65
                ];
66 2
            case 'getAvailableJournals':
67
                return [
68 1
                    'url' => '/1.0/report/available/journal',
69
                    'params' => [],
70
                    'method' => 'GET',
71
                    'code' => 200
72
                ];
73 1
            case 'getFormReportEBooks':
74
                return [
75 1
                    'url' => '/1.0/report/form/eBooks',
76
                    'params' => [],
77
                    'method' => 'GET',
78
                    'code' => 200
79
                ];
80
            default:
81
                throw new Exception('Route for ' . $method . ' not found');
82
        }
83
    }
84
85 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...
86
    {
87 1
        return $this->client->getResponse(
88 1
            $this->getUrl(__FUNCTION__),
89
            [
90 1
                'group_by' => $groupBy,
91 1
                'period_range_from' => $periodFrom,
92 1
                'period_range_to' => $periodTo,
93
            ]
94
        )['data'];
95
    }
96
97 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...
98
    {
99 1
        return $this->client->getResponse(
100 1
            $this->getUrl(__FUNCTION__),
101
            [
102 1
                'group_by' => $groupBy,
103 1
                'period_range_from' => $periodFrom,
104 1
                'period_range_to' => $periodTo,
105
            ]
106
        )['data'];
107
    }
108
109 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...
110
    {
111 1
        return $this->client->getResponse(
112 1
            $this->getUrl(__FUNCTION__),
113
            [
114 1
                'group_by' => $groupBy,
115 1
                'period_range_from' => $periodFrom,
116 1
                'period_range_to' => $periodTo,
117
            ]
118
        )['data'];
119
    }
120
121 1
    public function getAvailablePackets()
122
    {
123 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
124
    }
125
126 1
    public function getAvailableBooks($pdKey)
127
    {
128 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__, ['pdKey' => $pdKey]))['data'];
129
    }
130
131 1
    public function getAvailableJournals()
132
    {
133 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
134
    }
135
136 1
    public function getFormReportEBooks()
137
    {
138 1
        return $this->client->getResponse($this->getUrl(__FUNCTION__))['data'];
139
    }
140
}