BaseRequest::setPublicKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Phrlog\Zvonok\Phone\Request;
4
5
/**
6
 * Class BaseRequest
7
 */
8
abstract class BaseRequest implements RequestInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $public_key;
14
15
    /**
16
     * @param string $key
17
     * @return BaseRequest
18
     */
19
    public function setPublicKey(string $key): self
20
    {
21
        $this->public_key = $key;
22
23
        return $this;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function generateUri(): string
30
    {
31
        $availableParams = array_merge($this->getAvailableParams(), ['public_key']);
32
33
        $queryArray = [];
34
        foreach ($availableParams as $paramName) {
35
            $queryArray[$paramName] = $this->$paramName;
36
        }
37
38
        return $this->getUri() . '?' . http_build_query(array_filter($queryArray));
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    abstract protected function getAvailableParams(): array;
45
46
    /**
47
     * @return string
48
     */
49
    abstract protected function getUri(): string;
50
}
51