Passed
Push — master ( dc3967...a95317 )
by Paul
07:16
created

Form::getSettingsFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html;
4
5
use GeminiLabs\SiteReviews\Application;
6
use GeminiLabs\SiteReviews\Database\DefaultsManager;
7
use GeminiLabs\SiteReviews\Helper;
8
use GeminiLabs\SiteReviews\Modules\Html\Builder;
9
10
class Form
11
{
12
	/**
13
	 * @param string $path
14
	 * @return string
15
	 */
16
	public function build( $path, array $fields = [] )
17
	{
18
		if( empty( $fields )) {
19
			$fields = $this->getSettingsFields( $this->normalizeSettingsPath( $path ));
20
		}
21
		foreach( $fields as $name => &$field ) {
22
			$field = wp_parse_args( $field, ['name' => $name] );
23
			// new Field( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
		}
25
		// 1. generate fields (incl default form fields)
26
		// 2. generate form
27
		glsr_debug( $path, $fields );
28
	}
29
30
	/**
31
	 * @return array
32
	 */
33
	protected function getSettingsFields( $path )
34
	{
35
		$settings = glsr( DefaultsManager::class )->settings();
36
		return array_filter( $settings, function( $key ) use( $path ) {
37
			return glsr( Helper::class )->startsWith( $path, $key );
38
		}, ARRAY_FILTER_USE_KEY );
39
	}
40
41
	/**
42
	 * @return string
43
	 */
44
	protected function normalizeSettingsPath( $path )
45
	{
46
		return glsr( Helper::class )->prefixString( rtrim( $path, '.' ), 'settings.' );
47
	}
48
}
49