CDNBase::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace Ajax\lib;
4
5
use Ajax\service\PhalconUtils;
6
7
abstract class CDNBase {
8
	protected $version;
9
	protected $provider;
10
	protected $data;
11
	protected $local;
12
	protected $jsUrl;
13
14
	public function __construct($version, $provider) {
15
		$this->data=include 'CDN.php';
16
		$this->version=$version;
17
		$this->provider=$provider;
18
		$this->local=false;
19
		$this->jsUrl=null;
20
	}
21
22
	public function getJsUrl() {
23
		return $this->jsUrl;
24
	}
25
26 View Code Duplication
	public function setJsUrl($jsUrl, $local=null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
		$this->jsUrl=$jsUrl;
28
		if (isset($local)===false) {
29
			$local=PhalconUtils::startsWith($jsUrl, "http")===false;
30
		}
31
		$this->setLocal($local);
32
		return $this;
33
	}
34
35
	protected function getUrlOrCss($element, $key) {
36
		if (isset($element))
37
			return $element;
38
		$version=$this->version;
39
		if (array_search($version, $this->getVersions())===false)
40
			$version=$this->getLastVersion();
41
		return $this->replaceVersion($this->data [$this->provider] [$key], $version);
42
	}
43
44
	public function isLocal() {
45
		return $this->local;
46
	}
47
48
	public function setLocal($local) {
49
		$this->local=$local;
50
		return $this;
51
	}
52
53
	protected function replaceVersion($url, $version) {
54
		return str_ireplace("%version%", $version, $url);
55
	}
56
57
	protected function replaceTheme($url, $theme) {
58
		return str_ireplace("%theme%", $theme, $url);
59
	}
60
61
	protected function replaceVersionAndTheme($url, $version, $theme) {
62
		if (isset($theme))
63
			return str_ireplace(array (
64
					"%theme%",
65
					"%version%" 
66
			), array (
67
					$theme,
68
					$version 
69
			), $url);
70
		else
71
			return $this->replaceVersion($url, $version);
72
	}
73
74
	public function getProviders() {
75
		return array_keys($this->data);
76
	}
77
78
	public function getVersions($provider=NULL) {
79
		if (isset($provider))
80
			return $this->data [$provider] ["versions"];
81
		else
82
			return $this->data [$this->provider] ["versions"];
83
	}
84
85
	public function getLastVersion($provider=NULL) {
86
		return $this->getVersions($provider)[0];
87
	}
88
89
	abstract public function getUrl();
90
}