Passed
Push — master ( 925e6d...054ae2 )
by Paul
08:03 queued 03:39
created
plugin/Defaults/EmailDefaults.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
 
8 8
 class EmailDefaults extends Defaults
9 9
 {
10
-    /**
11
-     * @return array
12
-     */
13
-    protected function defaults()
14
-    {
15
-        return [
16
-            'after' => '',
17
-            'attachments' => [],
18
-            'bcc' => '',
19
-            'before' => '',
20
-            'cc' => '',
21
-            'from' => $this->getFromName().' <'.$this->getFromEmail().'>',
22
-            'message' => '',
23
-            'reply-to' => '',
24
-            'subject' => '',
25
-            'template' => '',
26
-            'template-tags' => [],
27
-            'to' => '',
28
-        ];
29
-    }
10
+	/**
11
+	 * @return array
12
+	 */
13
+	protected function defaults()
14
+	{
15
+		return [
16
+			'after' => '',
17
+			'attachments' => [],
18
+			'bcc' => '',
19
+			'before' => '',
20
+			'cc' => '',
21
+			'from' => $this->getFromName().' <'.$this->getFromEmail().'>',
22
+			'message' => '',
23
+			'reply-to' => '',
24
+			'subject' => '',
25
+			'template' => '',
26
+			'template-tags' => [],
27
+			'to' => '',
28
+		];
29
+	}
30 30
 
31
-    /**
32
-     * @return string
33
-     */
34
-    protected function getFromEmail()
35
-    {
36
-        return glsr(OptionManager::class)->getWP('admin_email');
37
-    }
31
+	/**
32
+	 * @return string
33
+	 */
34
+	protected function getFromEmail()
35
+	{
36
+		return glsr(OptionManager::class)->getWP('admin_email');
37
+	}
38 38
 
39
-    /**
40
-     * @return string
41
-     */
42
-    protected function getFromName()
43
-    {
44
-        return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES);
45
-    }
39
+	/**
40
+	 * @return string
41
+	 */
42
+	protected function getFromName()
43
+	{
44
+		return wp_specialchars_decode(glsr(OptionManager::class)->getWP('blogname'), ENT_QUOTES);
45
+	}
46 46
 }
Please login to merge, or discard this patch.
site-reviews.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,11 +18,11 @@
 block discarded – undo
18 18
 defined('WPINC') || die;
19 19
 
20 20
 if (!class_exists('GL_Plugin_Check_v3')) {
21
-    require_once __DIR__.'/activate.php';
21
+	require_once __DIR__.'/activate.php';
22 22
 }
23 23
 $check = new GL_Plugin_Check_v3(__FILE__);
24 24
 if (!$check->canProceed()) {
25
-    return;
25
+	return;
26 26
 }
27 27
 require_once __DIR__.'/autoload.php';
28 28
 require_once __DIR__.'/compatibility.php';
Please login to merge, or discard this patch.
plugin/Modules/Notice.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -8,112 +8,112 @@
 block discarded – undo
8 8
 
9 9
 class Notice
