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

UrlHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 5
c 2
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A sanitizeUrl() 0 10 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