BaseString   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getString() 0 4 1
A getBaseString() 0 4 1
A getOauthParameters() 0 10 1
A __construct() 0 6 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