Passed
Pull Request — v3 (#105)
by M. Mikkel
21:06
created

UrlHelper::sanitizeUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 1
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 Methods
24
    // =========================================================================
25
26
    /**
27
     * Return a sanitized URL
28
     *
29
     * @param string $url
30
     *
31
     * @return string
32
     */
33
    public static function sanitizeUrl(string $url): string
34
    {
35
        // HTML decode the entities, then strip out any tags
36
        $url = html_entity_decode($url, ENT_NOQUOTES, 'UTF-8');
37
        $url = strip_tags($url);
38
        // Remove any Twig tags that somehow are present in the incoming URL
39
        /** @noinspection CallableParameterUseCaseInTypeContextInspection */
40
        $url = preg_replace('/{.*}/', '', $url);
41
42
        return $url;
43
    }
44
}
45