CdnHelper::filterCdn()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 12
nc 3
nop 1
1
<?php
2
namespace Evheniy\JqueryBundle\Helper;
3
4
/**
5
 * Class CdnHelper
6
 *
7
 * @package Evheniy\JqueryBundle\Helper
8
 */
9
class CdnHelper
10
{
11
    /**
12
     * @return CdnHelper
13
     */
14
    public static function createInstance()
15
    {
16
        return new self;
17
    }
18
19
    /**
20
     * @param string $cdn
21
     *
22
     * @return string
23
     */
24
    public function filterCdn($cdn = '')
25
    {
26
        if (!empty($cdn) && $cdn != '/') {
27
            $url = parse_url($cdn);
28
            if (!empty($url['host'])) {
29
                $cdn = $url['host'];
30
            } else {
31
                $cdn = current(
32
                    array_filter(preg_split('/[^a-z0-9\.]+/', $url['path']))
33
                );
34
            }
35
            $cdn = '//' . $cdn;
36
        } else {
37
            $cdn = '';
38
        }
39
40
        return $cdn;
41
    }
42
}