10 10
 {
11
-    /**
12
-     * @param string $type
13
-     * @param string|array|WP_Error $message
14
-     * @return void
15
-     */
16
-    public function add($type, $message, array $args = [])
17
-    {
18
-        if (empty(array_filter([$message, $type]))) {
19
-            return;
20
-        }
21
-        $args['message'] = $message;
22
-        $args['type'] = $type;
23
-        add_settings_error(Application::ID, '', json_encode($this->normalize($args)));
24
-    }
11
+	/**
12
+	 * @param string $type
13
+	 * @param string|array|WP_Error $message
14
+	 * @return void
15
+	 */
16
+	public function add($type, $message, array $args = [])
17
+	{
18
+		if (empty(array_filter([$message, $type]))) {
19
+			return;
20
+		}
21
+		$args['message'] = $message;
22
+		$args['type'] = $type;
23
+		add_settings_error(Application::ID, '', json_encode($this->normalize($args)));
24
+	}
25 25
 
26
-    /**
27
-     * @param string|array|WP_Error $message
28
-     * @return void
29
-     */
30
-    public function addError($message, array $args = [])
31
-    {
32
-        $this->add('error', $message, $args);
33
-    }
26
+	/**
27
+	 * @param string|array|WP_Error $message
28
+	 * @return void
29
+	 */
30
+	public function addError($message, array $args = [])
31
+	{
32
+		$this->add('error', $message, $args);
33
+	}
34 34
 
35
-    /**
36
-     * @param string|array|WP_Error $message
37
-     * @return void
38
-     */
39
-    public function addSuccess($message, array $args = [])
40
-    {
41
-        $this->add('success', $message, $args);
42
-    }
35
+	/**
36
+	 * @param string|array|WP_Error $message
37
+	 * @return void
38
+	 */
39
+	public function addSuccess($message, array $args = [])
40
+	{
41
+		$this->add('success', $message, $args);
42
+	}
43 43
 
44
-    /**
45
-     * @param string|array|WP_Error $message
46
-     * @return void
47
-     */
48
-    public function addWarning($message, array $args = [])
49
-    {
50
-        $this->add('warning', $message, $args);
51
-    }
44
+	/**
45
+	 * @param string|array|WP_Error $message
46
+	 * @return void
47
+	 */
48
+	public function addWarning($message, array $args = [])
49
+	{
50
+		$this->add('warning', $message, $args);
51
+	}
52 52
 
53
-    /**
54
-     * @return static
55
-     */
56
-    public function clear()
57
-    {
58
-        global $wp_settings_errors;
59
-        $wp_settings_errors = [];
60
-        delete_transient('settings_errors');
61
-        return $this;
62
-    }
53
+	/**
54
+	 * @return static
55
+	 */
56
+	public function clear()
57
+	{
58
+		global $wp_settings_errors;
59
+		$wp_settings_errors = [];
60
+		delete_transient('settings_errors');
61
+		return $this;
62
+	}
63 63
 
64
-    /**
65
-     * @return string
66
-     */
67
-    public function get()
68
-    {
69
-        $notices = array_map('unserialize',
70
-            array_unique(array_map('serialize', get_settings_errors(Application::ID)))
71
-        );
72
-        $notices = array_reduce($notices, function ($carry, $notice) {
73
-            return $carry.$this->buildNotice(json_decode($notice['message'], true));
74
-        });
75
-        return apply_filters('site-reviews/notices', $notices);
76
-    }
64
+	/**
65
+	 * @return string
66
+	 */
67
+	public function get()
68
+	{
69
+		$notices = array_map('unserialize',
70
+			array_unique(array_map('serialize', get_settings_errors(Application::ID)))
71
+		);
72
+		$notices = array_reduce($notices, function ($carry, $notice) {
73
+			return $carry.$this->buildNotice(json_decode($notice['message'], true));
74
+		});
75
+		return apply_filters('site-reviews/notices', $notices);
76
+	}
77 77
 
78
-    /**
79
-     * @return string
80
-     */
81
-    protected function buildNotice(array $args)
82
-    {
83
-        $messages = array_reduce($args['messages'], function ($carry, $message) {
84
-            return $carry.glsr(Builder::class)->p($message);
85
-        });
86
-        $class = 'notice notice-'.$args['type'];
87
-        if ($args['inline']) {
88
-            $class.= ' inline';
89
-        }
90
-        if ($args['dismissible']) {
91
-            $class.= ' is-dismissible';
92
-        }
93
-        return glsr(Builder::class)->div($messages, [
94
-            'class' => $class,
95
-        ]);
96
-    }
78
+	/**
79
+	 * @return string
80
+	 */
81
+	protected function buildNotice(array $args)
82
+	{
83
+		$messages = array_reduce($args['messages'], function ($carry, $message) {
84
+			return $carry.glsr(Builder::class)->p($message);
85
+		});
86
+		$class = 'notice notice-'.$args['type'];
87
+		if ($args['inline']) {
88
+			$class.= ' inline';
89
+		}
90
+		if ($args['dismissible']) {
91
+			$class.= ' is-dismissible';
92
+		}
93
+		return glsr(Builder::class)->div($messages, [
94
+			'class' => $class,
95
+		]);
96
+	}
97 97
 
98
-    /**
99
-     * @return array
100
-     */
101
-    protected function normalize(array $args)
102
-    {
103
-        $defaults = [
104
-            'dismissible' => true,
105
-            'inline' => true,
106
-            'message' => '',
107
-            'type' => '',
108
-        ];
109
-        $args = shortcode_atts($defaults, $args);
110
-        if (!in_array($args['type'], ['error', 'warning', 'success'])) {
111
-            $args['type'] = 'success';
112
-        }
113
-        $args['messages'] = is_wp_error($args['message'])
114
-            ? (array) $args['message']->get_error_message()
115
-            : (array) $args['message'];
116
-        unset($args['message']);
117
-        return $args;
118
-    }
98
+	/**
99
+	 * @return array
100
+	 */
101
+	protected function normalize(array $args)
102
+	{
103
+		$defaults = [
104
+			'dismissible' => true,
105
+			'inline' => true,
106
+			'message' => '',
107
+			'type' => '',
108
+		];
109
+		$args = shortcode_atts($defaults, $args);
110
+		if (!in_array($args['type'], ['error', 'warning', 'success'])) {
111
+			$args['type'] = 'success';
112
+		}
113
+		$args['messages'] = is_wp_error($args['message'])
114
+			? (array) $args['message']->get_error_message()
115
+			: (array) $args['message'];
116
+		unset($args['message']);
117
+		return $args;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Fields/Password.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@
 block discarded – undo
4 4
 
5 5
 class Password extends Field
6 6
 {
7
-    /**
8
-     * @return array
9
-     */
10
-    public static function defaults()
11
-    {
12
-        return [
13
-            'class' => 'regular-text',
14
-        ];
15
-    }
7
+	/**
8
+	 * @return array
9
+	 */
10
+	public static function defaults()
11
+	{
12
+		return [
13
+			'class' => 'regular-text',
14
+		];
15
+	}
16 16
 }
Please login to merge, or discard this patch.
plugin/Reviews.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -9,65 +9,65 @@
 block discarded – undo
9 9
 
10 10
 class Reviews extends ArrayObject
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $args;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $args;
16 16
 
17
-    /**
18
-     * @var int
19
-     */
20
-    public $max_num_pages;
17
+	/**
18
+	 * @var int
19
+	 */
20
+	public $max_num_pages;
21 21
 
22
-    /**
23
-     * @var array
24
-     */
25
-    public $reviews;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	public $reviews;
26 26
 
27
-    public function __construct(array $reviews, $maxPageCount, array $args)
28
-    {
29
-        $this->args = $args;
30
-        $this->max_num_pages = $maxPageCount;
31
-        $this->reviews = $reviews;
32
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
33
-    }
27
+	public function __construct(array $reviews, $maxPageCount, array $args)
28
+	{
29
+		$this->args = $args;
30
+		$this->max_num_pages = $maxPageCount;
31
+		$this->reviews = $reviews;
32
+		parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
33
+	}
34 34
 
35
-    /**
36
-     * @return string
37
-     */
38
-    public function __toString()
39
-    {
40
-        return (string) $this->build();
41
-    }
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function __toString()
39
+	{
40
+		return (string) $this->build();
41
+	}
42 42
 
43
-    /**
44
-     * @return ReviewsHtml
45
-     */
46
-    public function build()
47
-    {
48
-        $args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
-        return glsr(SiteReviewsPartial::class)->build($args, $this);
50
-    }
43
+	/**
44
+	 * @return ReviewsHtml
45
+	 */
46
+	public function build()
47
+	{
48
+		$args = glsr(SiteReviewsDefaults::class)->merge($this->args);
49
+		return glsr(SiteReviewsPartial::class)->build($args, $this);
50
+	}
51 51
 
52
-    /**
53
-     * @param mixed $key
54
-     * @return mixed
55
-     */
56
-    public function offsetGet($key)
57
-    {
58
-        if (property_exists($this, $key)) {
59
-            return $this->$key;
60
-        }
61
-        return array_key_exists($key, $this->reviews)
62
-            ? $this->reviews[$key]
63
-            : null;
64
-    }
52
+	/**
53
+	 * @param mixed $key
54
+	 * @return mixed
55
+	 */
56
+	public function offsetGet($key)
57
+	{
58
+		if (property_exists($this, $key)) {
59
+			return $this->$key;
60
+		}
61
+		return array_key_exists($key, $this->reviews)
62
+			? $this->reviews[$key]
63
+			: null;
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function render()
70
-    {
71
-        echo $this->build();
72
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function render()
70
+	{
71
+		echo $this->build();
72
+	}
73 73
 }
Please login to merge, or discard this patch.
plugin/Widgets/Widget.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -7,54 +7,54 @@
 block discarded – undo
7 7
 
8 8
 abstract class Widget extends WP_Widget
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    protected $widgetArgs;
10
+	/**
11
+	 * @var array
12
+	 */
13
+	protected $widgetArgs;
14 14
 
15
-    public function __construct($idBase, $name, $values)
16
-    {
17
-        $controlOptions = $widgetOptions = [];
18
-        if (isset($values['class'])) {
19
-            $widgetOptions['classname'] = $values['class'];
20
-        }
21
-        if (isset($values['description'])) {
22
-            $widgetOptions['description'] = $values['description'];
23
-        }
24
-        if (isset($values['width'])) {
25
-            $controlOptions['width'] = $values['width'];
26
-        }
27
-        parent::__construct($idBase, $name, $widgetOptions, $controlOptions);
28
-    }
15
+	public function __construct($idBase, $name, $values)
16
+	{
17
+		$controlOptions = $widgetOptions = [];
18
+		if (isset($values['class'])) {
19
+			$widgetOptions['classname'] = $values['class'];
20
+		}
21
+		if (isset($values['description'])) {
22
+			$widgetOptions['description'] = $values['description'];
23
+		}
24
+		if (isset($values['width'])) {
25
+			$controlOptions['width'] = $values['width'];
26
+		}
27
+		parent::__construct($idBase, $name, $widgetOptions, $controlOptions);
28
+	}
29 29
 
30
-    /**
31
-     * @param string $tag
32
-     * @return void
33
-     */
34
-    protected function renderField($tag, array $args = [])
35
-    {
36
-        $args = $this->normalizeFieldAttributes($tag, $args);
37
-        $field = glsr(Builder::class)->$tag($args['name'], $args);
38
-        echo glsr(Builder::class)->div($field, [
39
-            'class' => 'glsr-field',
40
-        ]);
41
-    }
30
+	/**
31
+	 * @param string $tag
32
+	 * @return void
33
+	 */
34
+	protected function renderField($tag, array $args = [])
35
+	{
36
+		$args = $this->normalizeFieldAttributes($tag, $args);
37
+		$field = glsr(Builder::class)->$tag($args['name'], $args);
38
+		echo glsr(Builder::class)->div($field, [
39
+			'class' => 'glsr-field',
40
+		]);
41
+	}
42 42
 
43
-    /**
44
-     * @param string $tag
45
-     * @return array
46
-     */
47
-    protected function normalizeFieldAttributes($tag, array $args)
48
-    {
49
-        if (empty($args['value'])) {
50
-            $args['value'] = $this->widgetArgs[$args['name']];
51
-        }
52
-        if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) {
53
-            $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]);
54
-        }
55
-        $args['id'] = $this->get_field_id($args['name']);
56
-        $args['name'] = $this->get_field_name($args['name']);
57
-        $args['is_widget'] = true;
58
-        return $args;
59
-    }
43
+	/**
44
+	 * @param string $tag
45
+	 * @return array
46
+	 */
47
+	protected function normalizeFieldAttributes($tag, array $args)
48
+	{
49
+		if (empty($args['value'])) {
50
+			$args['value'] = $this->widgetArgs[$args['name']];
51
+		}
52
+		if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) {
53
+			$args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]);
54
+		}
55
+		$args['id'] = $this->get_field_id($args['name']);
56
+		$args['name'] = $this->get_field_name($args['name']);
57
+		$args['is_widget'] = true;
58
+		return $args;
59
+	}
60 60
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/ReviewHtml.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -7,48 +7,48 @@
 block discarded – undo
