InlineWebLibrary   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Importance

Changes 0
Metric Value
wmc 17
lcom 3
cbo 2
dl 0
loc 193
rs 10
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setJsElement() 0 4 1
A setCssElement() 0 4 1
A setAdditionalElement() 0 4 1
A getJsFiles() 0 3 1
A getCssFiles() 0 3 1
A getDependencies() 0 3 1
A getFeatures() 0 3 1
A setJSFromText() 0 3 1
A setJSFromFile() 0 3 1
A setCSSFromText() 0 3 1
A setCSSFromFile() 0 3 1
A setAdditionalElementFromText() 0 3 1
A setAdditionalElementFromFile() 0 3 1
A getJsElement() 0 3 1
A getCssElement() 0 3 1
A getAdditionalElement() 0 3 1
1
<?php
2
namespace Mouf\Html\Utils\WebLibraryManager;
3
4
use Mouf\Html\HtmlElement\HtmlFromFile;
5
use Mouf\Html\HtmlElement\HtmlString;
6
use Mouf\Html\HtmlElement\HtmlElementInterface;
7
use Mouf\Html\HtmlElement\Scopable;
8
use Mouf\Html\Utils\WebLibraryManager\WebLibraryInterface;
9
10
/**
11
 * This class can be used to insert JS or CSS directly into the &lt;head&gt; tag (inline).
12
 * Content is loaded from PHP files passed to this object.
13
 *
14
 */
