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.
Completed
Push — master ( 6a5cb5...bf5e8a )
by Jorge
11s
created

PrepareUrl::build()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
3
namespace TheIconic\Tracking\GoogleAnalytics\Network;
4
5
use TheIconic\Tracking\GoogleAnalytics\Parameters\General\CacheBuster;
6
7
/**
8
 * Class PrepareUrl
9
 *
10
 * @package TheIconic\Tracking\GoogleAnalytics
11
 */
12
class PrepareUrl
13
{
14
    /**
15
     * @var array
16
     */
17
    private $payloadParameters;
18
19
    /**
20
     * @var string
21
     */
22
    private $cacheBuster = '';
23
24
    /**
25
     * Build URL which is sent to Google Analytics
26
     *
27
     * @param string $url
28
     * @param SingleParameter[] $singleParameters
29
     * @param CompoundParameterCollection[] $compoundParameters
30
     * @return string
31
     */
32
    public function build($url, array $singleParameters, array $compoundParameters)
33
    {
34
        $singlesPost = $this->getSingleParametersPayload($singleParameters);
35
36
        $compoundsPost = $this->getCompoundParametersPayload($compoundParameters);
37
38
        $this->payloadParameters = array_merge($singlesPost, $compoundsPost);
39
40
        if (!empty($this->cacheBuster)) {
41
            $this->payloadParameters['z'] = $this->cacheBuster;
42
        }
43
44
        return $url . '?' . http_build_query($this->payloadParameters);
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getPayloadParameters()
51
    {
52
        return $this->payloadParameters;
53
    }
54
55
    /**
56
     * Prepares all the Single Parameters to be sent to GA.
57
     *
58
     * @param SingleParameter[] $singleParameters
59
     * @return array
60
     */
61
    private function getSingleParametersPayload(array $singleParameters)
62
    {
63
        $postData = [];
64
        $cacheBuster = new CacheBuster();
65
66
        foreach ($singleParameters as $parameterObj) {
67
            if ($parameterObj->getName() === $cacheBuster->getName()) {
68
                $this->cacheBuster = $parameterObj->getValue();
69
                continue;
70
            }
71
72
            $postData[$parameterObj->getName()] = $parameterObj->getValue();
73
        }
74
75
        return $postData;
76
    }
77
78
    /**
79
     * Prepares compound parameters inside collections to be sent to GA.
80
     *
81
     * @param CompoundParameterCollection[] $compoundParameters
82
     * @return array
83
     */
84
    private function getCompoundParametersPayload(array $compoundParameters)
85
    {
86
        $postData = [];
87
88
        foreach ($compoundParameters as $compoundCollection) {
89
            $parameterArray = $compoundCollection->getParametersArray();
90
            $postData = array_merge($postData, $parameterArray);
91
        }
92
93
        return $postData;
94
    }
95
}