Passed
Push — master ( d8e403...d1c323 )
by Paul
05:05
created

Form::getTemplateContextForTranslations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Html;
4
5
use GeminiLabs\SiteReviews\Helper;
6
use GeminiLabs\SiteReviews\Modules\Html\Field;
7
use GeminiLabs\SiteReviews\Modules\Html\Template;
8
use GeminiLabs\SiteReviews\Modules\Session;
9
10
class Form
11
{
12
	/**
13
	 * @param string $id
14
	 * @return array
15
	 */
16
	public function buildFields( $id )
17
	{
18
		return array_reduce( $this->getFields( $id ), function( $carry, $field ) {
19
			return $carry.$field;
20
		});
21
	}
22
23
	/**
24
	 * @param string $id
25
	 * @return array
26
	 */
27
	public function getFields( $id )
28
	{
29
		$fields = [];
30
		$configPath = glsr()->path( 'config/'.$id.'.php' );;
31
		$values = file_exists( $configPath )
32
			? include $configPath
33
			: [];
34
		$values = apply_filters( 'site-reviews/form/fields', $values );
35
		foreach( $values as $name => $field ) {
36
			$fields[] = new Field( wp_parse_args( $field, ['name' => $name] ));
37
		}
38
		return $fields;
39
	}
40
41
	/**
42
	 * @param string $id
43
	 * @return void
44
	 */
45
	public function renderFields( $id )
46
	{
47
		echo $this->buildFields( $id );
0 ignored issues
show
Bug introduced by
Are you sure $this->buildFields($id) of type array can be used in echo? ( Ignorable by Annotation )

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

47
		echo /** @scrutinizer ignore-type */ $this->buildFields( $id );
Loading history...
48
	}
49
}
50