7 7
 
8 8
 class ReviewHtml extends ArrayObject
9 9
 {
10
-    /**
11
-     * @var Review
12
-     */
13
-    public $review;
10
+	/**
11
+	 * @var Review
12
+	 */
13
+	public $review;
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    public $values;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	public $values;
19 19
 
20
-    public function __construct(Review $review, array $values = [])
21
-    {
22
-        $this->review = $review;
23
-        $this->values = $values;
24
-        parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
25
-    }
20
+	public function __construct(Review $review, array $values = [])
21
+	{
22
+		$this->review = $review;
23
+		$this->values = $values;
24
+		parent::__construct($values, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
25
+	}
26 26
 
27
-    /**
28
-     * @return string|void
29
-     */
30
-    public function __toString()
31
-    {
32
-        if (empty($this->values)) {
33
-            return;
34
-        }
35
-        return glsr(Template::class)->build('templates/review', [
36
-            'context' => $this->values,
37
-            'review' => $this->review,
38
-        ]);
39
-    }
27
+	/**
28
+	 * @return string|void
29
+	 */
30
+	public function __toString()
31
+	{
32
+		if (empty($this->values)) {
33
+			return;
34
+		}
35
+		return glsr(Template::class)->build('templates/review', [
36
+			'context' => $this->values,
37
+			'review' => $this->review,
38
+		]);
39
+	}
40 40
 
41
-    /**
42
-     * @param mixed $key
43
-     * @return mixed
44
-     */
45
-    public function offsetGet($key)
46
-    {
47
-        if (property_exists($this, $key)) {
48
-            return $this->$key;
49
-        }
50
-        return array_key_exists($key, $this->values)
51
-            ? $this->values[$key]
52
-            : null;
53
-    }
41
+	/**
42
+	 * @param mixed $key
43
+	 * @return mixed
44
+	 */
45
+	public function offsetGet($key)
46
+	{
47
+		if (property_exists($this, $key)) {
48
+			return $this->$key;
49
+		}
50
+		return array_key_exists($key, $this->values)
51
+			? $this->values[$key]
52
+			: null;
53
+	}
54 54
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/Shortcode.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -11,223 +11,223 @@
 block discarded – undo
11 11
 
12 12
 abstract class Shortcode implements ShortcodeContract
13 13
 {
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $partialName;
18
-
19
-    /**
20
-     * @var string
21
-     */
22
-    protected $shortcodeName;
23
-
24
-    /**
25
-     * @param string|array $atts
26
-     * @param string $type
27
-     * @return string
28
-     */
29
-    public function build($atts, array $args = [], $type = 'shortcode')
30
-    {
31
-        $this->partialName = $this->getShortcodePartialName();
32
-        $this->shortcodeName = $this->getShortcodeName();
33
-        $args = $this->normalizeArgs($args, $type);
34
-        $atts = $this->normalizeAtts($atts, $type);
35
-        $partial = glsr(Partial::class)->build($this->partialName, $atts);
36
-        $title = !empty($atts['title'])
37
-            ? $args['before_title'].$atts['title'].$args['after_title']
38
-            : '';
39
-        $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
40
-        return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
41
-    }
42
-
43
-    /**
44
-     * @param string|array $atts
45
-     * @return string
46
-     */
47
-    public function buildShortcode($atts = [])
48
-    {
49
-        return $this->build($atts);
50
-    }
51
-
52
-    /**
53
-     * @return array
54
-     */
55
-    public function getDefaults($atts)
56
-    {
57
-        return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
58
-    }
59
-
60
-    /**
61
-     * @return array
62
-     */
63
-    public function getHideOptions()
64
-    {
65
-        $options = $this->hideOptions();
66
-        return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
67
-    }
68
-
69
-    /**
70
-     * @return string
71
-     */
72
-    public function getShortcodeClassName($replace = '', $search = 'Shortcode')
73
-    {
74
-        return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
75
-    }
76
-
77
-    /**
78
-     * @return string
79
-     */
80
-    public function getShortcodeDefaultsClassName()
81
-    {
82
-        return Helper::buildClassName(
83
-            $this->getShortcodeClassName('Defaults'),
84
-            'Defaults'
85
-        );
86
-    }
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function getShortcodeName()
92
-    {
93
-        return Str::snakeCase($this->getShortcodeClassName());
94
-    }
95
-
96
-    /**
97
-     * @return string
98
-     */
99
-    public function getShortcodePartialName()
100
-    {
101
-        return Str::dashCase($this->getShortcodeClassName());
102
-    }
103
-
104
-    /**
105
-     * @param array|string $args
106
-     * @param string $type
107
-     * @return array
108
-     */
109
-    public function normalizeArgs($args, $type = 'shortcode')
110
-    {
111
-        $args = wp_parse_args($args, [
112
-            'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
113
-            'after_widget' => '</div>',
114
-            'before_title' => '<h3 class="glsr-'.$type.'-title">',
115
-            'after_title' => '</h3>',
116
-        ]);
117
-        return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
118
-    }
119
-
120
-    /**
121
-     * @param array|string $atts
122
-     * @param string $type
123
-     * @return array
124
-     */
125
-    public function normalizeAtts($atts, $type = 'shortcode')
126
-    {
127
-        $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
128
-        $atts = $this->getDefaults($atts);
129
-        array_walk($atts, function (&$value, $key) {
130
-            $methodName = Helper::buildMethodName($key, 'normalize');
131
-            if (!method_exists($this, $methodName)) {
132
-                return;
133
-            }
134
-            $value = $this->$methodName($value);
135
-        });
136
-        return $atts;
137
-    }
138
-
139
-    /**
140
-     * @return array
141
-     */
142
-    abstract protected function hideOptions();
143
-
144
-    /**
145
-     * @param string $postId
146
-     * @return int|string
147
-     */
148
-    protected function normalizeAssignedTo($postId)
149
-    {
150
-        if ('parent_id' == $postId) {
151
-            $postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
152
-        } elseif ('post_id' == $postId) {
153
-            $postId = intval(get_the_ID());
154
-        }
155
-        return $postId;
156
-    }
157
-
158
-    /**
159
-     * @param string $postId
160
-     * @return int|string
161
-     */
162
-    protected function normalizeAssignTo($postId)
163
-    {
164
-        return $this->normalizeAssignedTo($postId);
165
-    }
166
-
167
-    /**
168
-     * @param string|array $hide
169
-     * @return array
170
-     */
171
-    protected function normalizeHide($hide)
172
-    {
173
-        if (is_string($hide)) {
174
-            $hide = explode(',', $hide);
175
-        }
176
-        $hideKeys = array_keys($this->getHideOptions());
177
-        return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
178
-            return in_array($value, $hideKeys);
179
-        });
180
-    }
181
-
182
-    /**
183
-     * @param string $id
184
-     * @return string
185
-     */
186
-    protected function normalizeId($id)
187
-    {
188
-        return sanitize_title($id);
189
-    }
190
-
191
-    /**
192
-     * @param string $labels
193
-     * @return array
194
-     */
195
-    protected function normalizeLabels($labels)
196
-    {
197
-        $defaults = [
198
-            __('Excellent', 'site-reviews'),
199
-            __('Very good', 'site-reviews'),
200
-            __('Average', 'site-reviews'),
201
-            __('Poor', 'site-reviews'),
202
-            __('Terrible', 'site-reviews'),
203
-        ];
204
-        $maxRating = glsr()->constant('MAX_RATING', Rating::class);
205
-        $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
206
-        $labels = array_map('trim', explode(',', $labels));
207
-        foreach ($defaults as $i => $label) {
208
-            if (empty($labels[$i])) {
209
-                continue;
210
-            }
211
-            $defaults[$i] = $labels[$i];
212
-        }
213
-        return array_combine(range($maxRating, 1), $defaults);
214
-    }
215
-
216
-    /**
217
-     * @param string $schema
218
-     * @return bool
219
-     */
220
-    protected function normalizeSchema($schema)
221
-    {
222
-        return wp_validate_boolean($schema);
223
-    }
224
-
225
-    /**
226
-     * @param string $text
227
-     * @return string
228
-     */
229
-    protected function normalizeText($text)
230
-    {
231
-        return trim($text);
232
-    }
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $partialName;
18
+
19
+	/**
20
+	 * @var string
21
+	 */
22
+	protected $shortcodeName;
23
+
24
+	/**
25
+	 * @param string|array $atts
26
+	 * @param string $type
27
+	 * @return string
28
+	 */
29
+	public function build($atts, array $args = [], $type = 'shortcode')
30
+	{
31
+		$this->partialName = $this->getShortcodePartialName();
32
+		$this->shortcodeName = $this->getShortcodeName();
33
+		$args = $this->normalizeArgs($args, $type);
34
+		$atts = $this->normalizeAtts($atts, $type);
35
+		$partial = glsr(Partial::class)->build($this->partialName, $atts);
36
+		$title = !empty($atts['title'])
37
+			? $args['before_title'].$atts['title'].$args['after_title']
38
+			: '';
39
+		$debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
40
+		return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
41
+	}
42
+
43
+	/**
44
+	 * @param string|array $atts
45
+	 * @return string
46
+	 */
47
+	public function buildShortcode($atts = [])
48
+	{
49
+		return $this->build($atts);
50
+	}
51
+
52
+	/**
53
+	 * @return array
54
+	 */
55
+	public function getDefaults($atts)
56
+	{
57
+		return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
58
+	}
59
+
60
+	/**
61
+	 * @return array
62
+	 */
63
+	public function getHideOptions()
64
+	{
65
+		$options = $this->hideOptions();
66
+		return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
67
+	}
68
+
69
+	/**
70
+	 * @return string
71
+	 */
72
+	public function getShortcodeClassName($replace = '', $search = 'Shortcode')
73
+	{
74
+		return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
75
+	}
76
+
77
+	/**
78
+	 * @return string
79
+	 */
80
+	public function getShortcodeDefaultsClassName()
81
+	{
82
+		return Helper::buildClassName(
83
+			$this->getShortcodeClassName('Defaults'),
84
+			'Defaults'
85
+		);
86
+	}
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function getShortcodeName()
92
+	{
93
+		return Str::snakeCase($this->getShortcodeClassName());
94
+	}
95
+
96
+	/**
97
+	 * @return string
98
+	 */
99
+	public function getShortcodePartialName()
100
+	{
101
+		return Str::dashCase($this->getShortcodeClassName());
102
+	}
103
+
104
+	/**
105
+	 * @param array|string $args
106
+	 * @param string $type
107
+	 * @return array
108
+	 */
109
+	public function normalizeArgs($args, $type = 'shortcode')
110
+	{
111
+		$args = wp_parse_args($args, [
112
+			'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
113
+			'after_widget' => '</div>',
114
+			'before_title' => '<h3 class="glsr-'.$type.'-title">',
115
+			'after_title' => '</h3>',
116
+		]);
117
+		return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
118
+	}
119
+
120
+	/**
121
+	 * @param array|string $atts
122
+	 * @param string $type
123
+	 * @return array
124
+	 */
125
+	public function normalizeAtts($atts, $type = 'shortcode')
126
+	{
127
+		$atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
128
+		$atts = $this->getDefaults($atts);
129
+		array_walk($atts, function (&$value, $key) {
130
+			$methodName = Helper::buildMethodName($key, 'normalize');
131
+			if (!method_exists($this, $methodName)) {
132
+				return;
133
+			}
134
+			$value = $this->$methodName($value);
135
+		});
136
+		return $atts;
137
+	}
138
+
139
+	/**
140
+	 * @return array
141
+	 */
142
+	abstract protected function hideOptions();
143
+
144
+	/**
145
+	 * @param string $postId
146
+	 * @return int|string
147
+	 */
148
+	protected function normalizeAssignedTo($postId)
149
+	{
150
+		if ('parent_id' == $postId) {
151
+			$postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
152
+		} elseif ('post_id' == $postId) {
153
+			$postId = intval(get_the_ID());
154
+		}
155
+		return $postId;
156
+	}
157
+
158
+	/**
159
+	 * @param string $postId
160
+	 * @return int|string
161
+	 */
162
+	protected function normalizeAssignTo($postId)
163
+	{
164
+		return $this->normalizeAssignedTo($postId);
165
+	}
166
+
167
+	/**
168
+	 * @param string|array $hide
169
+	 * @return array
170
+	 */
171
+	protected function normalizeHide($hide)
172
+	{
173
+		if (is_string($hide)) {
174
+			$hide = explode(',', $hide);
175
+		}
176
+		$hideKeys = array_keys($this->getHideOptions());
177
+		return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
178
+			return in_array($value, $hideKeys);
179
+		});
180
+	}
181
+
182
+	/**
183
+	 * @param string $id
184
+	 * @return string
185
+	 */
186
+	protected function normalizeId($id)
187
+	{
188
+		return sanitize_title($id);
189
+	}
190
+
191
+	/**
192
+	 * @param string $labels
193
+	 * @return array
194
+	 */
195
+	protected function normalizeLabels($labels)
196
+	{
197
+		$defaults = [
198
+			__('Excellent', 'site-reviews'),
199
+			__('Very good', 'site-reviews'),
200
+			__('Average', 'site-reviews'),
201
+			__('Poor', 'site-reviews'),
202
+			__('Terrible', 'site-reviews'),
203
+		];
204
+		$maxRating = glsr()->constant('MAX_RATING', Rating::class);
205
+		$defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
206
+		$labels = array_map('trim', explode(',', $labels));
207
+		foreach ($defaults as $i => $label) {
208
+			if (empty($labels[$i])) {
209
+				continue;
210
+			}
211
+			$defaults[$i] = $labels[$i];
212
+		}
213
+		return array_combine(range($maxRating, 1), $defaults);
214
+	}
215
+
216
+	/**
217
+	 * @param string $schema
218
+	 * @return bool
219
+	 */
220
+	protected function normalizeSchema($schema)
221
+	{
222
+		return wp_validate_boolean($schema);
223
+	}
224
+
225
+	/**
226
+	 * @param string $text
227
+	 * @return string
228
+	 */
229
+	protected function normalizeText($text)
230
+	{
231
+		return trim($text);
232
+	}
233 233
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Builder.php 1 patch
Indentation   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -18,346 +18,346 @@
 block discarded – undo
