GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

UriGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 16 2
A encodeUriParameters() 0 6 1
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 */
5
6
namespace CommerceLeague\ActiveCampaignApi\Routing;
7
8
use Psr\Http\Message\UriInterface;
9
10
/**
11
 * Class UriGenerator
12
 */
13
class UriGenerator implements UriGeneratorInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $baseUri;
19
20
    /**
21
     * @param string $baseUri
22
     */
23
    public function __construct(string $baseUri)
24
    {
25
        $this->baseUri = rtrim($baseUri, '/');
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function generate(string $path, array $uriParameters = [], array $queryParameters = []): string
32
    {
33
        $uriParameters = $this->encodeUriParameters($uriParameters);
34
35
        $uri = $this->baseUri . '/' . vsprintf(ltrim($path, '/'), $uriParameters);
36
37
        if (!empty($queryParameters)) {
38
            $uri .= '?' . http_build_query(
39
                $queryParameters,
40
                '',
41
                '&',
42
                PHP_QUERY_RFC3986
43
            );
44
        }
45
46
        return $uri;
47
    }
48
49
    /**
50
     * @param array $uriParameters
51
     * @return array
52
     */
53
    private function encodeUriParameters(array $uriParameters): array
54
    {
55
        return array_map(function ($uriParameter) {
56
            $uriParameter = rawurlencode((string)$uriParameter);
57
            return preg_replace('~\%2F~', '/', $uriParameter);
58
        }, $uriParameters);
59
    }
60
}
61