Url   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 36
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setUrlRegex() 0 6 1
A remove() 0 4 1
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
}