18 18
  */
19 19
 class Builder
20 20
 {
21
-    const INPUT_TYPES = [
22
-        'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
23
-        'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
24
-        'url', 'week',
25
-    ];
26
-
27
-    const TAGS_FORM = [
28
-        'input', 'select', 'textarea',
29
-    ];
30
-
31
-    const TAGS_SINGLE = [
32
-        'img',
33
-    ];
34
-
35
-    const TAGS_STRUCTURE = [
36
-        'div', 'form', 'nav', 'ol', 'section', 'ul',
37
-    ];
38
-
39
-    const TAGS_TEXT = [
40
-        'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
41
-        'small', 'span',
42
-    ];
43
-
44
-    /**
45
-     * @var array
46
-     */
47
-    public $args = [];
48
-
49
-    /**
50
-     * @var bool
51
-     */
52
-    public $render = false;
53
-
54
-    /**
55
-     * @var string
56
-     */
57
-    public $tag;
58
-
59
-    /**
60
-     * @param string $method
61
-     * @param array $args
62
-     * @return string|void
63
-     */
64
-    public function __call($method, $args)
65
-    {
66
-        $instance = new static();
67
-        $instance->setTagFromMethod($method);
68
-        call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
-        do_action_ref_array('site-reviews/builder', [$instance]);
71
-        $generatedTag = in_array($instance->tag, $tags)
72
-            ? $instance->buildTag()
73
-            : $instance->buildCustomField();
74
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
-        if (!$this->render) {
76
-            return $generatedTag;
77
-        }
78
-        echo $generatedTag;
79
-    }
80
-
81
-    /**
82
-     * @param string $property
83
-     * @param mixed $value
84
-     * @return void
85
-     */
86
-    public function __set($property, $value)
87
-    {
88
-        $properties = [
89
-            'args' => 'is_array',
90
-            'render' => 'is_bool',
91
-            'tag' => 'is_string',
92
-        ];
93
-        if (!isset($properties[$property])
94
-            || empty(array_filter([$value], $properties[$property]))
95
-        ) {
96
-            return;
97
-        }
98
-        $this->$property = $value;
99
-    }
100
-
101
-    /**
102
-     * @return void|string
103
-     */
104
-    public function getClosingTag()
105
-    {
106
-        if (empty($this->tag)) {
107
-            return;
108
-        }
109
-        return '</'.$this->tag.'>';
110
-    }
111
-
112
-    /**
113
-     * @return void|string
114
-     */
115
-    public function getOpeningTag()
116
-    {
117
-        if (empty($this->tag)) {
118
-            return;
119
-        }
120
-        $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
-        return '<'.trim($this->tag.' '.$attributes).'>';
122
-    }
123
-
124
-    /**
125
-     * @return void|string
126
-     */
127
-    public function getTag()
128
-    {
129
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
130
-            return $this->getOpeningTag();
131
-        }
132
-        if (!in_array($this->tag, static::TAGS_FORM)) {
133
-            return $this->buildDefaultTag();
134
-        }
135
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
136
-    }
137
-
138
-    /**
139
-     * @return string
140
-     */
141
-    public function raw(array $field)
142
-    {
143
-        unset($field['label']);
144
-        return $this->{$field['type']}($field);
145
-    }
146
-
147
-    /**
148
-     * @return string|void
149
-     */
150
-    protected function buildCustomField()
151
-    {
152
-        $className = $this->getCustomFieldClassName();
153
-        if (class_exists($className)) {
154
-            return (new $className($this))->build();
155
-        }
156
-        glsr_log()->error('Field missing: '.$className);
157
-    }
158
-
159
-    /**
160
-     * @return string|void
161
-     */
162
-    protected function buildDefaultTag($text = '')
163
-    {
164
-        if (empty($text)) {
165
-            $text = $this->args['text'];
166
-        }
167
-        return $this->getOpeningTag().$text.$this->getClosingTag();
168
-    }
169
-
170
-    /**
171
-     * @return string|void
172
-     */
173
-    protected function buildFieldDescription()
174
-    {
175
-        if (empty($this->args['description'])) {
176
-            return;
177
-        }
178
-        if ($this->args['is_widget']) {
179
-            return $this->small($this->args['description']);
180
-        }
181
-        return $this->p($this->args['description'], ['class' => 'description']);
182
-    }
183
-
184
-    /**
185
-     * @return string|void
186
-     */
187
-    protected function buildFormInput()
188
-    {
189
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
-            if (isset($this->args['multiple'])) {
191
-                $this->args['name'].= '[]';
192
-            }
193
-            return $this->buildFormLabel().$this->getOpeningTag();
194
-        }
195
-        return empty($this->args['options'])
196
-            ? $this->buildFormInputChoice()
197
-            : $this->buildFormInputMultiChoice();
198
-    }
199
-
200
-    /**
201
-     * @return string|void
202
-     */
203
-    protected function buildFormInputChoice()
204
-    {
205
-        if (!empty($this->args['text'])) {
206
-            $this->args['label'] = $this->args['text'];
207
-        }
208
-        if (!$this->args['is_public']) {
209
-            return $this->buildFormLabel([
210
-                'class' => 'glsr-'.$this->args['type'].'-label',
211
-                'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
-            ]);
213
-        }
214
-        return $this->getOpeningTag().$this->buildFormLabel([
215
-            'class' => 'glsr-'.$this->args['type'].'-label',
216
-            'text' => $this->args['label'].'<span></span>',
217
-        ]);
218
-    }
219
-
220
-    /**
221
-     * @return string|void
222
-     */
223
-    protected function buildFormInputMultiChoice()
224
-    {
225
-        if ('checkbox' == $this->args['type']) {
226
-            $this->args['name'].= '[]';
227
-        }
228
-        $index = 0;
229
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
-            return $carry.$this->li($this->{$this->args['type']}([
231
-                'checked' => in_array($key, (array) $this->args['value']),
232
-                'id' => $this->args['id'].'-'.$index++,
233
-                'name' => $this->args['name'],
234
-                'text' => $this->args['options'][$key],
235
-                'value' => $key,
236
-            ]));
237
-        });
238
-        return $this->ul($options, [
239
-            'class' => $this->args['class'],
240
-            'id' => $this->args['id'],
241
-        ]);
242
-    }
243
-
244
-    /**
245
-     * @return void|string
246
-     */
247
-    protected function buildFormLabel(array $customArgs = [])
248
-    {
249
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
250
-            return;
251
-        }
252
-        return $this->label(wp_parse_args($customArgs, [
253
-            'for' => $this->args['id'],
254
-            'is_public' => $this->args['is_public'],
255
-            'text' => $this->args['label'],
256
-            'type' => $this->args['type'],
257
-        ]));
258
-    }
259
-
260
-    /**
261
-     * @return string|void
262
-     */
263
-    protected function buildFormSelect()
264
-    {
265
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
266
-    }
267
-
268
-    /**
269
-     * @return string|void
270
-     */
271
-    protected function buildFormSelectOptions()
272
-    {
273
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
-            return $carry.$this->option([
275
-                'selected' => $this->args['value'] == $key,
276
-                'text' => $this->args['options'][$key],
277
-                'value' => $key,
278
-            ]);
279
-        });
280
-    }
281
-
282
-    /**
283
-     * @return string|void
284
-     */
285
-    protected function buildFormTextarea()
286
-    {
287
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
288
-    }
289
-
290
-    /**
291
-     * @return string|void
292
-     */
293
-    protected function buildTag()
294
-    {
295
-        $this->mergeArgsWithRequiredDefaults();
296
-        return $this->getTag();
297
-    }
298
-
299
-    /**
300
-     * @return string
301
-     */
302
-    protected function getCustomFieldClassName()
303
-    {
304
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
306
-    }
307
-
308
-    /**
309
-     * @return void
310
-     */
311
-    protected function mergeArgsWithRequiredDefaults()
312
-    {
313
-        $className = $this->getCustomFieldClassName();
314
-        if (class_exists($className)) {
315
-            $this->args = $className::merge($this->args);
316
-        }
317
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
318
-    }
319
-
320
-    /**
321
-     * @param string|array ...$params
322
-     * @return void
323
-     */
324
-    protected function normalize(...$params)
325
-    {
326
-        if (is_string($params[0]) || is_numeric($params[0])) {
327
-            $this->setNameOrTextAttributeForTag($params[0]);
328
-        }
329
-        if (is_array($params[0])) {
330
-            $this->args += $params[0];
331
-        } elseif (is_array($params[1])) {
332
-            $this->args += $params[1];
333
-        }
334
-        if (!isset($this->args['is_public'])) {
335
-            $this->args['is_public'] = false;
336
-        }
337
-    }
338
-
339
-    /**
340
-     * @param string $value
341
-     * @return void
342
-     */
343
-    protected function setNameOrTextAttributeForTag($value)
344
-    {
345
-        $attribute = in_array($this->tag, static::TAGS_FORM)
346
-            ? 'name'
347
-            : 'text';
348
-        $this->args[$attribute] = $value;
349
-    }
350
-
351
-    /**
352
-     * @param string $method
353
-     * @return void
354
-     */
355
-    protected function setTagFromMethod($method)
356
-    {
357
-        $this->tag = strtolower($method);
358
-        if (in_array($this->tag, static::INPUT_TYPES)) {
359
-            $this->args['type'] = $this->tag;
360
-            $this->tag = 'input';
361
-        }
362
-    }
21
+	const INPUT_TYPES = [
22
+		'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
23
+		'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
24
+		'url', 'week',
25
+	];
26
+
27
+	const TAGS_FORM = [
28
+		'input', 'select', 'textarea',
29
+	];
30
+
31
+	const TAGS_SINGLE = [
32
+		'img',
33
+	];
34
+
35
+	const TAGS_STRUCTURE = [
36
+		'div', 'form', 'nav', 'ol', 'section', 'ul',
37
+	];
38
+
39
+	const TAGS_TEXT = [
40
+		'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
41
+		'small', 'span',
42
+	];
43
+
44
+	/**
45
+	 * @var array
46
+	 */
47
+	public $args = [];
48
+
49
+	/**
50
+	 * @var bool
51
+	 */
52
+	public $render = false;
53
+
54
+	/**
55
+	 * @var string
56
+	 */
57
+	public $tag;
58
+
59
+	/**
60
+	 * @param string $method
61
+	 * @param array $args
62
+	 * @return string|void
63
+	 */
64
+	public function __call($method, $args)
65
+	{
66
+		$instance = new static();
67
+		$instance->setTagFromMethod($method);
68
+		call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
+		$tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
+		do_action_ref_array('site-reviews/builder', [$instance]);
71
+		$generatedTag = in_array($instance->tag, $tags)
72
+			? $instance->buildTag()
73
+			: $instance->buildCustomField();
74
+		$generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
+		if (!$this->render) {
76
+			return $generatedTag;
77
+		}
78
+		echo $generatedTag;
79
+	}
80
+
81
+	/**
82
+	 * @param string $property
83
+	 * @param mixed $value
84
+	 * @return void
85
+	 */
86
+	public function __set($property, $value)
87
+	{
88
+		$properties = [
89
+			'args' => 'is_array',
90
+			'render' => 'is_bool',
91
+			'tag' => 'is_string',
92
+		];
93
+		if (!isset($properties[$property])
94
+			|| empty(array_filter([$value], $properties[$property]))
95
+		) {
96
+			return;
97
+		}
98
+		$this->$property = $value;
99
+	}
100
+
101
+	/**
102
+	 * @return void|string
103
+	 */
104
+	public function getClosingTag()
105
+	{
106
+		if (empty($this->tag)) {
107
+			return;
108
+		}
109
+		return '</'.$this->tag.'>';
110
+	}
111
+
112
+	/**
113
+	 * @return void|string
114
+	 */
115
+	public function getOpeningTag()
116
+	{
117
+		if (empty($this->tag)) {
118
+			return;
119
+		}
120
+		$attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
+		return '<'.trim($this->tag.' '.$attributes).'>';
122
+	}
123
+
124
+	/**
125
+	 * @return void|string
126
+	 */
127
+	public function getTag()
128
+	{
129
+		if (in_array($this->tag, static::TAGS_SINGLE)) {
130
+			return $this->getOpeningTag();
131
+		}
132
+		if (!in_array($this->tag, static::TAGS_FORM)) {
133
+			return $this->buildDefaultTag();
134
+		}
135
+		return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
136
+	}
137
+
138
+	/**
139
+	 * @return string
140
+	 */
141
+	public function raw(array $field)
142
+	{
143
+		unset($field['label']);
144
+		return $this->{$field['type']}($field);
145
+	}
146
+
147
+	/**
148
+	 * @return string|void
149
+	 */
150
+	protected function buildCustomField()
151
+	{
152
+		$className = $this->getCustomFieldClassName();
153
+		if (class_exists($className)) {
154
+			return (new $className($this))->build();
155
+		}
156
+		glsr_log()->error('Field missing: '.$className);
157
+	}
158
+
159
+	/**
160
+	 * @return string|void
161
+	 */
162
+	protected function buildDefaultTag($text = '')
163
+	{
164
+		if (empty($text)) {
165
+			$text = $this->args['text'];
166
+		}
167
+		return $this->getOpeningTag().$text.$this->getClosingTag();
168
+	}
169
+
170
+	/**
171
+	 * @return string|void
172
+	 */
173
+	protected function buildFieldDescription()
174
+	{
175
+		if (empty($this->args['description'])) {
176
+			return;
177
+		}
178
+		if ($this->args['is_widget']) {
179
+			return $this->small($this->args['description']);
180
+		}
181
+		return $this->p($this->args['description'], ['class' => 'description']);
182
+	}
183
+
184
+	/**
185
+	 * @return string|void
186
+	 */
187
+	protected function buildFormInput()
188
+	{
189
+		if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
+			if (isset($this->args['multiple'])) {
191
+				$this->args['name'].= '[]';
192
+			}
193
+			return $this->buildFormLabel().$this->getOpeningTag();
194
+		}
195
+		return empty($this->args['options'])
196
+			? $this->buildFormInputChoice()
197
+			: $this->buildFormInputMultiChoice();
198
+	}
199
+
200
+	/**
201
+	 * @return string|void
202
+	 */
203
+	protected function buildFormInputChoice()
204
+	{
205
+		if (!empty($this->args['text'])) {
206
+			$this->args['label'] = $this->args['text'];
207
+		}
208
+		if (!$this->args['is_public']) {
209
+			return $this->buildFormLabel([
210
+				'class' => 'glsr-'.$this->args['type'].'-label',
211
+				'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
+			]);
213
+		}
214
+		return $this->getOpeningTag().$this->buildFormLabel([
215
+			'class' => 'glsr-'.$this->args['type'].'-label',
216
+			'text' => $this->args['label'].'<span></span>',
217
+		]);
218
+	}
219
+
220
+	/**
221
+	 * @return string|void
222
+	 */
223
+	protected function buildFormInputMultiChoice()
224
+	{
225
+		if ('checkbox' == $this->args['type']) {
226
+			$this->args['name'].= '[]';
227
+		}
228
+		$index = 0;
229
+		$options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
+			return $carry.$this->li($this->{$this->args['type']}([
231
+				'checked' => in_array($key, (array) $this->args['value']),
232
+				'id' => $this->args['id'].'-'.$index++,
233
+				'name' => $this->args['name'],
234
+				'text' => $this->args['options'][$key],
235
+				'value' => $key,
236
+			]));
237
+		});
238
+		return $this->ul($options, [
239
+			'class' => $this->args['class'],
240
+			'id' => $this->args['id'],
241
+		]);
242
+	}
243
+
244
+	/**
245
+	 * @return void|string
246
+	 */
247
+	protected function buildFormLabel(array $customArgs = [])
248
+	{
249
+		if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
250
+			return;
251
+		}
252
+		return $this->label(wp_parse_args($customArgs, [
253
+			'for' => $this->args['id'],
254
+			'is_public' => $this->args['is_public'],
255
+			'text' => $this->args['label'],
256
+			'type' => $this->args['type'],
257
+		]));
258
+	}
259
+
260
+	/**
261
+	 * @return string|void
262
+	 */
263
+	protected function buildFormSelect()
264
+	{
265
+		return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
266
+	}
267
+
268
+	/**
269
+	 * @return string|void
270
+	 */
271
+	protected function buildFormSelectOptions()
272
+	{
273
+		return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
+			return $carry.$this->option([
275
+				'selected' => $this->args['value'] == $key,
276
+				'text' => $this->args['options'][$key],
277
+				'value' => $key,
278
+			]);
279
+		});
280
+	}
281
+
282
+	/**
283
+	 * @return string|void
284
+	 */
285
+	protected function buildFormTextarea()
286
+	{
287
+		return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
288
+	}
289
+
290
+	/**
291
+	 * @return string|void
292
+	 */
293
+	protected function buildTag()
294
+	{
295
+		$this->mergeArgsWithRequiredDefaults();
296
+		return $this->getTag();
297
+	}
298
+
299
+	/**
300
+	 * @return string
301
+	 */
302
+	protected function getCustomFieldClassName()
303
+	{
304
+		$classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
+		return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
306
+	}
307
+
308
+	/**
309
+	 * @return void
310
+	 */
311
+	protected function mergeArgsWithRequiredDefaults()
312
+	{
313
+		$className = $this->getCustomFieldClassName();
314
+		if (class_exists($className)) {
315
+			$this->args = $className::merge($this->args);
316
+		}
317
+		$this->args = glsr(BuilderDefaults::class)->merge($this->args);
318
+	}
319
+
320
+	/**
321
+	 * @param string|array ...$params
322
+	 * @return void
323
+	 */
324
+	protected function normalize(...$params)
325
+	{
326
+		if (is_string($params[0]) || is_numeric($params[0])) {
327
+			$this->setNameOrTextAttributeForTag($params[0]);
328
+		}
329
+		if (is_array($params[0])) {
330
+			$this->args += $params[0];
331
+		} elseif (is_array($params[1])) {
332
+			$this->args += $params[1];
333
+		}
334
+		if (!isset($this->args['is_public'])) {
335
+			$this->args['is_public'] = false;
336
+		}
337
+	}
338
+
339
+	/**
340
+	 * @param string $value
341
+	 * @return void
342
+	 */
343
+	protected function setNameOrTextAttributeForTag($value)
344
+	{
345
+		$attribute = in_array($this->tag, static::TAGS_FORM)
346
+			? 'name'
347
+			: 'text';
348
+		$this->args[$attribute] = $value;
349
+	}
350
+
351
+	/**
352
+	 * @param string $method
353
+	 * @return void
354
+	 */
355
+	protected function setTagFromMethod($method)
356
+	{
357
+		$this->tag = strtolower($method);
358
+		if (in_array($this->tag, static::INPUT_TYPES)) {
359
+			$this->args['type'] = $this->tag;
360
+			$this->tag = 'input';
361
+		}
362
+	}
363 363
 }
Please login to merge, or discard this patch.