Url::setUrlRegex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace devtoolboxuk\soteria\classes;
4
5
class Url
6
{
7
8
    //Testing here - https://regex101.com/r/WtnC3m/2
9
10
    private $protocol = '(?:(?:[a-z]+:)?\/\/)';
11
    private $auth = '(?:\\S+(?::\\S*)?@)?';
12
    private $ip = '^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}';
13
    private $tld = "(?<TLD>\.\w+?)(?:$|\/)";
14
    private $tldAlt = '(?:[a-z\\\\u00a1-\\\\uffff]{2,})';
15
    private $host = '(?:(?:[a-z\\\\u00a1-\\\\uffff0-9][-_]*)*[a-z\\\\u00a1-\\\\uffff0-9]+)';
16
    private $domain = '(?:\\.(?:[a-z\\\\u00a1-\\\\uffff0-9]-*)*[a-z\\\\u00a1-\\\\uffff0-9]+)*';
17
    private $port = '(?::\\\\d{2,5})?';
18
    private $path = '(?:[^\s\b\n|]*[^.,;:\?\!\@\^\$ -]*)?';
19
20
    private $standardUrlRegEx = '';
21
    private $stringService;
22
23
    public function __construct($options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        $this->stringService = new Strings();
26
        $this->setUrlRegex();
27
    }
28
29
    private function setUrlRegex()
30
    {
31
        $standardUrlRegEx = '(?:' . $this->protocol . '|www\\.)' . $this->auth . '(?:localhost|' . $this->ip . '|' . $this->host . $this->domain . '(' . $this->tld . '|' . $this->tldAlt . '))' . $this->port . $this->path;
32
33
        $this->standardUrlRegEx = '/' . $standardUrlRegEx . '/i';
34
    }
35
36
    function remove($str)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
    {
38
        return preg_replace($this->standardUrlRegEx, ' ', $str);
39
    }
40
}