15
class InlineWebLibrary implements WebLibraryInterface {
16
	
17
	/**
18
	 * A custom Html element that will be inserted into the JS scripts into your &lt;head&gt; tag.
19
	 * 
20
	 * @var HtmlElementInterface
21
	 */
22
	protected $jsElement;
23
	
24
	/**
25
	 * A custom CSS element that will be inserted into the JS scripts into your &lt;head&gt; tag.
26
	 * 
27
	 * @var HtmlElementInterface
28
	 */
29
	protected $cssElement;
30
	
31
	/**
32
	 * A custom Html element that will be inserted into the additional scripts into your &lt;head&gt; tag.
33
	 * The content of this file is displayed BELOW JS and CSS inclusion.
34
	 *
35
	 * @var HtmlElementInterface
36
	 */
37
	protected $additionalElement;
38
	
39
	/**
40
	 * 
41
	 * @param HtmlElementInterface $jsElement A custom Html element that will be inserted into the JS scripts into your &lt;head&gt; tag.
42
	 * @param HtmlElementInterface $cssElement A custom CSS element that will be inserted into the JS scripts into your &lt;head&gt; tag.
43
	 * @param HtmlElementInterface $additionalElement A custom Html element that will be inserted into the additional scripts into your &lt;head&gt; tag. The content of this file is displayed BELOW JS and CSS inclusion.
44
	 */
45
	public function __construct(HtmlElementInterface $jsElement = null,
46
			HtmlElementInterface $cssElement = null,
47
			HtmlElementInterface $additionalElement = null) {
48
		$this->jsElement = $jsElement;
49
		$this->cssElement = $cssElement;
50
		$this->additionalElement = $additionalElement;
51
	}
52
	
53
	
54
	
55
	/**
56
	 * A custom Html element that will be inserted into the JS scripts into your &lt;head&gt; tag.
57
	 *
58
	 * @param HtmlElementInterface $jsElement
59
	 */
60
	public function setJsElement(HtmlElementInterface $jsElement) {
61
		$this->jsElement = $jsElement;
62
		return $this;
63
	}
64
	
65
	/**
66
	 * A custom CSS element that will be inserted into the JS scripts into your &lt;head&gt; tag.
67
	 * @param HtmlElementInterface $cssElement
68
	 */
69
	public function setCssElement(HtmlElementInterface $cssElement) {
70
		$this->cssElement = $cssElement;
71
		return $this;
72
	}
73
	
74
	/**
75
	 * A custom Html element that will be inserted into the additional scripts into your &lt;head&gt; tag.
76
	 * The content of this file is displayed BELOW JS and CSS inclusion.
77
	 *
78
	 * @param HtmlElementInterface $additionalElement
79
	 */
80
	public function setAdditionalElement(HtmlElementInterface $additionalElement) {
81
		$this->additionalElement = $additionalElement;
82
		return $this;
83
	}
84
	
85
    /**
86
     * Returns an array of Javascript files to be included for this library.
87
     *
88
     * @return array<string>
89
     */
90
    public function getJsFiles() {
91
    	return array();
92
    }
93
    
94
    /**
95
     * Returns an array of CSS files to be included for this library.
96
     *
97
     * @return array<string>
98
     */
99
    public function getCssFiles() {
100
    	return array();
101
    }
102
    
103
    /**
104
     * Returns a list of libraries that must be included before this library is included.
105
     *
106
     * @return array<WebLibraryInterface>
107
     */
108
    public function getDependencies() {
109
    	return array();
110
    }
111
    
112
    /**
113
     * Returns a list of features provided by this library.
114
     * A feature is typically a string describing what the file contains.
115
     *
116
     * For instance, an object representing the JQuery library would provide the "jquery" feature.
117
     *
118
     * @return array<string>
119
     */
120
    public function getFeatures() {
121
    	return array();
122
    }
123
    
124
    /**
125
     * Sets the script outputed in the JS section
126
     * @param string $script
127
     */
128
    function setJSFromText($script){
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...
129
    	$this->jsElement = new HtmlString($script);
130
    }
131
    
132
    
133
    /**
134
     * Sets the script outputed in the JS section
135
     * 
136
     * @param string $filename
137
     * @param Scopable $scope
138
     * @param bool $relativeToRootPath
139
     */
140
    function setJSFromFile($filename, $scope = null, $relativeToRootPath = true){
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...
141
    	$this->jsElement = new HtmlFromFile($filename, $scope, $relativeToRootPath);
142
    }
143
    
144
    /**
145
     * Sets the css outputed in the CSS section
146
     * @param string $css
147
     */
148
    function setCSSFromText($css){
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...
149
    	$this->cssElement = new HtmlString($css);
150
    }
151
    
152
    /**
153
     * Sets the script outputed in the CSS section
154
     * 
155
     * @param string $filename
156
     * @param Scopable $scope
157
     * @param bool $relativeToRootPath
158
     */
159
    function setCSSFromFile($filename, $scope = null, $relativeToRootPath = true){
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...
160
    	$this->cssElement = new HtmlFromFile($filename, $scope, $relativeToRootPath);
161
    }
162
    
163
    /**
164
     * Sets the additional items outputed below the JS and CSS sections
165
     * @param string $script
166
     */
167
    function setAdditionalElementFromText($script){
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...
168
    	$this->additionalElement = new HtmlString($script);
169
    }
170
    
171
    /**
172
     * Sets the additional items outputed below the JS and CSS sections
173
     *
174
     * @param string $filename
175
     * @param Scopable $scope
176
     * @param bool $relativeToRootPath
177
     */
178
    function setAdditionalElementFromFile($filename, $scope = null, $relativeToRootPath = true){
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...
179
    	$this->additionalElement = new HtmlFromFile($filename, $scope, $relativeToRootPath);
180
    }
181
	
182
	/**
183
	 * A custom Html element that will be inserted into the JS scripts into your &lt;head&gt; tag.
184
	 * @return the HtmlElementInterface
185
	 */
186
	public function getJsElement() {
187
		return $this->jsElement;
188
	}
189
	
190
	/**
191
	 * A custom CSS element that will be inserted into the JS scripts into your &lt;head&gt; tag.
192
	 * @return the HtmlElementInterface
193
	 */
194
	public function getCssElement() {
195
		return $this->cssElement;
196
	}
197
	
198
	/**
199
	 * A custom Html element that will be inserted into the additional scripts into your &lt;head&gt; tag.
200
	 * The content of this file is displayed BELOW JS and CSS inclusion.
201
	 * @return the HtmlElementInterface
202
	 */
203
	public function getAdditionalElement() {
204
		return $this->additionalElement;
205
	}
206
	
207
}
208