Url   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseHost() 0 5 3
B isRfc() 0 13 6
1
<?php
2
namespace SEOstats\Helper;
3
4
/**
5
 * URL-String Helper Class
6
 *
7
 * @package    SEOstats
8
 * @author     Stephan Schmitz <[email protected]>
9
 * @copyright  Copyright (c) 2010 - present Stephan Schmitz
10
 * @license    http://eyecatchup.mit-license.org/  MIT License
11
 * @updated    2013/02/03
12
 */
13
14
class Url
15
{
16 172
    public static function parseHost($url)
17
    {
18 172
        $url = @parse_url('http://' . preg_replace('#^https?://#', '', $url));
19 172
        return (isset($url['host']) && !empty($url['host'])) ? $url['host'] : false;
20
    }
21
22
    /**
23
     * Validates the initialized object URL syntax.
24
     *
25
     * @access        private
26
     * @param         string        $url        String, containing the initialized object URL.
27
     * @return        string                    Returns string, containing the validation result.
28
     */
29 164
    public static function isRfc($url)
30
    {
31 164
        if(isset($url) && 1 < strlen($url)) {
32 162
            $host   = self::parseHost($url);
33 162
            $scheme = strtolower(parse_url($url, PHP_URL_SCHEME));
34 162
            if (false !== $host && ($scheme == 'http' || $scheme == 'https')) {
35 158
                $pattern  = '([A-Za-z][A-Za-z0-9+.-]{1,120}:[A-Za-z0-9/](([A-Za-z0-9$_.+!*,;/?:@&~=-])';
36 158
                $pattern .= '|%[A-Fa-f0-9]{2}){1,333}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*,;/?:@&~=%-]{0,1000}))?)';
37 158
                return (bool) preg_match($pattern, $url);
38
            }
39 4
        }
40 6
        return false;
41
    }
42
}
43