BaseString::getOauthParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace PeeHaa\AsyncTwitter\Oauth\Signature;
4
5
use PeeHaa\AsyncTwitter\Oauth\Parameters;
6
use PeeHaa\AsyncTwitter\Request\Url;
7
8
class BaseString
9
{
10
    private $method;
11
12
    private $url;
13
14
    private $parameters;
15
16 7
    public function __construct(string $method, Url $url, Parameters $parameters)
17
    {
18 7
        $this->method     = strtoupper($method);
19 7
        $this->url        = $url;
20 7
        $this->parameters = $parameters;
21
    }
22
23 7
    public function getString(): string
24
    {
25 7
        return sprintf('%s&%s&%s', $this->method, $this->getBaseString(), $this->getOauthParameters());
26
    }
27
28 7
    private function getBaseString(): string
29
    {
30 7
        return rawurlencode($this->url->getBaseString());
31
    }
32
33 7
    private function getOauthParameters(): string
34
    {
35 7
        $oauthParameters = array_map('rawurlencode', $this->parameters->getAll());
36
37 7
        asort($oauthParameters);
38 7
        ksort($oauthParameters);
39
40
        // we are first `urldecode`ing the value, because `http_build_query` converts spaces to +
41 7
        return rawurlencode(urldecode(http_build_query($oauthParameters, '', '&')));
42
    }
43
}
44