Passed
Push — release-3.2.0 ( 24bcfb...4d8cca )
by Daniel
04:25
created

cfg_utils::ensure_array()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2019 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\blocks\config;
11
12
class cfg_utils
13
{
14
	/**
15
	 * Force array
16
	 *
17
	 * @param mixed $items
18
	 * @return array
19
	 */
20
	public static function ensure_array($items)
21
	{
22
		return is_array($items) ? $items : explode(',', $items);
23
	}
24
25
	/**
26
	 * Force multi dimensional array
27
	 *
28
	 * @param mixed $options
29
	 * @param string $css_class
30
	 * @return array
31
	 */
32
	public static function ensure_multi_array($options, &$css_class)
33
	{
34
		$test = current(cfg_utils::ensure_array($options));
35
		if (!is_array($test))
36
		{
37
			$css_class = '';
38
			$options = array($options);
39
		}
40
41
		return array_map('array_filter', $options);
42
	}
43
44
	/**
45
	 * @param string $needle
46
	 * @param array $haystack
47
	 * @param string $type selected|checked
48
	 * @return string
49
	 */
50
	public static function get_selected_option($needle, array $haystack, $type = 'selected')
51
	{
52
		return (in_array($needle, $haystack)) ? ' ' . $type . '="' . $type . '"' : '';
53
	}
54
}
55