Completed
Branch master (7c0038)
by
unknown
02:35
created

Tag::categoryRaw()   A

↳ Parent: Tag

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
namespace Redaxscript\Template;
3
4
use Redaxscript\Db;
5
use Redaxscript\Config;
6
use Redaxscript\Console;
7
use Redaxscript\Breadcrumb;
8
use Redaxscript\Head;
9
use Redaxscript\Registry;
10
use Redaxscript\Request;
11
use Redaxscript\Language;
12
use Redaxscript\View;
13
14
/**
15
 * parent class to provide template tags
16
 *
17
 * @since 3.0.0
18
 *
19
 * @package Redaxscript
20
 * @category Template
21
 * @author Henry Ruhs
22
 */
23
24
class Tag
25
{
26
	/**
27
	 * base
28
	 *
29
	 * @since 3.0.0
30
	 *
31
	 * @return string
32
	 */
33
34 1
	public static function base()
35
	{
36 1
		$base = new Head\Base(Registry::getInstance());
37 1
		return $base->render();
38
	}
39
40
	/**
41
	 * title
42
	 *
43
	 * @since 3.0.0
44
	 *
45
	 * @return string
46
	 */
47
48 1
	public static function title()
49
	{
50 1
		$title = new Head\Title(Registry::getInstance());
51 1
		return $title->render();
52
	}
53
54
	/**
55
	 * link
56
	 *
57
	 * @since 3.0.0
58
	 *
59
	 * @return object
60
	 */
61
62 1
	public static function link()
63
	{
64 1
		return Head\Link::getInstance();
65 1
	}
66
67
	/**
68
	 * meta
69
	 *
70
	 * @since 3.0.0
71
	 *
72
	 * @return object
73
	 */
74
75 1
	public static function meta()
76
	{
77 1
		return Head\Meta::getInstance();
78
	}
79
80
	/**
81
	 * script
82
	 *
83
	 * @since 3.0.0
84
	 *
85
	 * @return mixed
86
	 */
87
88 1
	public static function script()
89
	{
90 1
		return Head\Script::getInstance();
91
	}
92
93
	/**
94
	 * style
95
	 *
96
	 * @since 3.0.0
97
	 *
98
	 * @return object
99
	 */
100
101 2
	public static function style()
102
	{
103 1
		return Head\Style::getInstance();
104 2
	}
105
106
	/**
107
	 * breadcrumb
108
	 *
109
	 * @since 2.3.0
110
	 *
111
	 * @return string
112
	 */
113
114 2
	public static function breadcrumb()
115
	{
116 2
		$breadcrumb = new Breadcrumb(Registry::getInstance(), Language::getInstance());
117 2
		$breadcrumb->init();
118 2
		return $breadcrumb->render();
119
	}
120
121
	/**
122
	 * console line
123
	 *
124
	 * @since 3.0.0
125
	 *
126
	 * @return string
127
	 */
128
129 2
	public static function consoleLine()
130
	{
131 2
		$console = new Console\Console(Registry::getInstance(), Request::getInstance(), Config::getInstance());
132 2
		$output = $console->init('template');
133 2
		if (is_string($output))
134 2
		{
135 1
			return htmlentities($output);
136
		}
137 1
	}
138
139
	/**
140
	 * console form
141
	 *
142
	 * @since 3.0.0
143
	 *
144
	 * @return string
145
	 */
146
147 1
	public static function consoleForm()
148
	{
149 1
		$consoleForm = new View\ConsoleForm(Registry::getInstance(), Language::getInstance());
150 1
		return $consoleForm->render();
151
	}
152
153
	/**
154
	 * search form
155
	 *
156
	 * @since 3.0.0
157
	 *
158
	 * @param string $table
159
	 *
160
	 * @return string
161
	 */
162
163 1
	public static function searchForm($table = null)
164
	{
165 1
		$searchForm = new View\SearchForm(Registry::getInstance(), Language::getInstance());
166 1
		return $searchForm->render($table);
167
	}
168
169
	/**
170
	 * partial
171
	 *
172
	 * @since 2.3.0
173
	 *
174
	 * @param mixed $file
175
	 *
176
	 * @return string
177
	 */
178
179 4
	public static function partial($file = null)
180
	{
181
		/* handle file */
182
183 3
		if (is_string($file))
184 3
		{
185
			$file =
186
			[
187
				$file
188 3
			];
189 3
		}
190
191
		/* include files */
192
193 3
		ob_start();
194 4
		foreach ($file as $value)
0 ignored issues
show
Bug introduced by redaxmedia
The expression $file of type object|integer|double|null|array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
195
		{
196 3
			if (file_exists($value))
197 3
			{
198 3
				include($value);
199 3
			}
200 3
		}
201 3
		return ob_get_clean();
202
	}
203
204
	/**
205
	 * registry
206
	 *
207
	 * @since 2.6.0
208
	 *
209
	 * @param string $key
210
	 *
211
	 * @return string
212
	 */
213
214 3
	public static function registry($key = null)
215
	{
216 3
		$registry = Registry::getInstance();
217 3
		return $registry->get($key);
218
	}
219
220
	/**
221
	 * language
222
	 *
223
	 * @since 2.6.0
224
	 *
225
	 * @param string $key
226
	 * @param string $index
227
	 *
228
	 * @return string
229
	 */
230
231 1
	public static function language($key = null, $index = null)
232
	{
233 1
		$language = Language::getInstance();
234 1
		return $language->get($key, $index);
235
	}
236
237
	/**
238
	 * setting
239
	 *
240
	 * @since 2.6.0
241
	 *
242
	 * @param string $key
243
	 *
244
	 * @return string
245
	 */
246
247 2
	public static function setting($key = null)
248
	{
249 2
		return Db::getSetting($key);
250
	}
251
252
	/**
253
	 * content
254
	 *
255
	 * @since 2.3.0
256
	 *
257
	 * @return string
258
	 */
259
260
	public static function content()
261
	{
262
		// @codeCoverageIgnoreStart
263
		return self::_migrate('router');
264
		// @codeCoverageIgnoreEnd
265
	}
266
267
	/**
268
	 * extra
269
	 *
270
	 * @since 2.3.0
271
	 *
272
	 * @return string
273
	 */
274
275
	public static function extra()
276
	{
277
		// @codeCoverageIgnoreStart
278
		return self::_migrate('extras');
279
		// @codeCoverageIgnoreEnd
280
	}
281
282
	/**
283
	 * categoryRaw
284
	 *
285
	 * @since 3.0.0
286
	 *
287
	 * @return Db
288
	 */
289
290
	public static function categoryRaw()
291
	{
292
		return Db::forTablePrefix('categories');
293
	}
294
295
	/**
296
	 * articleRaw
297
	 *
298
	 * @since 3.0.0
299
	 *
300
	 * @return Db
301
	 */
302
303
	public static function articleRaw()
304
	{
305
		return Db::forTablePrefix('articles');
306
	}
307
308
	/**
309
	 * extraRaw
310
	 *
311
	 * @since 3.0.0
312
	 *
313
	 * @return Db
314
	 */
315
316
	public static function extraRaw()
317
	{
318
		return Db::forTablePrefix('extras');
319
	}
320
321
	/**
322
	 * navigation
323
	 *
324
	 * @since 3.0.0
325
	 *
326
	 * @param string $type
327
	 * @param array $optionArray
328
	 *
329
	 * @return string
330
	 */
331
332
	public static function navigation($type = null, $optionArray = [])
333
	{
334
		// @codeCoverageIgnoreStart
335
		if ($type === 'languages' || $type === 'templates')
336
		{
337
			return self::_migrate($type . '_list',
338
			[
339
				$optionArray
340
			]);
341
		}
342
		return self::_migrate('navigation_list',
343
		[
344
			$type,
345
			$optionArray
346
		]);
347
		// @codeCoverageIgnoreEnd
348
	}
349
350
	/**
351
	 * migrate
352
	 *
353
	 * @since 2.3.0
354
	 *
355
	 * @param string $function
356
	 * @param array $parameterArray
357
	 *
358
	 * @return string
359
	 */
360
361
	protected static function _migrate($function = null, $parameterArray = [])
362
	{
363
		// @codeCoverageIgnoreStart
364
		ob_start();
365
366
		/* call with parameter */
367
368
		if (is_array($parameterArray))
369
		{
370
			call_user_func_array($function, $parameterArray);
371
		}
372
373
		/* else simple call */
374
375
		else
376
		{
377
			call_user_func($function);
378
		}
379
		return ob_get_clean();
380
		// @codeCoverageIgnoreEnd
381
	}
382
}
383