Passed
Pull Request — master (#189)
by Ghazi
10:24
created

UrlBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildUrl() 0 3 2
A buildQs() 0 3 1
1
<?php
2
3
/*
4
 * BigBlueButton open source conferencing system - https://www.bigbluebutton.org/.
5
 *
6
 * Copyright (c) 2016-2022 BigBlueButton Inc. and by respective authors (see below).
7
 *
8
 * This program is free software; you can redistribute it and/or modify it under the
9
 * terms of the GNU Lesser General Public License as published by the Free Software
10
 * Foundation; either version 3.0 of the License, or (at your option) any later
11
 * version.
12
 *
13
 * BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
14
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License along
18
 * with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
namespace BigBlueButton\Util;
22
23
/**
24
 * Class UrlBuilder.
25
 */
26
class UrlBuilder
27
{
28
    /**
29
     * @var string
30
     */
31
    private $securitySalt;
32
33
    /**
34
     * @var string
35
     */
36
    private $bbbServerBaseUrl;
37
38
    /**
39
     * UrlBuilder constructor.
40
     *
41
     * @param $secret
42
     * @param $serverBaseUrl
43
     */
44
    public function __construct($secret, $serverBaseUrl)
45
    {
46
        $this->securitySalt     = $secret;
47
        $this->bbbServerBaseUrl = $serverBaseUrl;
48
    }
49
50
    /**
51
     * Builds an API method URL that includes the url + params + its generated checksum.
52
     *
53
     * @param string $method
54
     * @param string $params
55
     * @param bool   $append
56
     *
57
     * @return string
58
     */
59
    public function buildUrl($method = '', $params = '', $append = true)
60
    {
61
        return $this->bbbServerBaseUrl . 'api/' . $method . ($append ? '?' . $this->buildQs($method, $params) : '');
62
    }
63
64
    /**
65
     * Builds a query string for an API method URL that includes the params + its generated checksum.
66
     *
67
     * @param string $method
68
     * @param string $params
69
     *
70
     * @return string
71
     */
72
    public function buildQs($method = '', $params = '')
73
    {
74
        return $params . '&checksum=' . sha1($method . $params . $this->securitySalt);
75
    }
76
}
77