CdnHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 0
cbo 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 4 1
A filterCdn() 0 18 4
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
}