Compat   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A cleanHeaderLocation() 0 18 3
1
<?php
2
namespace Mailxpert\Util;
3
4
/**
5
 * Date: 20/08/15
6
 */
7
class Compat
8
{
9
    /**
10
     * Due to a conception mistake, the access token was returned with some POST request in the early stage of MX API V2.0 and was removed from it.
11
     * This patch fix potential access_token present in the header Location
12
     *
13
     * @param string $url
14
     *
15
     * @return string
16
     */
17
    public static function cleanHeaderLocation($url)
18
    {
19
        $urlElements = parse_url($url);
20
21
        parse_str($urlElements['query'], $query);
22
23
        if (isset($query['access_token'])) {
24
            unset($query['access_token']);
25
        }
26
27
        $newUrl = sprintf('%s://%s%s', $urlElements['scheme'], $urlElements['host'], $urlElements['path']);
28
29
        if (count($query)) {
30
            $newUrl .= '?'.http_build_query($query);
31
        }
32
33
        return $newUrl;
34
    }
35
}
36