Passed
Push — master ( a4754c...e0c6ec )
by Nazar
05:32
created

form()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
ccs 0
cts 31
cp 0
crap 2
1
<?php
2
/**
3
 * @package    CleverStyle Framework
4
 * @subpackage Builder
5
 * @author     Nazar Mokrynskyi <[email protected]>
6
 * @copyright  Copyright (c) 2016-2017, Nazar Mokrynskyi
7
 * @license    MIT License, see license.txt
8
 */
9
/**
10
 * @return string
11
 */
12
function form () {
13
	return h::{'form[method=post]'}(
14
		h::nav(
0 ignored issues
show
Bug introduced by
The method nav() does not exist on h. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
		h::/** @scrutinizer ignore-call */ 
15
     nav(
Loading history...
15
			'Build: '.
16
			h::{'radio[name=mode]'}(
17
				[
18
					'value' => ['core', 'module', 'theme'],
19
					'in'    => ['Core', 'Module', 'Theme']
20
				]
21
			)
22
		).
23
		h::{'table tr| td'}(
24
			[
25
				'Modules',
26
				'Themes'
27
			],
28
			[
29
				h::{'select[name=modules[]][size=20][multiple] option'}(
30
					get_list_for_form(DIR.'/modules', 'System')
31
				),
32
				h::{'select[name=themes[]][size=20][multiple] option'}(
33
					get_list_for_form(DIR.'/themes', 'CleverStyle')
34
				)
35
			]
36
		).
37
		h::{'input[name=suffix]'}(
38
			[
39
				'placeholder' => 'Package file suffix'
40
			]
41
		).
42
		h::{'button[type=submit]'}(
43
			'Build'
44
		)
45
	);
46
}
47
48
/**
49
 * @param string $dir
50
 * @param string $exclude_component
51
 *
52
 * @return array[]
53
 */
54
function get_list_for_form ($dir, $exclude_component = '') {
55
	$components = [];
56
	foreach (array_map('basename', glob("$dir/*", GLOB_ONLYDIR)) as $component) {
57
		if ($component != $exclude_component) {
58
			$components[] = [
59
				$component,
60
				file_exists("$dir/$component/meta.json") ? [
61
					'title' => 'Version: '.file_get_json("$dir/$component/meta.json")['version']
62
				] : [
63
					'title' => 'No meta.json file found',
64
					'disabled'
65
				]
66
			];
67
		}
68
	}
69
	return $components;
70
}
71