Passed
Push — develop ( a37d8c...129764 )
by Andrew
17:52
created

UrlHelper::sanitizeUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 3
nc 3
nop 2
1
<?php
2
/**
3
 * Retour plugin for Craft CMS 3.x
4
 *
5
 * Retour allows you to intelligently redirect legacy URLs, so that you don't
6
 * lose SEO value when rebuilding & restructuring a website
7
 *
8
 * @link      https://nystudio107.com/
9
 * @copyright Copyright (c) 2020 nystudio107
10
 */
11
12
namespace nystudio107\retour\helpers;
13
14
use craft\helpers\UrlHelper as CraftUrlHelper;
15
16
/**
17
 * @author    nystudio107
18
 * @package   Retour
19
 * @since     3.1.34
20
 */
21
class UrlHelper extends CraftUrlHelper
22
{
23
    // Public Static Properties
24
    // =========================================================================
25
26
    // Public Static Methods
27
    // =========================================================================
28
29
    /**
30
     * Sanitize the passed in URL
31
     *
32
     * @param $url
33
     * @param bool $encode
34
     *
35
     * @return bool|mixed|string
36
     */
37
    public static function sanitizeUrl($url, $encode = false) {
38
        $url = urlencode(urldecode($url));
39
        $url = filter_var(urldecode($url), FILTER_SANITIZE_SPECIAL_CHARS);
40
        if (!filter_var($url, FILTER_VALIDATE_URL)) {
41
            return false;
42
        }
43
44
        return $encode ? urlencode($url) : $url;
45
    }
46
}
47