Completed
Push — master ( 472ec5...cf38d9 )
by Rob
02:55
created

Url::setUrlRegex()   A

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
    private $protocol = '(?:(?:[a-z]+:)?\/\/)';
9
    private $auth = '(?:\\S+(?::\\S*)?@)?';
10
    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}';
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $ip. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
11
    private $tld = "(?<TLD>\.\w+?)(?:$|\/)";
12
    private $tldAlt = '(?:[a-z\\\\u00a1-\\\\uffff]{2,})';
13
    private $host = '(?:(?:[a-z\\\\u00a1-\\\\uffff0-9][-_]*)*[a-z\\\\u00a1-\\\\uffff0-9]+)';
14
    private $domain = '(?:\\.(?:[a-z\\\\u00a1-\\\\uffff0-9]-*)*[a-z\\\\u00a1-\\\\uffff0-9]+)*';
15
    private $port = '(?::\\\\d{2,5})?';
16
    private $path = '(?:[^\s\b\n|]*[^.,;:\?\!\@\^\$ -]*)?';
17
18
    private $standardUrlRegEx = '';
19
    private $stringService;
20
21
    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...
22
    {
23
        $this->stringService = new Strings();
24
        $this->setUrlRegex();
25
    }
26
27
    private function setUrlRegex()
28
    {
29
        $standardUrlRegEx = '(?:' . $this->protocol . '|www\\.)' . $this->auth . '(?:localhost|' . $this->ip . '|' . $this->host . $this->domain . '(' . $this->tld . '|' . $this->tldAlt . '))' . $this->port . $this->path;
30
31
        $this->standardUrlRegEx = '/' . $standardUrlRegEx . '/i';
32
    }
33
34
    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...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for remove.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

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