Url   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A clean() 0 16 3
1
<?php
2
/**
3
 * Mage Scan
4
 *
5
 * PHP version 5
6
 *
7
 * @category  MageScan
8
 * @package   MageScan
9
 * @author    Steve Robbins <[email protected]>
10
 * @copyright 2015 Steve Robbins
11
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
12
 * @link      https://github.com/steverobbins/magescan
13
 */
14
15
namespace MageScan;
16
17
/**
18
 * Url helper
19
 *
20
 * @category  MageScan
21
 * @package   MageScan
22
 * @author    Steve Robbins <[email protected]>
23
 * @copyright 2015 Steve Robbins
24
 * @license   http://creativecommons.org/licenses/by/4.0/ CC BY 4.0
25
 * @link      https://github.com/steverobbins/magescan
26
 */
27
class Url
28
{
29
    const DEFAULT_PROTOCOL = 'http';
30
31
    /**
32
     * Get the full, valid url from input
33
     *
34
     * @param string $input Dirty url input
35
     *
36
     * @return string
37
     */
38
    public function clean($input)
39
    {
40
        $bits = explode('://', $input);
41
        if (count($bits) > 1) {
42
            $protocol = $bits[0];
43
            unset($bits[0]);
44
        } else {
45
            $protocol = self::DEFAULT_PROTOCOL;
46
        }
47
        $url  = implode($bits);
48
        $bits = explode('?', $url);
49
        if (substr($bits[0], -1) != '/') {
50
            $bits[0] .= '/';
51
        }
52
        return $protocol . '://' . implode('?', $bits);
53
    }
54
}
55