Completed
Push — master ( 037db1...ba35b9 )
by Viacheslav
02:55
created

WebinarApi::getSubscribers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 9.9332
cc 1
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
4
namespace slavkluev\Bizon365\Api;
5
6
use slavkluev\Bizon365\Helpers\UrlHelper;
7
8
class WebinarApi extends AbstractApi
9
{
10
    const METHODS = [
11
        'get'               => 'webinars/reports/get',
12
        'get.list'          => 'webinars/reports/getlist',
13
        'get.viewers'       => 'webinars/reports/getviewers',
14
        'get.subpages'      => 'webinars/subpages/getSubpages',
15
        'get.subscribers'   => 'webinars/subpages/getSubscribers',
16
        'add.subscriber'    => 'webinars/subpages/addSubscriber',
17
        'remove.subscriber' => 'webinars/subpages/removeSubscriber',
18
    ];
19
20
    /**
21
     * @param int $skip
22
     * @param int $limit
23
     * @param bool $liveWebinars
24
     * @param bool $autoWebinars
25
     * @return array
26
     */
27 3
    public function getList(
28
        int $skip = 0,
29
        int $limit = 20,
30
        bool $liveWebinars = true,
31
        bool $autoWebinars = true
32
    ) {
33 3
        $url = UrlHelper::build(self::METHODS['get.list'], [
34 3
            'skip'         => $skip,
35 3
            'limit'        => $limit,
36 3
            'LiveWebinars' => $liveWebinars,
37 3
            'AutoWebinars' => $autoWebinars,
38
        ]);
39 3
        return $this->get($url);
40
    }
41
42
    /**
43
     * @param string $webinarId
44
     * @return array
45
     */
46 3
    public function getWebinar(string $webinarId)
47
    {
48 3
        $url = UrlHelper::build(self::METHODS['get'], [
49 3
            'webinarId' => $webinarId,
50
        ]);
51 3
        print_r($url);
52 3
        return $this->get($url);
53
    }
54
55
    /**
56
     * @param string $webinarId
57
     * @param int $skip
58
     * @param int $limit
59
     * @return array
60
     */
61 3
    public function getViewers(
62
        string $webinarId,
63
        int $skip = 0,
64
        int $limit = 1000
65
    ) {
66 3
        $url = UrlHelper::build(self::METHODS['get.viewers'], [
67 3
            'webinarId' => $webinarId,
68 3
            'skip'      => $skip,
69 3
            'limit'     => $limit,
70
        ]);
71 3
        return $this->get($url);
72
    }
73
74 3
    public function getSubpages(
75
        int $skip = 0,
76
        int $limit = 50
77
    ) {
78 3
        $url = UrlHelper::build(self::METHODS['get.subpages'], [
79 3
            'skip'  => $skip,
80 3
            'limit' => $limit,
81
        ]);
82 3
        return $this->get($url);
83
    }
84
85 3
    public function getSubscribers(
86
        string $pageId,
87
        int $skip                 = 0,
88
        int $limit                = 50,
89
        string $registeredTimeMin = null,
90
        string $registeredTimeMax = null,
91
        string $webinarTimeMin    = null,
92
        string $webinarTimeMax    = null,
93
        string $urlMarker         = null
94
    ) {
95 3
        $url = UrlHelper::build(self::METHODS['get.subscribers'], [
96 3
            'pageId'            => $pageId,
97 3
            'skip'              => $skip,
98 3
            'limit'             => $limit,
99 3
            'registeredTimeMin' => $registeredTimeMin,
100 3
            'registeredTimeMax' => $registeredTimeMax,
101 3
            'webinarTimeMin'    => $webinarTimeMin,
102 3
            'webinarTimeMax'    => $webinarTimeMax,
103 3
            'urlMarker'         => $urlMarker,
104
        ]);
105 3
        return $this->get($url);
106
    }
107
108 3
    public function addSubscriber(array $subscriber) {
109 3
        return $this->post(self::METHODS['add.subscriber'], $subscriber);
110
    }
111
112 3
    public function removeSubscriber(
113
        string $pageId,
114
        string $email
115
    ) {
116 3
        return $this->post(self::METHODS['remove.subscriber'], [
117 3
            'pageId' => $pageId,
118 3
            'email'  => $email,
119
        ]);
120
    }
121
}
122