Test Failed
Push — hotfix/fix-counts ( 9a2e54...d16e24 )
by Paul
03:31
created
activate.php 3 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
  */
9 9
 class GL_Plugin_Check_v3
10 10
 {
11
-    const MIN_PHP_VERSION = '5.6.0';
12
-    const MIN_WORDPRESS_VERSION = '4.7.0';
11
+	const MIN_PHP_VERSION = '5.6.0';
12
+	const MIN_WORDPRESS_VERSION = '4.7.0';
13 13
 
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $file;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $file;
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    protected $versions;
19
+	/**
20
+	 * @var array
21
+	 */
22
+	protected $versions;
23 23
 
24
-    /**
25
-     * @param string $file
26
-     */
27
-    public function __construct($file, array $versions = array())
28
-    {
29
-        $this->file = realpath($file);
30
-        $this->versions = wp_parse_args($versions, array(
31
-            'php' => static::MIN_PHP_VERSION,
32
-            'wordpress' => static::MIN_WORDPRESS_VERSION,
33
-        ));
34
-    }
24
+	/**
25
+	 * @param string $file
26
+	 */
27
+	public function __construct($file, array $versions = array())
28
+	{
29
+		$this->file = realpath($file);
30
+		$this->versions = wp_parse_args($versions, array(
31
+			'php' => static::MIN_PHP_VERSION,
32
+			'wordpress' => static::MIN_WORDPRESS_VERSION,
33
+		));
34
+	}
35 35
 
36
-    /**
37
-     * @return bool
38
-     */
39
-    public function canProceed()
40
-    {
41
-        if ($this->isValid()) {
42
-            return true;
43
-        }
44
-        add_action('activated_plugin', array($this, 'deactivate'));
45
-        add_action('admin_notices', array($this, 'deactivate'));
46
-        return false;
47
-    }
36
+	/**
37
+	 * @return bool
38
+	 */
39
+	public function canProceed()
40
+	{
41
+		if ($this->isValid()) {
42
+			return true;
43
+		}
44
+		add_action('activated_plugin', array($this, 'deactivate'));
45
+		add_action('admin_notices', array($this, 'deactivate'));
46
+		return false;
47
+	}
48 48
 
49
-    /**
50
-     * @return bool
51
-     */
52
-    public function isPhpValid()
53
-    {
54
-        return !version_compare(PHP_VERSION, $this->versions['php'], '<');
55
-    }
49
+	/**
50
+	 * @return bool
51
+	 */
52
+	public function isPhpValid()
53
+	{
54
+		return !version_compare(PHP_VERSION, $this->versions['php'], '<');
55
+	}
56 56
 
57
-    /**
58
-     * @return bool
59
-     */
60
-    public function isValid()
61
-    {
62
-        return $this->isPhpValid() && $this->isWpValid();
63
-    }
57
+	/**
58
+	 * @return bool
59
+	 */
60
+	public function isValid()
61
+	{
62
+		return $this->isPhpValid() && $this->isWpValid();
63
+	}
64 64
 
65
-    /**
66
-     * @return bool
67
-     */
68
-    public function isWpValid()
69
-    {
70
-        global $wp_version;
71
-        return !version_compare($wp_version, $this->versions['wordpress'], '<');
72
-    }
65
+	/**
66
+	 * @return bool
67
+	 */
68
+	public function isWpValid()
69
+	{
70
+		global $wp_version;
71
+		return !version_compare($wp_version, $this->versions['wordpress'], '<');
72
+	}
73 73
 
74
-    /**
75
-     * @param string $plugin
76
-     * @return void
77
-     */
78
-    public function deactivate($plugin)
79
-    {
80
-        if ($this->isValid()) {
81
-            return;
82
-        }
83
-        $pluginSlug = plugin_basename($this->file);
84
-        if ($plugin == $pluginSlug) {
85
-            $this->redirect(); //exit
86
-        }
87
-        $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin');
88
-        deactivate_plugins($pluginSlug);
89
-        $this->printNotice($pluginData['name']);
90
-    }
74
+	/**
75
+	 * @param string $plugin
76
+	 * @return void
77
+	 */
78
+	public function deactivate($plugin)
79
+	{
80
+		if ($this->isValid()) {
81
+			return;
82
+		}
83
+		$pluginSlug = plugin_basename($this->file);
84
+		if ($plugin == $pluginSlug) {
85
+			$this->redirect(); //exit
86
+		}
87
+		$pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin');
88
+		deactivate_plugins($pluginSlug);
89
+		$this->printNotice($pluginData['name']);
90
+	}
91 91
 
92
-    /**
93
-     * @return array
94
-     */
95
-    protected function getMessages()
96
-    {
97
-        return array(
98
-            __('The %s plugin was deactivated.', 'site-reviews'),
99
-            __('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
100
-            __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
101
-            __('PHP version', 'site-reviews'),
102
-            __('WordPress version', 'site-reviews'),
103
-            __('Update WordPress', 'site-reviews'),
104
-            __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
105
-        );
106
-    }
92
+	/**
93
+	 * @return array
94
+	 */
95
+	protected function getMessages()
96
+	{
97
+		return array(
98
+			__('The %s plugin was deactivated.', 'site-reviews'),
99
+			__('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
100
+			__('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
101
+			__('PHP version', 'site-reviews'),
102
+			__('WordPress version', 'site-reviews'),
103
+			__('Update WordPress', 'site-reviews'),
104
+			__('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
105
+		);
106
+	}
107 107
 
108
-    /**
109
-     * @param string $pluginName
110
-     * @return void
111
-     */
112
-    protected function printNotice($pluginName)
113
-    {
114
-        $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
115
-        $messages = $this->getMessages();
116
-        $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
117
-        if (!$this->isPhpValid()) {
118
-            printf($noticeTemplate,
119
-                sprintf($messages[0], $pluginName),
120
-                sprintf($messages[1], $messages[3].' '.$this->versions['php']),
121
-                sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage
122
-            );
123
-        } elseif (!$this->isWpValid()) {
124
-            printf($noticeTemplate,
125
-                sprintf($messages[0], $pluginName),
126
-                sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']),
127
-                $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5])
128
-            );
129
-        }
130
-    }
108
+	/**
109
+	 * @param string $pluginName
110
+	 * @return void
111
+	 */
112
+	protected function printNotice($pluginName)
113
+	{
114
+		$noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
115
+		$messages = $this->getMessages();
116
+		$rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
117
+		if (!$this->isPhpValid()) {
118
+			printf($noticeTemplate,
119
+				sprintf($messages[0], $pluginName),
120
+				sprintf($messages[1], $messages[3].' '.$this->versions['php']),
121
+				sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage
122
+			);
123
+		} elseif (!$this->isWpValid()) {
124
+			printf($noticeTemplate,
125
+				sprintf($messages[0], $pluginName),
126
+				sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']),
127
+				$rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5])
128
+			);
129
+		}
130
+	}
131 131
 
132
-    /**
133
-     * @return void
134
-     */
135
-    protected function redirect()
136
-    {
137
-        wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
138
-            filter_input(INPUT_GET, 'plugin_status'),
139
-            filter_input(INPUT_GET, 'paged'),
140
-            filter_input(INPUT_GET, 's')
141
-        )));
142
-        exit;
143
-    }
132
+	/**
133
+	 * @return void
134
+	 */
135
+	protected function redirect()
136
+	{
137
+		wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
138
+			filter_input(INPUT_GET, 'plugin_status'),
139
+			filter_input(INPUT_GET, 'paged'),
140
+			filter_input(INPUT_GET, 's')
141
+		)));
142
+		exit;
143
+	}
144 144
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-defined('WPINC') || die;
3
+defined( 'WPINC' ) || die;
4 4
 
5 5
 /**
6 6
  * Check for minimum system requirments on plugin activation.
@@ -24,13 +24,13 @@  discard block
 block discarded – undo
24 24
     /**
25 25
      * @param string $file
26 26
      */
27
-    public function __construct($file, array $versions = array())
27
+    public function __construct( $file, array $versions = array() )
28 28
     {
29
-        $this->file = realpath($file);
30
-        $this->versions = wp_parse_args($versions, array(
29
+        $this->file = realpath( $file );
30
+        $this->versions = wp_parse_args( $versions, array(
31 31
             'php' => static::MIN_PHP_VERSION,
32 32
             'wordpress' => static::MIN_WORDPRESS_VERSION,
33
-        ));
33
+        ) );
34 34
     }
35 35
 
36 36
     /**
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function canProceed()
40 40
     {
41
-        if ($this->isValid()) {
41
+        if( $this->isValid() ) {
42 42
             return true;
43 43
         }
44
-        add_action('activated_plugin', array($this, 'deactivate'));
45
-        add_action('admin_notices', array($this, 'deactivate'));
44
+        add_action( 'activated_plugin', array( $this, 'deactivate' ) );
45
+        add_action( 'admin_notices', array( $this, 'deactivate' ) );
46 46
         return false;
47 47
     }
48 48
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function isPhpValid()
53 53
     {
54
-        return !version_compare(PHP_VERSION, $this->versions['php'], '<');
54
+        return !version_compare( PHP_VERSION, $this->versions['php'], '<' );
55 55
     }
56 56
 
57 57
     /**
@@ -68,25 +68,25 @@  discard block
 block discarded – undo
68 68
     public function isWpValid()
69 69
     {
70 70
         global $wp_version;
71
-        return !version_compare($wp_version, $this->versions['wordpress'], '<');
71
+        return !version_compare( $wp_version, $this->versions['wordpress'], '<' );
72 72
     }
73 73
 
74 74
     /**
75 75
      * @param string $plugin
76 76
      * @return void
77 77
      */
78
-    public function deactivate($plugin)
78
+    public function deactivate( $plugin )
79 79
     {
80
-        if ($this->isValid()) {
80
+        if( $this->isValid() ) {
81 81
             return;
82 82
         }
83
-        $pluginSlug = plugin_basename($this->file);
84
-        if ($plugin == $pluginSlug) {
83
+        $pluginSlug = plugin_basename( $this->file );
84
+        if( $plugin == $pluginSlug ) {
85 85
             $this->redirect(); //exit
86 86
         }
87
-        $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin');
88
-        deactivate_plugins($pluginSlug);
89
-        $this->printNotice($pluginData['name']);
87
+        $pluginData = get_file_data( $this->file, array( 'name' => 'Plugin Name' ), 'plugin' );
88
+        deactivate_plugins( $pluginSlug );
89
+        $this->printNotice( $pluginData['name'] );
90 90
     }
91 91
 
92 92
     /**
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
     protected function getMessages()
96 96
     {
97 97
         return array(
98
-            __('The %s plugin was deactivated.', 'site-reviews'),
99
-            __('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
100
-            __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
101
-            __('PHP version', 'site-reviews'),
102
-            __('WordPress version', 'site-reviews'),
103
-            __('Update WordPress', 'site-reviews'),
104
-            __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
98
+            __( 'The %s plugin was deactivated.', 'site-reviews' ),
99
+            __( 'This plugin requires %s or greater in order to work properly.', 'site-reviews' ),
100
+            __( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews' ),
101
+            __( 'PHP version', 'site-reviews' ),
102
+            __( 'WordPress version', 'site-reviews' ),
103
+            __( 'Update WordPress', 'site-reviews' ),
104
+            __( 'You can use the %s plugin to restore %s to the previous version.', 'site-reviews' ),
105 105
         );
106 106
     }
107 107
 
@@ -109,22 +109,22 @@  discard block
 block discarded – undo
109 109
      * @param string $pluginName
110 110
      * @return void
111 111
      */
112
-    protected function printNotice($pluginName)
112
+    protected function printNotice( $pluginName )
113 113
     {
114 114
         $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
115 115
         $messages = $this->getMessages();
116
-        $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
117
-        if (!$this->isPhpValid()) {
118
-            printf($noticeTemplate,
119
-                sprintf($messages[0], $pluginName),
120
-                sprintf($messages[1], $messages[3].' '.$this->versions['php']),
121
-                sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage
116
+        $rollbackMessage = sprintf( '<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName );
117
+        if( !$this->isPhpValid() ) {
118
+            printf( $noticeTemplate,
119
+                sprintf( $messages[0], $pluginName ),
120
+                sprintf( $messages[1], $messages[3].' '.$this->versions['php'] ),
121
+                sprintf( $messages[2], PHP_VERSION ).'</p><p>'.$rollbackMessage
122 122
             );
123
-        } elseif (!$this->isWpValid()) {
124
-            printf($noticeTemplate,
125
-                sprintf($messages[0], $pluginName),
126
-                sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']),
127
-                $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5])
123
+        } elseif( !$this->isWpValid() ) {
124
+            printf( $noticeTemplate,
125
+                sprintf( $messages[0], $pluginName ),
126
+                sprintf( $messages[1], $messages[4].' '.$this->versions['wordpress'] ),
127
+                $rollbackMessage.'</p><p>'.sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages[5] )
128 128
             );
129 129
         }
130 130
     }
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
      */
135 135
     protected function redirect()
136 136
     {
137
-        wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
138
-            filter_input(INPUT_GET, 'plugin_status'),
139
-            filter_input(INPUT_GET, 'paged'),
140
-            filter_input(INPUT_GET, 's')
141
-        )));
137
+        wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s',
138
+            filter_input( INPUT_GET, 'plugin_status' ),
139
+            filter_input( INPUT_GET, 'paged' ),
140
+            filter_input( INPUT_GET, 's' )
141
+        ) ) );
142 142
         exit;
143 143
     }
144 144
 }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -120,7 +120,8 @@
 block discarded – undo
120 120
                 sprintf($messages[1], $messages[3].' '.$this->versions['php']),
121 121
                 sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage
122 122
             );
123
-        } elseif (!$this->isWpValid()) {
123
+        }
124
+        elseif (!$this->isWpValid()) {
124 125
             printf($noticeTemplate,
125 126
                 sprintf($messages[0], $pluginName),
126 127
                 sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']),
Please login to merge, or discard this patch.
plugin/Modules/Html/Settings.php 2 patches
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -9,239 +9,239 @@
 block discarded – undo
9 9
 
10 10
 class Settings
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $settings;
16
-
17
-    /**
18
-     * @param string $id
19
-     * @return string
20
-     */
21
-    public function buildFields($id)
22
-    {
23
-        $this->settings = glsr(DefaultsManager::class)->settings();
24
-        $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
-        $data = !method_exists($this, $method)
26
-            ? $this->getTemplateData($id)
27
-            : $this->$method($id);
28
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
29
-    }
30
-
31
-    /**
32
-     * @return string
33
-     */
34
-    protected function getFieldDefault(array $field)
35
-    {
36
-        return glsr_get($field, 'default');
37
-    }
38
-
39
-    /**
40
-     * @return string
41
-     */
42
-    protected function getFieldNameForDependsOn($path)
43
-    {
44
-        $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
-        return $this->isMultiDependency($path)
46
-            ? $fieldName.'[]'
47
-            : $fieldName;
48
-    }
49
-
50
-    /**
51
-     * @return array
52
-     */
53
-    protected function getSettingFields($path)
54
-    {
55
-        return array_filter($this->settings, function ($key) use ($path) {
56
-            return glsr(Helper::class)->startsWith($path, $key);
57
-        }, ARRAY_FILTER_USE_KEY);
58
-    }
59
-
60
-    /**
61
-     * @return string
62
-     */
63
-    protected function getSettingRows(array $fields)
64
-    {
65
-        $rows = '';
66
-        foreach ($fields as $name => $field) {
67
-            $field = wp_parse_args($field, [
68
-                'is_setting' => true,
69
-                'name' => $name,
70
-            ]);
71
-            $rows.= new Field($this->normalize($field));
72
-        }
73
-        return $rows;
74
-    }
75
-
76
-    /**
77
-     * @param string $id
78
-     * @return array
79
-     */
80
-    protected function getTemplateData($id)
81
-    {
82
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
83
-        return [
84
-            'context' => [
85
-                'rows' => $this->getSettingRows($fields),
86
-            ],
87
-        ];
88
-    }
89
-
90
-    /**
91
-     * @param string $id
92
-     * @return array
93
-     */
94
-    protected function getTemplateDataForAddons($id)
95
-    {
96
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
-        $settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
-        $settingKeys = array_keys($settings['settings']['addons']);
99
-        $results = [];
100
-        foreach ($settingKeys as $key) {
101
-            $addonFields = array_filter($fields, function ($path) use ($key) {
102
-                return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
-            }, ARRAY_FILTER_USE_KEY);
104
-            $results[$key] = $this->getSettingRows($addonFields);
105
-        }
106
-        ksort($results);
107
-        return [
108
-            'settings' => $results,
109
-        ];
110
-    }
111
-
112
-    /**
113
-     * @param string $id
114
-     * @return array
115
-     */
116
-    protected function getTemplateDataForLicenses($id)
117
-    {
118
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
-        ksort($fields);
120
-        return [
121
-            'context' => [
122
-                'rows' => $this->getSettingRows($fields),
123
-            ],
124
-        ];
125
-    }
126
-
127
-    /**
128
-     * @return array
129
-     */
130
-    protected function getTemplateDataForTranslations()
131
-    {
132
-        $translations = glsr(Translation::class)->renderAll();
133
-        $class = empty($translations)
134
-            ? 'glsr-hidden'
135
-            : '';
136
-        return [
137
-            'context' => [
138
-                'class' => $class,
139
-                'database_key' => OptionManager::databaseKey(),
140
-                'translations' => $translations,
141
-            ],
142
-        ];
143
-    }
144
-
145
-    /**
146
-     * @param string $path
147
-     * @param string|array $expectedValue
148
-     * @return bool
149
-     */
150
-    protected function isFieldHidden($path, $expectedValue)
151
-    {
152
-        $optionValue = glsr(OptionManager::class)->get(
153
-            $path,
154
-            glsr(Helper::class)->dataGet(glsr()->defaults, $path)
155
-        );
156
-        if (is_array($expectedValue)) {
157
-            return is_array($optionValue)
158
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
159
-                : !in_array($optionValue, $expectedValue);
160
-        }
161
-        return $optionValue != $expectedValue;
162
-    }
163
-
164
-    /**
165
-     * @return bool
166
-     */
167
-    protected function isMultiDependency($path)
168
-    {
169
-        if (isset($this->settings[$path])) {
170
-            $field = $this->settings[$path];
171
-            return ('checkbox' == $field['type'] && !empty($field['options']))
172
-                || !empty($field['multiple']);
173
-        }
174
-        return false;
175
-    }
176
-
177
-    /**
178
-     * @return array
179
-     */
180
-    protected function normalize(array $field)
181
-    {
182
-        $field = $this->normalizeDependsOn($field);
183
-        $field = $this->normalizeLabelAndLegend($field);
184
-        $field = $this->normalizeValue($field);
185
-        return $field;
186
-    }
187
-
188
-    /**
189
-     * @return array
190
-     */
191
-    protected function normalizeDependsOn(array $field)
192
-    {
193
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
194
-            $isFieldHidden = false;
195
-            $conditions = [];
196
-            foreach ($field['depends_on'] as $path => $value) {
197
-                $conditions[] = [
198
-                    'name' => $this->getFieldNameForDependsOn($path),
199
-                    'value' => $value,
200
-                ];
201
-                if ($this->isFieldHidden($path, $value)) {
202
-                    $isFieldHidden = true;
203
-                }
204
-            }
205
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
206
-            $field['is_hidden'] = $isFieldHidden;
207
-        }
208
-        return $field;
209
-    }
210
-
211
-    /**
212
-     * @return array
213
-     */
214
-    protected function normalizeLabelAndLegend(array $field)
215
-    {
216
-        if (!empty($field['label'])) {
217
-            $field['legend'] = $field['label'];
218
-            unset($field['label']);
219
-        } else {
220
-            $field['is_valid'] = false;
221
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
222
-        }
223
-        return $field;
224
-    }
225
-
226
-    /**
227
-     * @return array
228
-     */
229
-    protected function normalizeValue(array $field)
230
-    {
231
-        if (!isset($field['value'])) {
232
-            $field['value'] = glsr(OptionManager::class)->get(
233
-                $field['name'],
234
-                $this->getFieldDefault($field)
235
-            );
236
-        }
237
-        return $field;
238
-    }
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    protected function normalizeSettingPath($path)
244
-    {
245
-        return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.');
246
-    }
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $settings;
16
+
17
+	/**
18
+	 * @param string $id
19
+	 * @return string
20
+	 */
21
+	public function buildFields($id)
22
+	{
23
+		$this->settings = glsr(DefaultsManager::class)->settings();
24
+		$method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
+		$data = !method_exists($this, $method)
26
+			? $this->getTemplateData($id)
27
+			: $this->$method($id);
28
+		return glsr(Template::class)->build('pages/settings/'.$id, $data);
29
+	}
30
+
31
+	/**
32
+	 * @return string
33
+	 */
34
+	protected function getFieldDefault(array $field)
35
+	{
36
+		return glsr_get($field, 'default');
37
+	}
38
+
39
+	/**
40
+	 * @return string
41
+	 */
42
+	protected function getFieldNameForDependsOn($path)
43
+	{
44
+		$fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
+		return $this->isMultiDependency($path)
46
+			? $fieldName.'[]'
47
+			: $fieldName;
48
+	}
49
+
50
+	/**
51
+	 * @return array
52
+	 */
53
+	protected function getSettingFields($path)
54
+	{
55
+		return array_filter($this->settings, function ($key) use ($path) {
56
+			return glsr(Helper::class)->startsWith($path, $key);
57
+		}, ARRAY_FILTER_USE_KEY);
58
+	}
59
+
60
+	/**
61
+	 * @return string
62
+	 */
63
+	protected function getSettingRows(array $fields)
64
+	{
65
+		$rows = '';
66
+		foreach ($fields as $name => $field) {
67
+			$field = wp_parse_args($field, [
68
+				'is_setting' => true,
69
+				'name' => $name,
70
+			]);
71
+			$rows.= new Field($this->normalize($field));
72
+		}
73
+		return $rows;
74
+	}
75
+
76
+	/**
77
+	 * @param string $id
78
+	 * @return array
79
+	 */
80
+	protected function getTemplateData($id)
81
+	{
82
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
83
+		return [
84
+			'context' => [
85
+				'rows' => $this->getSettingRows($fields),
86
+			],
87
+		];
88
+	}
89
+
90
+	/**
91
+	 * @param string $id
92
+	 * @return array
93
+	 */
94
+	protected function getTemplateDataForAddons($id)
95
+	{
96
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
+		$settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
+		$settingKeys = array_keys($settings['settings']['addons']);
99
+		$results = [];
100
+		foreach ($settingKeys as $key) {
101
+			$addonFields = array_filter($fields, function ($path) use ($key) {
102
+				return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
+			}, ARRAY_FILTER_USE_KEY);
104
+			$results[$key] = $this->getSettingRows($addonFields);
105
+		}
106
+		ksort($results);
107
+		return [
108
+			'settings' => $results,
109
+		];
110
+	}
111
+
112
+	/**
113
+	 * @param string $id
114
+	 * @return array
115
+	 */
116
+	protected function getTemplateDataForLicenses($id)
117
+	{
118
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
+		ksort($fields);
120
+		return [
121
+			'context' => [
122
+				'rows' => $this->getSettingRows($fields),
123
+			],
124
+		];
125
+	}
126
+
127
+	/**
128
+	 * @return array
129
+	 */
130
+	protected function getTemplateDataForTranslations()
131
+	{
132
+		$translations = glsr(Translation::class)->renderAll();
133
+		$class = empty($translations)
134
+			? 'glsr-hidden'
135
+			: '';
136
+		return [
137
+			'context' => [
138
+				'class' => $class,
139
+				'database_key' => OptionManager::databaseKey(),
140
+				'translations' => $translations,
141
+			],
142
+		];
143
+	}
144
+
145
+	/**
146
+	 * @param string $path
147
+	 * @param string|array $expectedValue
148
+	 * @return bool
149
+	 */
150
+	protected function isFieldHidden($path, $expectedValue)
151
+	{
152
+		$optionValue = glsr(OptionManager::class)->get(
153
+			$path,
154
+			glsr(Helper::class)->dataGet(glsr()->defaults, $path)
155
+		);
156
+		if (is_array($expectedValue)) {
157
+			return is_array($optionValue)
158
+				? 0 === count(array_intersect($optionValue, $expectedValue))
159
+				: !in_array($optionValue, $expectedValue);
160
+		}
161
+		return $optionValue != $expectedValue;
162
+	}
163
+
164
+	/**
165
+	 * @return bool
166
+	 */
167
+	protected function isMultiDependency($path)
168
+	{
169
+		if (isset($this->settings[$path])) {
170
+			$field = $this->settings[$path];
171
+			return ('checkbox' == $field['type'] && !empty($field['options']))
172
+				|| !empty($field['multiple']);
173
+		}
174
+		return false;
175
+	}
176
+
177
+	/**
178
+	 * @return array
179
+	 */
180
+	protected function normalize(array $field)
181
+	{
182
+		$field = $this->normalizeDependsOn($field);
183
+		$field = $this->normalizeLabelAndLegend($field);
184
+		$field = $this->normalizeValue($field);
185
+		return $field;
186
+	}
187
+
188
+	/**
189
+	 * @return array
190
+	 */
191
+	protected function normalizeDependsOn(array $field)
192
+	{
193
+		if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
194
+			$isFieldHidden = false;
195
+			$conditions = [];
196
+			foreach ($field['depends_on'] as $path => $value) {
197
+				$conditions[] = [
198
+					'name' => $this->getFieldNameForDependsOn($path),
199
+					'value' => $value,
200
+				];
201
+				if ($this->isFieldHidden($path, $value)) {
202
+					$isFieldHidden = true;
203
+				}
204
+			}
205
+			$field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
206
+			$field['is_hidden'] = $isFieldHidden;
207
+		}
208
+		return $field;
209
+	}
210
+
211
+	/**
212
+	 * @return array
213
+	 */
214
+	protected function normalizeLabelAndLegend(array $field)
215
+	{
216
+		if (!empty($field['label'])) {
217
+			$field['legend'] = $field['label'];
218
+			unset($field['label']);
219
+		} else {
220
+			$field['is_valid'] = false;
221
+			glsr_log()->warning('Setting field is missing a label')->debug($field);
222
+		}
223
+		return $field;
224
+	}
225
+
226
+	/**
227
+	 * @return array
228
+	 */
229
+	protected function normalizeValue(array $field)
230
+	{
231
+		if (!isset($field['value'])) {
232
+			$field['value'] = glsr(OptionManager::class)->get(
233
+				$field['name'],
234
+				$this->getFieldDefault($field)
235
+			);
236
+		}
237
+		return $field;
238
+	}
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	protected function normalizeSettingPath($path)
244
+	{
245
+		return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.');
246
+	}
247 247
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -18,31 +18,31 @@  discard block
 block discarded – undo
18 18
      * @param string $id
19 19
      * @return string
20 20
      */
21
-    public function buildFields($id)
21
+    public function buildFields( $id )
22 22
     {
23
-        $this->settings = glsr(DefaultsManager::class)->settings();
24
-        $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
-        $data = !method_exists($this, $method)
26
-            ? $this->getTemplateData($id)
27
-            : $this->$method($id);
28
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
23
+        $this->settings = glsr( DefaultsManager::class )->settings();
24
+        $method = glsr( Helper::class )->buildMethodName( $id, 'getTemplateDataFor' );
25
+        $data = !method_exists( $this, $method )
26
+            ? $this->getTemplateData( $id )
27
+            : $this->$method( $id );
28
+        return glsr( Template::class )->build( 'pages/settings/'.$id, $data );
29 29
     }
30 30
 
31 31
     /**
32 32
      * @return string
33 33
      */
34
-    protected function getFieldDefault(array $field)
34
+    protected function getFieldDefault( array $field )
35 35
     {
36
-        return glsr_get($field, 'default');
36
+        return glsr_get( $field, 'default' );
37 37
     }
38 38
 
39 39
     /**
40 40
      * @return string
41 41
      */
42
-    protected function getFieldNameForDependsOn($path)
42
+    protected function getFieldNameForDependsOn( $path )
43 43
     {
44
-        $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
-        return $this->isMultiDependency($path)
44
+        $fieldName = glsr( Helper::class )->convertPathToName( $path, OptionManager::databaseKey() );
45
+        return $this->isMultiDependency( $path )
46 46
             ? $fieldName.'[]'
47 47
             : $fieldName;
48 48
     }
@@ -50,25 +50,25 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @return array
52 52
      */
53
-    protected function getSettingFields($path)
53
+    protected function getSettingFields( $path )
54 54
     {
55
-        return array_filter($this->settings, function ($key) use ($path) {
56
-            return glsr(Helper::class)->startsWith($path, $key);
57
-        }, ARRAY_FILTER_USE_KEY);
55
+        return array_filter( $this->settings, function( $key ) use ($path) {
56
+            return glsr( Helper::class )->startsWith( $path, $key );
57
+        }, ARRAY_FILTER_USE_KEY );
58 58
     }
59 59
 
60 60
     /**
61 61
      * @return string
62 62
      */
63
-    protected function getSettingRows(array $fields)
63
+    protected function getSettingRows( array $fields )
64 64
     {
65 65
         $rows = '';
66
-        foreach ($fields as $name => $field) {
67
-            $field = wp_parse_args($field, [
66
+        foreach( $fields as $name => $field ) {
67
+            $field = wp_parse_args( $field, [
68 68
                 'is_setting' => true,
69 69
                 'name' => $name,
70
-            ]);
71
-            $rows.= new Field($this->normalize($field));
70
+            ] );
71
+            $rows .= new Field( $this->normalize( $field ) );
72 72
         }
73 73
         return $rows;
74 74
     }
@@ -77,12 +77,12 @@  discard block
 block discarded – undo
77 77
      * @param string $id
78 78
      * @return array
79 79
      */
80
-    protected function getTemplateData($id)
80
+    protected function getTemplateData( $id )
81 81
     {
82
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
82
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
83 83
         return [
84 84
             'context' => [
85
-                'rows' => $this->getSettingRows($fields),
85
+                'rows' => $this->getSettingRows( $fields ),
86 86
             ],
87 87
         ];
88 88
     }
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
      * @param string $id
92 92
      * @return array
93 93
      */
94
-    protected function getTemplateDataForAddons($id)
94
+    protected function getTemplateDataForAddons( $id )
95 95
     {
96
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
-        $settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
-        $settingKeys = array_keys($settings['settings']['addons']);
96
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
97
+        $settings = glsr( Helper::class )->convertDotNotationArray( $fields );
98
+        $settingKeys = array_keys( $settings['settings']['addons'] );
99 99
         $results = [];
100
-        foreach ($settingKeys as $key) {
101
-            $addonFields = array_filter($fields, function ($path) use ($key) {
102
-                return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
-            }, ARRAY_FILTER_USE_KEY);
104
-            $results[$key] = $this->getSettingRows($addonFields);
100
+        foreach( $settingKeys as $key ) {
101
+            $addonFields = array_filter( $fields, function( $path ) use ($key) {
102
+                return glsr( Helper::class )->startsWith( 'settings.addons.'.$key, $path );
103
+            }, ARRAY_FILTER_USE_KEY );
104
+            $results[$key] = $this->getSettingRows( $addonFields );
105 105
         }
106
-        ksort($results);
106
+        ksort( $results );
107 107
         return [
108 108
             'settings' => $results,
109 109
         ];
@@ -113,13 +113,13 @@  discard block
 block discarded – undo
113 113
      * @param string $id
114 114
      * @return array
115 115
      */
116
-    protected function getTemplateDataForLicenses($id)
116
+    protected function getTemplateDataForLicenses( $id )
117 117
     {
118
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
-        ksort($fields);
118
+        $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) );
119
+        ksort( $fields );
120 120
         return [
121 121
             'context' => [
122
-                'rows' => $this->getSettingRows($fields),
122
+                'rows' => $this->getSettingRows( $fields ),
123 123
             ],
124 124
         ];
125 125
     }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      */
130 130
     protected function getTemplateDataForTranslations()
131 131
     {
132
-        $translations = glsr(Translation::class)->renderAll();
132
+        $translations = glsr( Translation::class )->renderAll();
133 133
         $class = empty($translations)
134 134
             ? 'glsr-hidden'
135 135
             : '';
@@ -147,16 +147,16 @@  discard block
 block discarded – undo
147 147
      * @param string|array $expectedValue
148 148
      * @return bool
149 149
      */
150
-    protected function isFieldHidden($path, $expectedValue)
150
+    protected function isFieldHidden( $path, $expectedValue )
151 151
     {
152
-        $optionValue = glsr(OptionManager::class)->get(
152
+        $optionValue = glsr( OptionManager::class )->get(
153 153
             $path,
154
-            glsr(Helper::class)->dataGet(glsr()->defaults, $path)
154
+            glsr( Helper::class )->dataGet( glsr()->defaults, $path )
155 155
         );
156
-        if (is_array($expectedValue)) {
157
-            return is_array($optionValue)
158
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
159
-                : !in_array($optionValue, $expectedValue);
156
+        if( is_array( $expectedValue ) ) {
157
+            return is_array( $optionValue )
158
+                ? 0 === count( array_intersect( $optionValue, $expectedValue ) )
159
+                : !in_array( $optionValue, $expectedValue );
160 160
         }
161 161
         return $optionValue != $expectedValue;
162 162
     }
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
     /**
165 165
      * @return bool
166 166
      */
167
-    protected function isMultiDependency($path)
167
+    protected function isMultiDependency( $path )
168 168
     {
169
-        if (isset($this->settings[$path])) {
169
+        if( isset($this->settings[$path]) ) {
170 170
             $field = $this->settings[$path];
171 171
             return ('checkbox' == $field['type'] && !empty($field['options']))
172 172
                 || !empty($field['multiple']);
@@ -177,32 +177,32 @@  discard block
 block discarded – undo
177 177
     /**
178 178
      * @return array
179 179
      */
180
-    protected function normalize(array $field)
180
+    protected function normalize( array $field )
181 181
     {
182
-        $field = $this->normalizeDependsOn($field);
183
-        $field = $this->normalizeLabelAndLegend($field);
184
-        $field = $this->normalizeValue($field);
182
+        $field = $this->normalizeDependsOn( $field );
183
+        $field = $this->normalizeLabelAndLegend( $field );
184
+        $field = $this->normalizeValue( $field );
185 185
         return $field;
186 186
     }
187 187
 
188 188
     /**
189 189
      * @return array
190 190
      */
191
-    protected function normalizeDependsOn(array $field)
191
+    protected function normalizeDependsOn( array $field )
192 192
     {
193
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
193
+        if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) {
194 194
             $isFieldHidden = false;
195 195
             $conditions = [];
196
-            foreach ($field['depends_on'] as $path => $value) {
196
+            foreach( $field['depends_on'] as $path => $value ) {
197 197
                 $conditions[] = [
198
-                    'name' => $this->getFieldNameForDependsOn($path),
198
+                    'name' => $this->getFieldNameForDependsOn( $path ),
199 199
                     'value' => $value,
200 200
                 ];
201
-                if ($this->isFieldHidden($path, $value)) {
201
+                if( $this->isFieldHidden( $path, $value ) ) {
202 202
                     $isFieldHidden = true;
203 203
                 }
204 204
             }
205
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
205
+            $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT );
206 206
             $field['is_hidden'] = $isFieldHidden;
207 207
         }
208 208
         return $field;
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
     /**
212 212
      * @return array
213 213
      */
214
-    protected function normalizeLabelAndLegend(array $field)
214
+    protected function normalizeLabelAndLegend( array $field )
215 215
     {
216
-        if (!empty($field['label'])) {
216
+        if( !empty($field['label']) ) {
217 217
             $field['legend'] = $field['label'];
218 218
             unset($field['label']);
219 219
         } else {
220 220
             $field['is_valid'] = false;
221
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
221
+            glsr_log()->warning( 'Setting field is missing a label' )->debug( $field );
222 222
         }
223 223
         return $field;
224 224
     }
@@ -226,12 +226,12 @@  discard block
 block discarded – undo
226 226
     /**
227 227
      * @return array
228 228
      */
229
-    protected function normalizeValue(array $field)
229
+    protected function normalizeValue( array $field )
230 230
     {
231
-        if (!isset($field['value'])) {
232
-            $field['value'] = glsr(OptionManager::class)->get(
231
+        if( !isset($field['value']) ) {
232
+            $field['value'] = glsr( OptionManager::class )->get(
233 233
                 $field['name'],
234
-                $this->getFieldDefault($field)
234
+                $this->getFieldDefault( $field )
235 235
             );
236 236
         }
237 237
         return $field;
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
     /**
241 241
      * @return string
242 242
      */
243
-    protected function normalizeSettingPath($path)
243
+    protected function normalizeSettingPath( $path )
244 244
     {
245
-        return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.');
245
+        return glsr( Helper::class )->prefixString( rtrim( $path, '.' ), 'settings.' );
246 246
     }
247 247
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Builder.php 2 patches
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 = glsr(Helper::class)->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 = glsr(Helper::class)->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.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -61,18 +61,18 @@  discard block
 block discarded – undo
61 61
      * @param array $args
62 62
      * @return string|void
63 63
      */
64
-    public function __call($method, $args)
64
+    public function __call( $method, $args )
65 65
     {
66 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)
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 72
             ? $instance->buildTag()
73 73
             : $instance->buildCustomField();
74
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
-        if (!$this->render) {
74
+        $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance );
75
+        if( !$this->render ) {
76 76
             return $generatedTag;
77 77
         }
78 78
         echo $generatedTag;
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
      * @param mixed $value
84 84
      * @return void
85 85
      */
86
-    public function __set($property, $value)
86
+    public function __set( $property, $value )
87 87
     {
88 88
         $properties = [
89 89
             'args' => 'is_array',
90 90
             'render' => 'is_bool',
91 91
             'tag' => 'is_string',
92 92
         ];
93
-        if (!isset($properties[$property])
94
-            || empty(array_filter([$value], $properties[$property]))
93
+        if( !isset($properties[$property])
94
+            || empty(array_filter( [$value], $properties[$property] ))
95 95
         ) {
96 96
             return;
97 97
         }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function getClosingTag()
105 105
     {
106
-        if (empty($this->tag)) {
106
+        if( empty($this->tag) ) {
107 107
             return;
108 108
         }
109 109
         return '</'.$this->tag.'>';
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function getOpeningTag()
116 116
     {
117
-        if (empty($this->tag)) {
117
+        if( empty($this->tag) ) {
118 118
             return;
119 119
         }
120
-        $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
-        return '<'.trim($this->tag.' '.$attributes).'>';
120
+        $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString();
121
+        return '<'.trim( $this->tag.' '.$attributes ).'>';
122 122
     }
123 123
 
124 124
     /**
@@ -126,19 +126,19 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function getTag()
128 128
     {
129
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
129
+        if( in_array( $this->tag, static::TAGS_SINGLE ) ) {
130 130
             return $this->getOpeningTag();
131 131
         }
132
-        if (!in_array($this->tag, static::TAGS_FORM)) {
132
+        if( !in_array( $this->tag, static::TAGS_FORM ) ) {
133 133
             return $this->buildDefaultTag();
134 134
         }
135
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
135
+        return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription();
136 136
     }
137 137
 
138 138
     /**
139 139
      * @return string
140 140
      */
141
-    public function raw(array $field)
141
+    public function raw( array $field )
142 142
     {
143 143
         unset($field['label']);
144 144
         return $this->{$field['type']}($field);
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
     protected function buildCustomField()
151 151
     {
152 152
         $className = $this->getCustomFieldClassName();
153
-        if (class_exists($className)) {
154
-            return (new $className($this))->build();
153
+        if( class_exists( $className ) ) {
154
+            return (new $className( $this ))->build();
155 155
         }
156
-        glsr_log()->error('Field missing: '.$className);
156
+        glsr_log()->error( 'Field missing: '.$className );
157 157
     }
158 158
 
159 159
     /**
160 160
      * @return string|void
161 161
      */
162
-    protected function buildDefaultTag($text = '')
162
+    protected function buildDefaultTag( $text = '' )
163 163
     {
164
-        if (empty($text)) {
164
+        if( empty($text) ) {
165 165
             $text = $this->args['text'];
166 166
         }
167 167
         return $this->getOpeningTag().$text.$this->getClosingTag();
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
      */
173 173
     protected function buildFieldDescription()
174 174
     {
175
-        if (empty($this->args['description'])) {
175
+        if( empty($this->args['description']) ) {
176 176
             return;
177 177
         }
178
-        if ($this->args['is_widget']) {
179
-            return $this->small($this->args['description']);
178
+        if( $this->args['is_widget'] ) {
179
+            return $this->small( $this->args['description'] );
180 180
         }
181
-        return $this->p($this->args['description'], ['class' => 'description']);
181
+        return $this->p( $this->args['description'], ['class' => 'description'] );
182 182
     }
183 183
 
184 184
     /**
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
      */
187 187
     protected function buildFormInput()
188 188
     {
189
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
-            if (isset($this->args['multiple'])) {
191
-                $this->args['name'].= '[]';
189
+        if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) {
190
+            if( isset($this->args['multiple']) ) {
191
+                $this->args['name'] .= '[]';
192 192
             }
193 193
             return $this->buildFormLabel().$this->getOpeningTag();
194 194
         }
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
      */
203 203
     protected function buildFormInputChoice()
204 204
     {
205
-        if (!empty($this->args['text'])) {
205
+        if( !empty($this->args['text']) ) {
206 206
             $this->args['label'] = $this->args['text'];
207 207
         }
208
-        if (!$this->args['is_public']) {
209
-            return $this->buildFormLabel([
208
+        if( !$this->args['is_public'] ) {
209
+            return $this->buildFormLabel( [
210 210
                 'class' => 'glsr-'.$this->args['type'].'-label',
211 211
                 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
-            ]);
212
+            ] );
213 213
         }
214
-        return $this->getOpeningTag().$this->buildFormLabel([
214
+        return $this->getOpeningTag().$this->buildFormLabel( [
215 215
             'class' => 'glsr-'.$this->args['type'].'-label',
216 216
             'text' => $this->args['label'].'<span></span>',
217
-        ]);
217
+        ] );
218 218
     }
219 219
 
220 220
     /**
@@ -222,39 +222,39 @@  discard block
 block discarded – undo
222 222
      */
223 223
     protected function buildFormInputMultiChoice()
224 224
     {
225
-        if ('checkbox' == $this->args['type']) {
226
-            $this->args['name'].= '[]';
225
+        if( 'checkbox' == $this->args['type'] ) {
226
+            $this->args['name'] .= '[]';
227 227
         }
228 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']),
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 232
                 'id' => $this->args['id'].'-'.$index++,
233 233
                 'name' => $this->args['name'],
234 234
                 'text' => $this->args['options'][$key],
235 235
                 'value' => $key,
236
-            ]));
236
+            ]) );
237 237
         });
238
-        return $this->ul($options, [
238
+        return $this->ul( $options, [
239 239
             'class' => $this->args['class'],
240 240
             'id' => $this->args['id'],
241
-        ]);
241
+        ] );
242 242
     }
243 243
 
244 244
     /**
245 245
      * @return void|string
246 246
      */
247
-    protected function buildFormLabel(array $customArgs = [])
247
+    protected function buildFormLabel( array $customArgs = [] )
248 248
     {
249
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
249
+        if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) {
250 250
             return;
251 251
         }
252
-        return $this->label(wp_parse_args($customArgs, [
252
+        return $this->label( wp_parse_args( $customArgs, [
253 253
             'for' => $this->args['id'],
254 254
             'is_public' => $this->args['is_public'],
255 255
             'text' => $this->args['label'],
256 256
             'type' => $this->args['type'],
257
-        ]));
257
+        ] ) );
258 258
     }
259 259
 
260 260
     /**
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      */
263 263
     protected function buildFormSelect()
264 264
     {
265
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
265
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() );
266 266
     }
267 267
 
268 268
     /**
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
      */
271 271
     protected function buildFormSelectOptions()
272 272
     {
273
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
-            return $carry.$this->option([
273
+        return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) {
274
+            return $carry.$this->option( [
275 275
                 'selected' => $this->args['value'] == $key,
276 276
                 'text' => $this->args['options'][$key],
277 277
                 'value' => $key,
278
-            ]);
278
+            ] );
279 279
         });
280 280
     }
281 281
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      */
285 285
     protected function buildFormTextarea()
286 286
     {
287
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
287
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] );
288 288
     }
289 289
 
290 290
     /**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
      */
302 302
     protected function getCustomFieldClassName()
303 303
     {
304
-        $classname = glsr(Helper::class)->buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
304
+        $classname = glsr( Helper::class )->buildClassName( $this->tag, __NAMESPACE__.'\Fields' );
305
+        return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname );
306 306
     }
307 307
 
308 308
     /**
@@ -311,27 +311,27 @@  discard block
 block discarded – undo
311 311
     protected function mergeArgsWithRequiredDefaults()
312 312
     {
313 313
         $className = $this->getCustomFieldClassName();
314
-        if (class_exists($className)) {
315
-            $this->args = $className::merge($this->args);
314
+        if( class_exists( $className ) ) {
315
+            $this->args = $className::merge( $this->args );
316 316
         }
317
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
317
+        $this->args = glsr( BuilderDefaults::class )->merge( $this->args );
318 318
     }
319 319
 
320 320
     /**
321 321
      * @param string|array ...$params
322 322
      * @return void
323 323
      */
324
-    protected function normalize(...$params)
324
+    protected function normalize( ...$params )
325 325
     {
326
-        if (is_string($params[0]) || is_numeric($params[0])) {
327
-            $this->setNameOrTextAttributeForTag($params[0]);
326
+        if( is_string( $params[0] ) || is_numeric( $params[0] ) ) {
327
+            $this->setNameOrTextAttributeForTag( $params[0] );
328 328
         }
329
-        if (is_array($params[0])) {
329
+        if( is_array( $params[0] ) ) {
330 330
             $this->args += $params[0];
331
-        } elseif (is_array($params[1])) {
331
+        } elseif( is_array( $params[1] ) ) {
332 332
             $this->args += $params[1];
333 333
         }
334
-        if (!isset($this->args['is_public'])) {
334
+        if( !isset($this->args['is_public']) ) {
335 335
             $this->args['is_public'] = false;
336 336
         }
337 337
     }
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
      * @param string $value
341 341
      * @return void
342 342
      */
343
-    protected function setNameOrTextAttributeForTag($value)
343
+    protected function setNameOrTextAttributeForTag( $value )
344 344
     {
345
-        $attribute = in_array($this->tag, static::TAGS_FORM)
345
+        $attribute = in_array( $this->tag, static::TAGS_FORM )
346 346
             ? 'name'
347 347
             : 'text';
348 348
         $this->args[$attribute] = $value;
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
      * @param string $method
353 353
      * @return void
354 354
      */
355
-    protected function setTagFromMethod($method)
355
+    protected function setTagFromMethod( $method )
356 356
     {
357
-        $this->tag = strtolower($method);
358
-        if (in_array($this->tag, static::INPUT_TYPES)) {
357
+        $this->tag = strtolower( $method );
358
+        if( in_array( $this->tag, static::INPUT_TYPES ) ) {
359 359
             $this->args['type'] = $this->tag;
360 360
             $this->tag = 'input';
361 361
         }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviewsForm.php 2 patches
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -13,297 +13,297 @@
 block discarded – undo
13 13
 
14 14
 class SiteReviewsForm
15 15
 {
16
-    /**
17
-     * @var array
18
-     */
19
-    protected $args;
16
+	/**
17
+	 * @var array
18
+	 */
19
+	protected $args;
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    protected $errors;
21
+	/**
22
+	 * @var array
23
+	 */
24
+	protected $errors;
25 25
 
26
-    /**
27
-     * @var string
28
-     */
29
-    protected $message;
26
+	/**
27
+	 * @var string
28
+	 */
29
+	protected $message;
30 30
 
31
-    /**
32
-     * @var array
33
-     */
34
-    protected $required;
31
+	/**
32
+	 * @var array
33
+	 */
34
+	protected $required;
35 35
 
36
-    /**
37
-     * @var array
38
-     */
39
-    protected $values;
36
+	/**
37
+	 * @var array
38
+	 */
39
+	protected $values;
40 40
 
41
-    /**
42
-     * @return void|string
43
-     */
44
-    public function build(array $args = [])
45
-    {
46
-        $this->args = $args;
47
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
48
-            return $this->buildLoginRegister();
49
-        }
50
-        $this->errors = glsr(Session::class)->get($args['id'].'errors', [], true);
51
-        $this->message = glsr(Session::class)->get($args['id'].'message', '', true);
52
-        $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []);
53
-        $this->values = glsr(Session::class)->get($args['id'].'values', [], true);
54
-        $fields = array_reduce($this->getFields(), function ($carry, $field) {
55
-            return $carry.$field;
56
-        });
57
-        return glsr(Template::class)->build('templates/reviews-form', [
58
-            'args' => $args,
59
-            'context' => [
60
-                'class' => $this->getClass(),
61
-                'fields' => $fields,
62
-                'id' => $this->args['id'],
63
-                'response' => $this->buildResponse(),
64
-                'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(),
65
-            ],
66
-        ]);
67
-    }
41
+	/**
42
+	 * @return void|string
43
+	 */
44
+	public function build(array $args = [])
45
+	{
46
+		$this->args = $args;
47
+		if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
48
+			return $this->buildLoginRegister();
49
+		}
50
+		$this->errors = glsr(Session::class)->get($args['id'].'errors', [], true);
51
+		$this->message = glsr(Session::class)->get($args['id'].'message', '', true);
52
+		$this->required = glsr(OptionManager::class)->get('settings.submissions.required', []);
53
+		$this->values = glsr(Session::class)->get($args['id'].'values', [], true);
54
+		$fields = array_reduce($this->getFields(), function ($carry, $field) {
55
+			return $carry.$field;
56
+		});
57
+		return glsr(Template::class)->build('templates/reviews-form', [
58
+			'args' => $args,
59
+			'context' => [
60
+				'class' => $this->getClass(),
61
+				'fields' => $fields,
62
+				'id' => $this->args['id'],
63
+				'response' => $this->buildResponse(),
64
+				'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(),
65
+			],
66
+		]);
67
+	}
68 68
 
69
-    /**
70
-     * @return string
71
-     */
72
-    protected function buildLoginRegister()
73
-    {
74
-        return glsr(Template::class)->build('templates/login-register', [
75
-            'context' => [
76
-                'text' => trim($this->getLoginText().' '.$this->getRegisterText()),
77
-            ],
78
-        ]);
79
-    }
69
+	/**
70
+	 * @return string
71
+	 */
72
+	protected function buildLoginRegister()
73
+	{
74
+		return glsr(Template::class)->build('templates/login-register', [
75
+			'context' => [
76
+				'text' => trim($this->getLoginText().' '.$this->getRegisterText()),
77
+			],
78
+		]);
79
+	}
80 80
 
81
-    /**
82
-     * @return void|string
83
-     */
84
-    protected function buildRecaptcha()
85
-    {
86
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
87
-            return;
88
-        }
89
-        return glsr(Builder::class)->div([
90
-            'class' => 'glsr-recaptcha-holder',
91
-            'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'),
92
-            'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')),
93
-            'data-size' => 'invisible',
94
-        ]);
95
-    }
81
+	/**
82
+	 * @return void|string
83
+	 */
84
+	protected function buildRecaptcha()
85
+	{
86
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
87
+			return;
88
+		}
89
+		return glsr(Builder::class)->div([
90
+			'class' => 'glsr-recaptcha-holder',
91
+			'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'),
92
+			'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')),
93
+			'data-size' => 'invisible',
94
+		]);
95
+	}
96 96
 
97
-    /**
98
-     * @return string
99
-     */
100
-    protected function buildResponse()
101
-    {
102
-        $classes = !empty($this->errors)
103
-            ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class']
104
-            : '';
105
-        return glsr(Template::class)->build('templates/form/response', [
106
-            'context' => [
107
-                'class' => $classes,
108
-                'message' => wpautop($this->message),
109
-            ],
110
-            'has_errors' => !empty($this->errors),
111
-        ]);
112
-    }
97
+	/**
98
+	 * @return string
99
+	 */
100
+	protected function buildResponse()
101
+	{
102
+		$classes = !empty($this->errors)
103
+			? glsr(StyleValidationDefaults::class)->defaults()['message_error_class']
104
+			: '';
105
+		return glsr(Template::class)->build('templates/form/response', [
106
+			'context' => [
107
+				'class' => $classes,
108
+				'message' => wpautop($this->message),
109
+			],
110
+			'has_errors' => !empty($this->errors),
111
+		]);
112
+	}
113 113
 
114
-    /**
115
-     * @return string
116
-     */
117
-    protected function buildSubmitButton()
118
-    {
119
-        return glsr(Template::class)->build('templates/form/submit-button', [
120
-            'context' => [
121
-                'text' => __('Submit your review', 'site-reviews'),
122
-            ],
123
-        ]);
124
-    }
114
+	/**
115
+	 * @return string
116
+	 */
117
+	protected function buildSubmitButton()
118
+	{
119
+		return glsr(Template::class)->build('templates/form/submit-button', [
120
+			'context' => [
121
+				'text' => __('Submit your review', 'site-reviews'),
122
+			],
123
+		]);
124
+	}
125 125
 
126
-    /**
127
-     * @return string
128
-     */
129
-    protected function getClass()
130
-    {
131
-        return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']);
132
-    }
126
+	/**
127
+	 * @return string
128
+	 */
129
+	protected function getClass()
130
+	{
131
+		return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']);
132
+	}
133 133
 
134
-    /**
135
-     * @return array
136
-     */
137
-    protected function getFields()
138
-    {
139
-        $hiddenFields = $this->getHiddenFields();
140
-        $hiddenFields[] = $this->getHoneypotField();
141
-        $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form'));
142
-        $paths = array_map(function ($obj) {
143
-            return $obj->field['path'];
144
-        }, $hiddenFields);
145
-        foreach ($fields as $field) {
146
-            $index = array_search($field->field['path'], $paths);
147
-            if (false === $index) {
148
-                continue;
149
-            }
150
-            unset($hiddenFields[$index]);
151
-        }
152
-        return array_merge($hiddenFields, $fields);
153
-    }
134
+	/**
135
+	 * @return array
136
+	 */
137
+	protected function getFields()
138
+	{
139
+		$hiddenFields = $this->getHiddenFields();
140
+		$hiddenFields[] = $this->getHoneypotField();
141
+		$fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form'));
142
+		$paths = array_map(function ($obj) {
143
+			return $obj->field['path'];
144
+		}, $hiddenFields);
145
+		foreach ($fields as $field) {
146
+			$index = array_search($field->field['path'], $paths);
147
+			if (false === $index) {
148
+				continue;
149
+			}
150
+			unset($hiddenFields[$index]);
151
+		}
152
+		return array_merge($hiddenFields, $fields);
153
+	}
154 154
 
155
-    /**
156
-     * @return string
157
-     */
158
-    protected function getLoginText()
159
-    {
160
-        $loginLink = glsr(Builder::class)->a([
161
-            'href' => wp_login_url(strval(get_permalink())),
162
-            'text' => __('logged in', 'site-reviews'),
163
-        ]);
164
-        return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink);
165
-    }
155
+	/**
156
+	 * @return string
157
+	 */
158
+	protected function getLoginText()
159
+	{
160
+		$loginLink = glsr(Builder::class)->a([
161
+			'href' => wp_login_url(strval(get_permalink())),
162
+			'text' => __('logged in', 'site-reviews'),
163
+		]);
164
+		return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink);
165
+	}
166 166
 
167
-    /**
168
-     * @return void|string
169
-     */
170
-    protected function getRegisterText()
171
-    {
172
-        if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) {
173
-            return;
174
-        }
175
-        $registerLink = glsr(Builder::class)->a([
176
-            'href' => wp_registration_url(),
177
-            'text' => __('register', 'site-reviews'),
178
-        ]);
179
-        return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink);
180
-    }
167
+	/**
168
+	 * @return void|string
169
+	 */
170
+	protected function getRegisterText()
171
+	{
172
+		if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) {
173
+			return;
174
+		}
175
+		$registerLink = glsr(Builder::class)->a([
176
+			'href' => wp_registration_url(),
177
+			'text' => __('register', 'site-reviews'),
178
+		]);
179
+		return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink);
180
+	}
181 181
 
182
-    /**
183
-     * @return array
184
-     */
185
-    protected function getHiddenFields()
186
-    {
187
-        $fields = [[
188
-            'name' => '_action',
189
-            'value' => 'submit-review',
190
-        ], [
191
-            'name' => '_counter',
192
-        ], [
193
-            'name' => '_nonce',
194
-            'value' => wp_create_nonce('submit-review'),
195
-        ], [
196
-            'name' => '_post_id',
197
-            'value' => get_the_ID(),
198
-        ], [
199
-            'name' => '_referer',
200
-            'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')),
201
-        ], [
202
-            'name' => 'assign_to',
203
-            'value' => $this->args['assign_to'],
204
-        ], [
205
-            'name' => 'category',
206
-            'value' => $this->args['category'],
207
-        ], [
208
-            'name' => 'excluded',
209
-            'value' => $this->args['hide'],
210
-        ], [
211
-            'name' => 'form_id',
212
-            'value' => $this->args['id'],
213
-        ]];
214
-        return array_map(function ($field) {
215
-            return new Field(wp_parse_args($field, ['type' => 'hidden']));
216
-        }, $fields);
217
-    }
182
+	/**
183
+	 * @return array
184
+	 */
185
+	protected function getHiddenFields()
186
+	{
187
+		$fields = [[
188
+			'name' => '_action',
189
+			'value' => 'submit-review',
190
+		], [
191
+			'name' => '_counter',
192
+		], [
193
+			'name' => '_nonce',
194
+			'value' => wp_create_nonce('submit-review'),
195
+		], [
196
+			'name' => '_post_id',
197
+			'value' => get_the_ID(),
198
+		], [
199
+			'name' => '_referer',
200
+			'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')),
201
+		], [
202
+			'name' => 'assign_to',
203
+			'value' => $this->args['assign_to'],
204
+		], [
205
+			'name' => 'category',
206
+			'value' => $this->args['category'],
207
+		], [
208
+			'name' => 'excluded',
209
+			'value' => $this->args['hide'],
210
+		], [
211
+			'name' => 'form_id',
212
+			'value' => $this->args['id'],
213
+		]];
214
+		return array_map(function ($field) {
215
+			return new Field(wp_parse_args($field, ['type' => 'hidden']));
216
+		}, $fields);
217
+	}
218 218
 
219
-    /**
220
-     * @return Field
221
-     */
222
-    protected function getHoneypotField()
223
-    {
224
-        return new Field([
225
-            'name' => 'gotcha',
226
-            'type' => 'honeypot',
227
-        ]);
228
-    }
219
+	/**
220
+	 * @return Field
221
+	 */
222
+	protected function getHoneypotField()
223
+	{
224
+		return new Field([
225
+			'name' => 'gotcha',
226
+			'type' => 'honeypot',
227
+		]);
228
+	}
229 229
 
230
-    /**
231
-     * @return void
232
-     */
233
-    protected function normalizeFieldId(Field &$field)
234
-    {
235
-        if (empty($this->args['id']) || empty($field->field['id'])) {
236
-            return;
237
-        }
238
-        $field->field['id'].= '-'.$this->args['id'];
239
-    }
230
+	/**
231
+	 * @return void
232
+	 */
233
+	protected function normalizeFieldId(Field &$field)
234
+	{
235
+		if (empty($this->args['id']) || empty($field->field['id'])) {
236
+			return;
237
+		}
238
+		$field->field['id'].= '-'.$this->args['id'];
239
+	}
240 240
 
241
-    /**
242
-     * @return void
243
-     */
244
-    protected function normalizeFieldClass(Field &$field)
245
-    {
246
-        if (!isset($field->field['class'])) {
247
-            $field->field['class'] = '';
248
-        }
249
-        $field->field['class'] = trim($field->field['class'].' glsr-field-control');
250
-    }
241
+	/**
242
+	 * @return void
243
+	 */
244
+	protected function normalizeFieldClass(Field &$field)
245
+	{
246
+		if (!isset($field->field['class'])) {
247
+			$field->field['class'] = '';
248
+		}
249
+		$field->field['class'] = trim($field->field['class'].' glsr-field-control');
250
+	}
251 251
 
252
-    /**
253
-     * @return void
254
-     */
255
-    protected function normalizeFieldErrors(Field &$field)
256
-    {
257
-        if (!array_key_exists($field->field['path'], $this->errors)) {
258
-            return;
259
-        }
260
-        $field->field['errors'] = $this->errors[$field->field['path']];
261
-    }
252
+	/**
253
+	 * @return void
254
+	 */
255
+	protected function normalizeFieldErrors(Field &$field)
256
+	{
257
+		if (!array_key_exists($field->field['path'], $this->errors)) {
258
+			return;
259
+		}
260
+		$field->field['errors'] = $this->errors[$field->field['path']];
261
+	}
262 262
 
263
-    /**
264
-     * @return void
265
-     */
266
-    protected function normalizeFieldRequired(Field &$field)
267
-    {
268
-        if (!in_array($field->field['path'], $this->required)) {
269
-            return;
270
-        }
271
-        $field->field['required'] = true;
272
-    }
263
+	/**
264
+	 * @return void
265
+	 */
266
+	protected function normalizeFieldRequired(Field &$field)
267
+	{
268
+		if (!in_array($field->field['path'], $this->required)) {
269
+			return;
270
+		}
271
+		$field->field['required'] = true;
272
+	}
273 273
 
274
-    /**
275
-     * @return array
276
-     */
277
-    protected function normalizeFields($fields)
278
-    {
279
-        $normalizedFields = [];
280
-        foreach ($fields as $field) {
281
-            if (in_array($field->field['path'], $this->args['hide'])) {
282
-                continue;
283
-            }
284
-            $field->field['is_public'] = true;
285
-            $this->normalizeFieldClass($field);
286
-            $this->normalizeFieldErrors($field);
287
-            $this->normalizeFieldRequired($field);
288
-            $this->normalizeFieldValue($field);
289
-            $this->normalizeFieldId($field);
290
-            $normalizedFields[] = $field;
291
-        }
292
-        return $normalizedFields;
293
-    }
274
+	/**
275
+	 * @return array
276
+	 */
277
+	protected function normalizeFields($fields)
278
+	{
279
+		$normalizedFields = [];
280
+		foreach ($fields as $field) {
281
+			if (in_array($field->field['path'], $this->args['hide'])) {
282
+				continue;
283
+			}
284
+			$field->field['is_public'] = true;
285
+			$this->normalizeFieldClass($field);
286
+			$this->normalizeFieldErrors($field);
287
+			$this->normalizeFieldRequired($field);
288
+			$this->normalizeFieldValue($field);
289
+			$this->normalizeFieldId($field);
290
+			$normalizedFields[] = $field;
291
+		}
292
+		return $normalizedFields;
293
+	}
294 294
 
295
-    /**
296
-     * @return void
297
-     */
298
-    protected function normalizeFieldValue(Field &$field)
299
-    {
300
-        if (!array_key_exists($field->field['path'], $this->values)) {
301
-            return;
302
-        }
303
-        if (in_array($field->field['type'], ['radio', 'checkbox'])) {
304
-            $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
305
-        } else {
306
-            $field->field['value'] = $this->values[$field->field['path']];
307
-        }
308
-    }
295
+	/**
296
+	 * @return void
297
+	 */
298
+	protected function normalizeFieldValue(Field &$field)
299
+	{
300
+		if (!array_key_exists($field->field['path'], $this->values)) {
301
+			return;
302
+		}
303
+		if (in_array($field->field['type'], ['radio', 'checkbox'])) {
304
+			$field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
305
+		} else {
306
+			$field->field['value'] = $this->values[$field->field['path']];
307
+		}
308
+	}
309 309
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -41,20 +41,20 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * @return void|string
43 43
      */
44
-    public function build(array $args = [])
44
+    public function build( array $args = [] )
45 45
     {
46 46
         $this->args = $args;
47
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
47
+        if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) {
48 48
             return $this->buildLoginRegister();
49 49
         }
50
-        $this->errors = glsr(Session::class)->get($args['id'].'errors', [], true);
51
-        $this->message = glsr(Session::class)->get($args['id'].'message', '', true);
52
-        $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []);
53
-        $this->values = glsr(Session::class)->get($args['id'].'values', [], true);
54
-        $fields = array_reduce($this->getFields(), function ($carry, $field) {
50
+        $this->errors = glsr( Session::class )->get( $args['id'].'errors', [], true );
51
+        $this->message = glsr( Session::class )->get( $args['id'].'message', '', true );
52
+        $this->required = glsr( OptionManager::class )->get( 'settings.submissions.required', [] );
53
+        $this->values = glsr( Session::class )->get( $args['id'].'values', [], true );
54
+        $fields = array_reduce( $this->getFields(), function( $carry, $field ) {
55 55
             return $carry.$field;
56 56
         });
57
-        return glsr(Template::class)->build('templates/reviews-form', [
57
+        return glsr( Template::class )->build( 'templates/reviews-form', [
58 58
             'args' => $args,
59 59
             'context' => [
60 60
                 'class' => $this->getClass(),
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
                 'response' => $this->buildResponse(),
64 64
                 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(),
65 65
             ],
66
-        ]);
66
+        ] );
67 67
     }
68 68
 
69 69
     /**
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
      */
72 72
     protected function buildLoginRegister()
73 73
     {
74
-        return glsr(Template::class)->build('templates/login-register', [
74
+        return glsr( Template::class )->build( 'templates/login-register', [
75 75
             'context' => [
76
-                'text' => trim($this->getLoginText().' '.$this->getRegisterText()),
76
+                'text' => trim( $this->getLoginText().' '.$this->getRegisterText() ),
77 77
             ],
78
-        ]);
78
+        ] );
79 79
     }
80 80
 
81 81
     /**
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
      */
84 84
     protected function buildRecaptcha()
85 85
     {
86
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
86
+        if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) {
87 87
             return;
88 88
         }
89
-        return glsr(Builder::class)->div([
89
+        return glsr( Builder::class )->div( [
90 90
             'class' => 'glsr-recaptcha-holder',
91
-            'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'),
92
-            'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')),
91
+            'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ),
92
+            'data-sitekey' => sanitize_text_field( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.key' ) ),
93 93
             'data-size' => 'invisible',
94
-        ]);
94
+        ] );
95 95
     }
96 96
 
97 97
     /**
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
     protected function buildResponse()
101 101
     {
102 102
         $classes = !empty($this->errors)
103
-            ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class']
103
+            ? glsr( StyleValidationDefaults::class )->defaults()['message_error_class']
104 104
             : '';
105
-        return glsr(Template::class)->build('templates/form/response', [
105
+        return glsr( Template::class )->build( 'templates/form/response', [
106 106
             'context' => [
107 107
                 'class' => $classes,
108
-                'message' => wpautop($this->message),
108
+                'message' => wpautop( $this->message ),
109 109
             ],
110 110
             'has_errors' => !empty($this->errors),
111
-        ]);
111
+        ] );
112 112
     }
113 113
 
114 114
     /**
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
      */
117 117
     protected function buildSubmitButton()
118 118
     {
119
-        return glsr(Template::class)->build('templates/form/submit-button', [
119
+        return glsr( Template::class )->build( 'templates/form/submit-button', [
120 120
             'context' => [
121
-                'text' => __('Submit your review', 'site-reviews'),
121
+                'text' => __( 'Submit your review', 'site-reviews' ),
122 122
             ],
123
-        ]);
123
+        ] );
124 124
     }
125 125
 
126 126
     /**
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      */
129 129
     protected function getClass()
130 130
     {
131
-        return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']);
131
+        return trim( 'glsr-form glsr-'.glsr( Style::class )->get().' '.$this->args['class'] );
132 132
     }
133 133
 
134 134
     /**
@@ -138,18 +138,18 @@  discard block
 block discarded – undo
138 138
     {
139 139
         $hiddenFields = $this->getHiddenFields();
140 140
         $hiddenFields[] = $this->getHoneypotField();
141
-        $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form'));
142
-        $paths = array_map(function ($obj) {
141
+        $fields = $this->normalizeFields( glsr( Form::class )->getFields( 'submission-form' ) );
142
+        $paths = array_map( function( $obj ) {
143 143
             return $obj->field['path'];
144
-        }, $hiddenFields);
145
-        foreach ($fields as $field) {
146
-            $index = array_search($field->field['path'], $paths);
147
-            if (false === $index) {
144
+        }, $hiddenFields );
145
+        foreach( $fields as $field ) {
146
+            $index = array_search( $field->field['path'], $paths );
147
+            if( false === $index ) {
148 148
                 continue;
149 149
             }
150 150
             unset($hiddenFields[$index]);
151 151
         }
152
-        return array_merge($hiddenFields, $fields);
152
+        return array_merge( $hiddenFields, $fields );
153 153
     }
154 154
 
155 155
     /**
@@ -157,11 +157,11 @@  discard block
 block discarded – undo
157 157
      */
158 158
     protected function getLoginText()
159 159
     {
160
-        $loginLink = glsr(Builder::class)->a([
161
-            'href' => wp_login_url(strval(get_permalink())),
162
-            'text' => __('logged in', 'site-reviews'),
163
-        ]);
164
-        return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink);
160
+        $loginLink = glsr( Builder::class )->a( [
161
+            'href' => wp_login_url( strval( get_permalink() ) ),
162
+            'text' => __( 'logged in', 'site-reviews' ),
163
+        ] );
164
+        return sprintf( __( 'You must be %s to submit a review.', 'site-reviews' ), $loginLink );
165 165
     }
166 166
 
167 167
     /**
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
      */
170 170
     protected function getRegisterText()
171 171
     {
172
-        if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) {
172
+        if( !get_option( 'users_can_register' ) || !glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) {
173 173
             return;
174 174
         }
175
-        $registerLink = glsr(Builder::class)->a([
175
+        $registerLink = glsr( Builder::class )->a( [
176 176
             'href' => wp_registration_url(),
177
-            'text' => __('register', 'site-reviews'),
178
-        ]);
179
-        return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink);
177
+            'text' => __( 'register', 'site-reviews' ),
178
+        ] );
179
+        return sprintf( __( 'You may also %s for an account.', 'site-reviews' ), $registerLink );
180 180
     }
181 181
 
182 182
     /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
             'name' => '_counter',
192 192
         ], [
193 193
             'name' => '_nonce',
194
-            'value' => wp_create_nonce('submit-review'),
194
+            'value' => wp_create_nonce( 'submit-review' ),
195 195
         ], [
196 196
             'name' => '_post_id',
197 197
             'value' => get_the_ID(),
198 198
         ], [
199 199
             'name' => '_referer',
200
-            'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')),
200
+            'value' => wp_unslash( filter_input( INPUT_SERVER, 'REQUEST_URI' ) ),
201 201
         ], [
202 202
             'name' => 'assign_to',
203 203
             'value' => $this->args['assign_to'],
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
             'name' => 'form_id',
212 212
             'value' => $this->args['id'],
213 213
         ]];
214
-        return array_map(function ($field) {
215
-            return new Field(wp_parse_args($field, ['type' => 'hidden']));
216
-        }, $fields);
214
+        return array_map( function( $field ) {
215
+            return new Field( wp_parse_args( $field, ['type' => 'hidden'] ) );
216
+        }, $fields );
217 217
     }
218 218
 
219 219
     /**
@@ -221,40 +221,40 @@  discard block
 block discarded – undo
221 221
      */
222 222
     protected function getHoneypotField()
223 223
     {
224
-        return new Field([
224
+        return new Field( [
225 225
             'name' => 'gotcha',
226 226
             'type' => 'honeypot',
227
-        ]);
227
+        ] );
228 228
     }
229 229
 
230 230
     /**
231 231
      * @return void
232 232
      */
233
-    protected function normalizeFieldId(Field &$field)
233
+    protected function normalizeFieldId( Field &$field )
234 234
     {
235
-        if (empty($this->args['id']) || empty($field->field['id'])) {
235
+        if( empty($this->args['id']) || empty($field->field['id']) ) {
236 236
             return;
237 237
         }
238
-        $field->field['id'].= '-'.$this->args['id'];
238
+        $field->field['id'] .= '-'.$this->args['id'];
239 239
     }
240 240
 
241 241
     /**
242 242
      * @return void
243 243
      */
244
-    protected function normalizeFieldClass(Field &$field)
244
+    protected function normalizeFieldClass( Field &$field )
245 245
     {
246
-        if (!isset($field->field['class'])) {
246
+        if( !isset($field->field['class']) ) {
247 247
             $field->field['class'] = '';
248 248
         }
249
-        $field->field['class'] = trim($field->field['class'].' glsr-field-control');
249
+        $field->field['class'] = trim( $field->field['class'].' glsr-field-control' );
250 250
     }
251 251
 
252 252
     /**
253 253
      * @return void
254 254
      */
255
-    protected function normalizeFieldErrors(Field &$field)
255
+    protected function normalizeFieldErrors( Field &$field )
256 256
     {
257
-        if (!array_key_exists($field->field['path'], $this->errors)) {
257
+        if( !array_key_exists( $field->field['path'], $this->errors ) ) {
258 258
             return;
259 259
         }
260 260
         $field->field['errors'] = $this->errors[$field->field['path']];
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
     /**
264 264
      * @return void
265 265
      */
266
-    protected function normalizeFieldRequired(Field &$field)
266
+    protected function normalizeFieldRequired( Field &$field )
267 267
     {
268
-        if (!in_array($field->field['path'], $this->required)) {
268
+        if( !in_array( $field->field['path'], $this->required ) ) {
269 269
             return;
270 270
         }
271 271
         $field->field['required'] = true;
@@ -274,19 +274,19 @@  discard block
 block discarded – undo
274 274
     /**
275 275
      * @return array
276 276
      */
277
-    protected function normalizeFields($fields)
277
+    protected function normalizeFields( $fields )
278 278
     {
279 279
         $normalizedFields = [];
280
-        foreach ($fields as $field) {
281
-            if (in_array($field->field['path'], $this->args['hide'])) {
280
+        foreach( $fields as $field ) {
281
+            if( in_array( $field->field['path'], $this->args['hide'] ) ) {
282 282
                 continue;
283 283
             }
284 284
             $field->field['is_public'] = true;
285
-            $this->normalizeFieldClass($field);
286
-            $this->normalizeFieldErrors($field);
287
-            $this->normalizeFieldRequired($field);
288
-            $this->normalizeFieldValue($field);
289
-            $this->normalizeFieldId($field);
285
+            $this->normalizeFieldClass( $field );
286
+            $this->normalizeFieldErrors( $field );
287
+            $this->normalizeFieldRequired( $field );
288
+            $this->normalizeFieldValue( $field );
289
+            $this->normalizeFieldId( $field );
290 290
             $normalizedFields[] = $field;
291 291
         }
292 292
         return $normalizedFields;
@@ -295,12 +295,12 @@  discard block
 block discarded – undo
295 295
     /**
296 296
      * @return void
297 297
      */
298
-    protected function normalizeFieldValue(Field &$field)
298
+    protected function normalizeFieldValue( Field &$field )
299 299
     {
300
-        if (!array_key_exists($field->field['path'], $this->values)) {
300
+        if( !array_key_exists( $field->field['path'], $this->values ) ) {
301 301
             return;
302 302
         }
303
-        if (in_array($field->field['type'], ['radio', 'checkbox'])) {
303
+        if( in_array( $field->field['type'], ['radio', 'checkbox'] ) ) {
304 304
             $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
305 305
         } else {
306 306
             $field->field['value'] = $this->values[$field->field['path']];
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 2 patches
Indentation   +347 added lines, -347 removed lines patch added patch discarded remove patch
@@ -19,376 +19,376 @@
 block discarded – undo
19 19
 
20 20
 class SiteReviews
21 21
 {
22
-    /**
23
-     * @var array
24
-     */
25
-    public $args;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	public $args;
26 26
 
27
-    /**
28
-     * @var Review
29
-     */
30
-    public $current;
27
+	/**
28
+	 * @var Review
29
+	 */
30
+	public $current;
31 31
 
32
-    /**
33
-     * @var array
34
-     */
35
-    public $options;
32
+	/**
33
+	 * @var array
34
+	 */
35
+	public $options;
36 36
 
37
-    /**
38
-     * @var Reviews
39
-     */
40
-    protected $reviews;
37
+	/**
38
+	 * @var Reviews
39
+	 */
40
+	protected $reviews;
41 41
 
42
-    /**
43
-     * @param Reviews|null $reviews
44
-     * @return ReviewsHtml
45
-     */
46
-    public function build(array $args = [], $reviews = null)
47
-    {
48
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
49
-        $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all());
50
-        $this->reviews = $reviews instanceof Reviews
51
-            ? $reviews
52
-            : glsr(ReviewManager::class)->get($args);
53
-        $this->generateSchema();
54
-        return $this->buildReviews();
55
-    }
42
+	/**
43
+	 * @param Reviews|null $reviews
44
+	 * @return ReviewsHtml
45
+	 */
46
+	public function build(array $args = [], $reviews = null)
47
+	{
48
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
49
+		$this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all());
50
+		$this->reviews = $reviews instanceof Reviews
51
+			? $reviews
52
+			: glsr(ReviewManager::class)->get($args);
53
+		$this->generateSchema();
54
+		return $this->buildReviews();
55
+	}
56 56
 
57
-    /**
58
-     * @return ReviewHtml
59
-     */
60
-    public function buildReview(Review $review)
61
-    {
62
-        $review = apply_filters('site-reviews/review/build/before', $review);
63
-        $this->current = $review;
64
-        $renderedFields = [];
65
-        foreach ($review as $key => $value) {
66
-            $method = glsr(Helper::class)->buildMethodName($key, 'buildOption');
67
-            $field = method_exists($this, $method)
68
-                ? $this->$method($key, $value)
69
-                : apply_filters('site-reviews/review/build/'.$key, false, $value, $this, $review);
70
-            if (false === $field) {
71
-                continue;
72
-            }
73
-            $renderedFields[$key] = $field;
74
-        }
75
-        $this->wrap($renderedFields, $review);
76
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review);
77
-        $this->current = null;
78
-        return new ReviewHtml($review, (array) $renderedFields);
79
-    }
57
+	/**
58
+	 * @return ReviewHtml
59
+	 */
60
+	public function buildReview(Review $review)
61
+	{
62
+		$review = apply_filters('site-reviews/review/build/before', $review);
63
+		$this->current = $review;
64
+		$renderedFields = [];
65
+		foreach ($review as $key => $value) {
66
+			$method = glsr(Helper::class)->buildMethodName($key, 'buildOption');
67
+			$field = method_exists($this, $method)
68
+				? $this->$method($key, $value)
69
+				: apply_filters('site-reviews/review/build/'.$key, false, $value, $this, $review);
70
+			if (false === $field) {
71
+				continue;
72
+			}
73
+			$renderedFields[$key] = $field;
74
+		}
75
+		$this->wrap($renderedFields, $review);
76
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review);
77
+		$this->current = null;
78
+		return new ReviewHtml($review, (array) $renderedFields);
79
+	}
80 80
 
81
-    /**
82
-     * @return ReviewsHtml
83
-     */
84
-    public function buildReviews()
85
-    {
86
-        $renderedReviews = [];
87
-        foreach ($this->reviews as $index => $review) {
88
-            $renderedReviews[] = $this->buildReview($review);
89
-        }
90
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
91
-    }
81
+	/**
82
+	 * @return ReviewsHtml
83
+	 */
84
+	public function buildReviews()
85
+	{
86
+		$renderedReviews = [];
87
+		foreach ($this->reviews as $index => $review) {
88
+			$renderedReviews[] = $this->buildReview($review);
89
+		}
90
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
91
+	}
92 92
 
93
-    /**
94
-     * @return void
95
-     */
96
-    public function generateSchema()
97
-    {
98
-        if (!wp_validate_boolean($this->args['schema'])) {
99
-            return;
100
-        }
101
-        glsr(Schema::class)->store(
102
-            glsr(Schema::class)->build($this->args)
103
-        );
104
-    }
93
+	/**
94
+	 * @return void
95
+	 */
96
+	public function generateSchema()
97
+	{
98
+		if (!wp_validate_boolean($this->args['schema'])) {
99
+			return;
100
+		}
101
+		glsr(Schema::class)->store(
102
+			glsr(Schema::class)->build($this->args)
103
+		);
104
+	}
105 105
 
106
-    /**
107
-     * @param string $key
108
-     * @param string $path
109
-     * @return bool
110
-     */
111
-    public function isHidden($key, $path = '')
112
-    {
113
-        $isOptionEnabled = !empty($path)
114
-            ? $this->isOptionEnabled($path)
115
-            : true;
116
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
117
-    }
106
+	/**
107
+	 * @param string $key
108
+	 * @param string $path
109
+	 * @return bool
110
+	 */
111
+	public function isHidden($key, $path = '')
112
+	{
113
+		$isOptionEnabled = !empty($path)
114
+			? $this->isOptionEnabled($path)
115
+			: true;
116
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
117
+	}
118 118
 
119
-    /**
120
-     * @param string $key
121
-     * @param string $value
122
-     * @return void|string
123
-     */
124
-    protected function buildOptionAssignedTo($key, $value)
125
-    {
126
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
127
-            return;
128
-        }
129
-        $post = glsr(Polylang::class)->getPost($value);
130
-        if (!($post instanceof WP_Post)) {
131
-            return;
132
-        }
133
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
134
-            'href' => get_the_permalink($post->ID),
135
-        ]);
136
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
137
-        return '<span>'.$assignedTo.'</span>';
138
-    }
119
+	/**
120
+	 * @param string $key
121
+	 * @param string $value
122
+	 * @return void|string
123
+	 */
124
+	protected function buildOptionAssignedTo($key, $value)
125
+	{
126
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
127
+			return;
128
+		}
129
+		$post = glsr(Polylang::class)->getPost($value);
130
+		if (!($post instanceof WP_Post)) {
131
+			return;
132
+		}
133
+		$permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
134
+			'href' => get_the_permalink($post->ID),
135
+		]);
136
+		$assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
137
+		return '<span>'.$assignedTo.'</span>';
138
+	}
139 139
 
140
-    /**
141
-     * @param string $key
142
-     * @param string $value
143
-     * @return void|string
144
-     */
145
-    protected function buildOptionAuthor($key, $value)
146
-    {
147
-        if (!$this->isHidden($key)) {
148
-            return '<span>'.$value.'</span>';
149
-        }
150
-    }
140
+	/**
141
+	 * @param string $key
142
+	 * @param string $value
143
+	 * @return void|string
144
+	 */
145
+	protected function buildOptionAuthor($key, $value)
146
+	{
147
+		if (!$this->isHidden($key)) {
148
+			return '<span>'.$value.'</span>';
149
+		}
150
+	}
151 151
 
152
-    /**
153
-     * @param string $key
154
-     * @param string $value
155
-     * @return void|string
156
-     */
157
-    protected function buildOptionAvatar($key, $value)
158
-    {
159
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
160
-            return;
161
-        }
162
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
163
-        return glsr(Builder::class)->img([
164
-            'height' => $size,
165
-            'src' => $this->generateAvatar($value),
166
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
167
-            'width' => $size,
168
-        ]);
169
-    }
152
+	/**
153
+	 * @param string $key
154
+	 * @param string $value
155
+	 * @return void|string
156
+	 */
157
+	protected function buildOptionAvatar($key, $value)
158
+	{
159
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
160
+			return;
161
+		}
162
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
163
+		return glsr(Builder::class)->img([
164
+			'height' => $size,
165
+			'src' => $this->generateAvatar($value),
166
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
167
+			'width' => $size,
168
+		]);
169
+	}
170 170
 
171
-    /**
172
-     * @param string $key
173
-     * @param string $value
174
-     * @return void|string
175
-     */
176
-    protected function buildOptionContent($key, $value)
177
-    {
178
-        $text = $this->normalizeText($value);
179
-        if (!$this->isHiddenOrEmpty($key, $text)) {
180
-            return '<p>'.$text.'</p>';
181
-        }
182
-    }
171
+	/**
172
+	 * @param string $key
173
+	 * @param string $value
174
+	 * @return void|string
175
+	 */
176
+	protected function buildOptionContent($key, $value)
177
+	{
178
+		$text = $this->normalizeText($value);
179
+		if (!$this->isHiddenOrEmpty($key, $text)) {
180
+			return '<p>'.$text.'</p>';
181
+		}
182
+	}
183 183
 
184
-    /**
185
-     * @param string $key
186
-     * @param string $value
187
-     * @return void|string
188
-     */
189
-    protected function buildOptionDate($key, $value)
190
-    {
191
-        if ($this->isHidden($key)) {
192
-            return;
193
-        }
194
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
195
-        if ('relative' == $dateFormat) {
196
-            $date = glsr(Date::class)->relative($value);
197
-        } else {
198
-            $format = 'custom' == $dateFormat
199
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
200
-                : (string) get_option('date_format');
201
-            $date = date_i18n($format, strtotime($value));
202
-        }
203
-        return '<span>'.$date.'</span>';
204
-    }
184
+	/**
185
+	 * @param string $key
186
+	 * @param string $value
187
+	 * @return void|string
188
+	 */
189
+	protected function buildOptionDate($key, $value)
190
+	{
191
+		if ($this->isHidden($key)) {
192
+			return;
193
+		}
194
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
195
+		if ('relative' == $dateFormat) {
196
+			$date = glsr(Date::class)->relative($value);
197
+		} else {
198
+			$format = 'custom' == $dateFormat
199
+				? $this->getOption('settings.reviews.date.custom', 'M j, Y')
200
+				: (string) get_option('date_format');
201
+			$date = date_i18n($format, strtotime($value));
202
+		}
203
+		return '<span>'.$date.'</span>';
204
+	}
205 205
 
206
-    /**
207
-     * @param string $key
208
-     * @param string $value
209
-     * @return void|string
210
-     */
211
-    protected function buildOptionRating($key, $value)
212
-    {
213
-        if (!$this->isHiddenOrEmpty($key, $value)) {
214
-            return glsr_star_rating($value);
215
-        }
216
-    }
206
+	/**
207
+	 * @param string $key
208
+	 * @param string $value
209
+	 * @return void|string
210
+	 */
211
+	protected function buildOptionRating($key, $value)
212
+	{
213
+		if (!$this->isHiddenOrEmpty($key, $value)) {
214
+			return glsr_star_rating($value);
215
+		}
216
+	}
217 217
 
218
-    /**
219
-     * @param string $key
220
-     * @param string $value
221
-     * @return void|string
222
-     */
223
-    protected function buildOptionResponse($key, $value)
224
-    {
225
-        if ($this->isHiddenOrEmpty($key, $value)) {
226
-            return;
227
-        }
228
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
229
-        $text = $this->normalizeText($value);
230
-        $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
231
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
232
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
233
-        return $response.$background;
234
-    }
218
+	/**
219
+	 * @param string $key
220
+	 * @param string $value
221
+	 * @return void|string
222
+	 */
223
+	protected function buildOptionResponse($key, $value)
224
+	{
225
+		if ($this->isHiddenOrEmpty($key, $value)) {
226
+			return;
227
+		}
228
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
229
+		$text = $this->normalizeText($value);
230
+		$text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
231
+		$response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
232
+		$background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
233
+		return $response.$background;
234
+	}
235 235
 
236
-    /**
237
-     * @param string $key
238
-     * @param string $value
239
-     * @return void|string
240
-     */
241
-    protected function buildOptionTitle($key, $value)
242
-    {
243
-        if ($this->isHidden($key)) {
244
-            return;
245
-        }
246
-        if (empty($value)) {
247
-            $value = __('No Title', 'site-reviews');
248
-        }
249
-        return '<h3>'.$value.'</h3>';
250
-    }
236
+	/**
237
+	 * @param string $key
238
+	 * @param string $value
239
+	 * @return void|string
240
+	 */
241
+	protected function buildOptionTitle($key, $value)
242
+	{
243
+		if ($this->isHidden($key)) {
244
+			return;
245
+		}
246
+		if (empty($value)) {
247
+			$value = __('No Title', 'site-reviews');
248
+		}
249
+		return '<h3>'.$value.'</h3>';
250
+	}
251 251
 
252
-    /**
253
-     * @param string $avatarUrl
254
-     * @return string
255
-     */
256
-    protected function generateAvatar($avatarUrl)
257
-    {
258
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
259
-            return $avatarUrl;
260
-        }
261
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
262
-        if (empty($authorIdOrEmail)) {
263
-            $authorIdOrEmail = $this->current->email;
264
-        }
265
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
266
-            return $newAvatar;
267
-        }
268
-        return $avatarUrl;
269
-    }
252
+	/**
253
+	 * @param string $avatarUrl
254
+	 * @return string
255
+	 */
256
+	protected function generateAvatar($avatarUrl)
257
+	{
258
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
259
+			return $avatarUrl;
260
+		}
261
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
262
+		if (empty($authorIdOrEmail)) {
263
+			$authorIdOrEmail = $this->current->email;
264
+		}
265
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
266
+			return $newAvatar;
267
+		}
268
+		return $avatarUrl;
269
+	}
270 270
 
271
-    /**
272
-     * @param string $text
273
-     * @return string
274
-     */
275
-    protected function getExcerpt($text)
276
-    {
277
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
278
-        $split = extension_loaded('intl')
279
-            ? $this->getExcerptIntlSplit($text, $limit)
280
-            : $this->getExcerptSplit($text, $limit);
281
-        $hiddenText = substr($text, $split);
282
-        if (!empty($hiddenText)) {
283
-            $showMore = glsr(Builder::class)->span($hiddenText, [
284
-                'class' => 'glsr-hidden glsr-hidden-text',
285
-                'data-show-less' => __('Show less', 'site-reviews'),
286
-                'data-show-more' => __('Show more', 'site-reviews'),
287
-            ]);
288
-            $text = ltrim(substr($text, 0, $split)).$showMore;
289
-        }
290
-        return $text;
291
-    }
271
+	/**
272
+	 * @param string $text
273
+	 * @return string
274
+	 */
275
+	protected function getExcerpt($text)
276
+	{
277
+		$limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
278
+		$split = extension_loaded('intl')
279
+			? $this->getExcerptIntlSplit($text, $limit)
280
+			: $this->getExcerptSplit($text, $limit);
281
+		$hiddenText = substr($text, $split);
282
+		if (!empty($hiddenText)) {
283
+			$showMore = glsr(Builder::class)->span($hiddenText, [
284
+				'class' => 'glsr-hidden glsr-hidden-text',
285
+				'data-show-less' => __('Show less', 'site-reviews'),
286
+				'data-show-more' => __('Show more', 'site-reviews'),
287
+			]);
288
+			$text = ltrim(substr($text, 0, $split)).$showMore;
289
+		}
290
+		return $text;
291
+	}
292 292
 
293
-    /**
294
-     * @param string $text
295
-     * @param int $limit
296
-     * @return int
297
-     */
298
-    protected function getExcerptIntlSplit($text, $limit)
299
-    {
300
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
301
-        $words->setText($text);
302
-        $count = 0;
303
-        foreach ($words as $offset) {
304
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
305
-                continue;
306
-            }
307
-            ++$count;
308
-            if ($count != $limit) {
309
-                continue;
310
-            }
311
-            return $offset;
312
-        }
313
-        return strlen($text);
314
-    }
293
+	/**
294
+	 * @param string $text
295
+	 * @param int $limit
296
+	 * @return int
297
+	 */
298
+	protected function getExcerptIntlSplit($text, $limit)
299
+	{
300
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
301
+		$words->setText($text);
302
+		$count = 0;
303
+		foreach ($words as $offset) {
304
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
305
+				continue;
306
+			}
307
+			++$count;
308
+			if ($count != $limit) {
309
+				continue;
310
+			}
311
+			return $offset;
312
+		}
313
+		return strlen($text);
314
+	}
315 315
 
316
-    /**
317
-     * @param string $text
318
-     * @param int $limit
319
-     * @return int
320
-     */
321
-    protected function getExcerptSplit($text, $limit)
322
-    {
323
-        if (str_word_count($text, 0) > $limit) {
324
-            $words = array_keys(str_word_count($text, 2));
325
-            return $words[$limit];
326
-        }
327
-        return strlen($text);
328
-    }
316
+	/**
317
+	 * @param string $text
318
+	 * @param int $limit
319
+	 * @return int
320
+	 */
321
+	protected function getExcerptSplit($text, $limit)
322
+	{
323
+		if (str_word_count($text, 0) > $limit) {
324
+			$words = array_keys(str_word_count($text, 2));
325
+			return $words[$limit];
326
+		}
327
+		return strlen($text);
328
+	}
329 329
 
330
-    /**
331
-     * @param string $path
332
-     * @param mixed $fallback
333
-     * @return mixed
334
-     */
335
-    protected function getOption($path, $fallback = '')
336
-    {
337
-        if (array_key_exists($path, $this->options)) {
338
-            return $this->options[$path];
339
-        }
340
-        return $fallback;
341
-    }
330
+	/**
331
+	 * @param string $path
332
+	 * @param mixed $fallback
333
+	 * @return mixed
334
+	 */
335
+	protected function getOption($path, $fallback = '')
336
+	{
337
+		if (array_key_exists($path, $this->options)) {
338
+			return $this->options[$path];
339
+		}
340
+		return $fallback;
341
+	}
342 342
 
343
-    /**
344
-     * @param string $key
345
-     * @param string $value
346
-     * @return bool
347
-     */
348
-    protected function isHiddenOrEmpty($key, $value)
349
-    {
350
-        return $this->isHidden($key) || empty($value);
351
-    }
343
+	/**
344
+	 * @param string $key
345
+	 * @param string $value
346
+	 * @return bool
347
+	 */
348
+	protected function isHiddenOrEmpty($key, $value)
349
+	{
350
+		return $this->isHidden($key) || empty($value);
351
+	}
352 352
 
353
-    /**
354
-     * @param string $path
355
-     * @return bool
356
-     */
357
-    protected function isOptionEnabled($path)
358
-    {
359
-        return 'yes' == $this->getOption($path);
360
-    }
353
+	/**
354
+	 * @param string $path
355
+	 * @return bool
356
+	 */
357
+	protected function isOptionEnabled($path)
358
+	{
359
+		return 'yes' == $this->getOption($path);
360
+	}
361 361
 
362
-    /**
363
-     * @param string $text
364
-     * @return string
365
-     */
366
-    protected function normalizeText($text)
367
-    {
368
-        $text = wp_kses($text, wp_kses_allowed_html());
369
-        $text = convert_smilies(strip_shortcodes($text));
370
-        $text = str_replace(']]>', ']]&gt;', $text);
371
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
372
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
373
-            $text = $this->getExcerpt($text);
374
-        }
375
-        return wptexturize(nl2br($text));
376
-    }
362
+	/**
363
+	 * @param string $text
364
+	 * @return string
365
+	 */
366
+	protected function normalizeText($text)
367
+	{
368
+		$text = wp_kses($text, wp_kses_allowed_html());
369
+		$text = convert_smilies(strip_shortcodes($text));
370
+		$text = str_replace(']]>', ']]&gt;', $text);
371
+		$text = preg_replace('/(\R){2,}/', '$1', $text);
372
+		if ($this->isOptionEnabled('settings.reviews.excerpts')) {
373
+			$text = $this->getExcerpt($text);
374
+		}
375
+		return wptexturize(nl2br($text));
376
+	}
377 377
 
378
-    /**
379
-     * @return void
380
-     */
381
-    protected function wrap(array &$renderedFields, Review $review)
382
-    {
383
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review);
384
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
385
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
386
-            if (empty($value)) {
387
-                return;
388
-            }
389
-            $value = glsr(Builder::class)->div($value, [
390
-                'class' => 'glsr-review-'.$key,
391
-            ]);
392
-        });
393
-    }
378
+	/**
379
+	 * @return void
380
+	 */
381
+	protected function wrap(array &$renderedFields, Review $review)
382
+	{
383
+		$renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review);
384
+		array_walk($renderedFields, function (&$value, $key) use ($review) {
385
+			$value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
386
+			if (empty($value)) {
387
+				return;
388
+			}
389
+			$value = glsr(Builder::class)->div($value, [
390
+				'class' => 'glsr-review-'.$key,
391
+			]);
392
+		});
393
+	}
394 394
 }
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
      * @param Reviews|null $reviews
44 44
      * @return ReviewsHtml
45 45
      */
46
-    public function build(array $args = [], $reviews = null)
46
+    public function build( array $args = [], $reviews = null )
47 47
     {
48
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
49
-        $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all());
48
+        $this->args = glsr( SiteReviewsDefaults::class )->merge( $args );
49
+        $this->options = glsr( Helper::class )->flattenArray( glsr( OptionManager::class )->all() );
50 50
         $this->reviews = $reviews instanceof Reviews
51 51
             ? $reviews
52
-            : glsr(ReviewManager::class)->get($args);
52
+            : glsr( ReviewManager::class )->get( $args );
53 53
         $this->generateSchema();
54 54
         return $this->buildReviews();
55 55
     }
@@ -57,25 +57,25 @@  discard block
 block discarded – undo
57 57
     /**
58 58
      * @return ReviewHtml
59 59
      */
60
-    public function buildReview(Review $review)
60
+    public function buildReview( Review $review )
61 61
     {
62
-        $review = apply_filters('site-reviews/review/build/before', $review);
62
+        $review = apply_filters( 'site-reviews/review/build/before', $review );
63 63
         $this->current = $review;
64 64
         $renderedFields = [];
65
-        foreach ($review as $key => $value) {
66
-            $method = glsr(Helper::class)->buildMethodName($key, 'buildOption');
67
-            $field = method_exists($this, $method)
68
-                ? $this->$method($key, $value)
69
-                : apply_filters('site-reviews/review/build/'.$key, false, $value, $this, $review);
70
-            if (false === $field) {
65
+        foreach( $review as $key => $value ) {
66
+            $method = glsr( Helper::class )->buildMethodName( $key, 'buildOption' );
67
+            $field = method_exists( $this, $method )
68
+                ? $this->$method( $key, $value )
69
+                : apply_filters( 'site-reviews/review/build/'.$key, false, $value, $this, $review );
70
+            if( false === $field ) {
71 71
                 continue;
72 72
             }
73 73
             $renderedFields[$key] = $field;
74 74
         }
75
-        $this->wrap($renderedFields, $review);
76
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review);
75
+        $this->wrap( $renderedFields, $review );
76
+        $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review );
77 77
         $this->current = null;
78
-        return new ReviewHtml($review, (array) $renderedFields);
78
+        return new ReviewHtml( $review, (array)$renderedFields );
79 79
     }
80 80
 
81 81
     /**
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
     public function buildReviews()
85 85
     {
86 86
         $renderedReviews = [];
87
-        foreach ($this->reviews as $index => $review) {
88
-            $renderedReviews[] = $this->buildReview($review);
87
+        foreach( $this->reviews as $index => $review ) {
88
+            $renderedReviews[] = $this->buildReview( $review );
89 89
         }
90
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
90
+        return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args );
91 91
     }
92 92
 
93 93
     /**
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
      */
96 96
     public function generateSchema()
97 97
     {
98
-        if (!wp_validate_boolean($this->args['schema'])) {
98
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
99 99
             return;
100 100
         }
101
-        glsr(Schema::class)->store(
102
-            glsr(Schema::class)->build($this->args)
101
+        glsr( Schema::class )->store(
102
+            glsr( Schema::class )->build( $this->args )
103 103
         );
104 104
     }
105 105
 
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
      * @param string $path
109 109
      * @return bool
110 110
      */
111
-    public function isHidden($key, $path = '')
111
+    public function isHidden( $key, $path = '' )
112 112
     {
113 113
         $isOptionEnabled = !empty($path)
114
-            ? $this->isOptionEnabled($path)
114
+            ? $this->isOptionEnabled( $path )
115 115
             : true;
116
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
116
+        return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled;
117 117
     }
118 118
 
119 119
     /**
@@ -121,19 +121,19 @@  discard block
 block discarded – undo
121 121
      * @param string $value
122 122
      * @return void|string
123 123
      */
124
-    protected function buildOptionAssignedTo($key, $value)
124
+    protected function buildOptionAssignedTo( $key, $value )
125 125
     {
126
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
126
+        if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) {
127 127
             return;
128 128
         }
129
-        $post = glsr(Polylang::class)->getPost($value);
130
-        if (!($post instanceof WP_Post)) {
129
+        $post = glsr( Polylang::class )->getPost( $value );
130
+        if( !($post instanceof WP_Post) ) {
131 131
             return;
132 132
         }
133
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
134
-            'href' => get_the_permalink($post->ID),
135
-        ]);
136
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
133
+        $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [
134
+            'href' => get_the_permalink( $post->ID ),
135
+        ] );
136
+        $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink );
137 137
         return '<span>'.$assignedTo.'</span>';
138 138
     }
139 139
 
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
      * @param string $value
143 143
      * @return void|string
144 144
      */
145
-    protected function buildOptionAuthor($key, $value)
145
+    protected function buildOptionAuthor( $key, $value )
146 146
     {
147
-        if (!$this->isHidden($key)) {
147
+        if( !$this->isHidden( $key ) ) {
148 148
             return '<span>'.$value.'</span>';
149 149
         }
150 150
     }
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
      * @param string $value
155 155
      * @return void|string
156 156
      */
157
-    protected function buildOptionAvatar($key, $value)
157
+    protected function buildOptionAvatar( $key, $value )
158 158
     {
159
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
159
+        if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) {
160 160
             return;
161 161
         }
162
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
163
-        return glsr(Builder::class)->img([
162
+        $size = $this->getOption( 'settings.reviews.avatars_size', 40 );
163
+        return glsr( Builder::class )->img( [
164 164
             'height' => $size,
165
-            'src' => $this->generateAvatar($value),
166
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
165
+            'src' => $this->generateAvatar( $value ),
166
+            'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ),
167 167
             'width' => $size,
168
-        ]);
168
+        ] );
169 169
     }
170 170
 
171 171
     /**
@@ -173,10 +173,10 @@  discard block
 block discarded – undo
173 173
      * @param string $value
174 174
      * @return void|string
175 175
      */
176
-    protected function buildOptionContent($key, $value)
176
+    protected function buildOptionContent( $key, $value )
177 177
     {
178
-        $text = $this->normalizeText($value);
179
-        if (!$this->isHiddenOrEmpty($key, $text)) {
178
+        $text = $this->normalizeText( $value );
179
+        if( !$this->isHiddenOrEmpty( $key, $text ) ) {
180 180
             return '<p>'.$text.'</p>';
181 181
         }
182 182
     }
@@ -186,19 +186,19 @@  discard block
 block discarded – undo
186 186
      * @param string $value
187 187
      * @return void|string
188 188
      */
189
-    protected function buildOptionDate($key, $value)
189
+    protected function buildOptionDate( $key, $value )
190 190
     {
191
-        if ($this->isHidden($key)) {
191
+        if( $this->isHidden( $key ) ) {
192 192
             return;
193 193
         }
194
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
195
-        if ('relative' == $dateFormat) {
196
-            $date = glsr(Date::class)->relative($value);
194
+        $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' );
195
+        if( 'relative' == $dateFormat ) {
196
+            $date = glsr( Date::class )->relative( $value );
197 197
         } else {
198 198
             $format = 'custom' == $dateFormat
199
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
200
-                : (string) get_option('date_format');
201
-            $date = date_i18n($format, strtotime($value));
199
+                ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' )
200
+                : (string)get_option( 'date_format' );
201
+            $date = date_i18n( $format, strtotime( $value ) );
202 202
         }
203 203
         return '<span>'.$date.'</span>';
204 204
     }
@@ -208,10 +208,10 @@  discard block
 block discarded – undo
208 208
      * @param string $value
209 209
      * @return void|string
210 210
      */
211
-    protected function buildOptionRating($key, $value)
211
+    protected function buildOptionRating( $key, $value )
212 212
     {
213
-        if (!$this->isHiddenOrEmpty($key, $value)) {
214
-            return glsr_star_rating($value);
213
+        if( !$this->isHiddenOrEmpty( $key, $value ) ) {
214
+            return glsr_star_rating( $value );
215 215
         }
216 216
     }
217 217
 
@@ -220,16 +220,16 @@  discard block
 block discarded – undo
220 220
      * @param string $value
221 221
      * @return void|string
222 222
      */
223
-    protected function buildOptionResponse($key, $value)
223
+    protected function buildOptionResponse( $key, $value )
224 224
     {
225
-        if ($this->isHiddenOrEmpty($key, $value)) {
225
+        if( $this->isHiddenOrEmpty( $key, $value ) ) {
226 226
             return;
227 227
         }
228
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
229
-        $text = $this->normalizeText($value);
228
+        $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) );
229
+        $text = $this->normalizeText( $value );
230 230
         $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
231
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
232
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
231
+        $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] );
232
+        $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] );
233 233
         return $response.$background;
234 234
     }
235 235
 
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
      * @param string $value
239 239
      * @return void|string
240 240
      */
241
-    protected function buildOptionTitle($key, $value)
241
+    protected function buildOptionTitle( $key, $value )
242 242
     {
243
-        if ($this->isHidden($key)) {
243
+        if( $this->isHidden( $key ) ) {
244 244
             return;
245 245
         }
246
-        if (empty($value)) {
247
-            $value = __('No Title', 'site-reviews');
246
+        if( empty($value) ) {
247
+            $value = __( 'No Title', 'site-reviews' );
248 248
         }
249 249
         return '<h3>'.$value.'</h3>';
250 250
     }
@@ -253,16 +253,16 @@  discard block
 block discarded – undo
253 253
      * @param string $avatarUrl
254 254
      * @return string
255 255
      */
256
-    protected function generateAvatar($avatarUrl)
256
+    protected function generateAvatar( $avatarUrl )
257 257
     {
258
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
258
+        if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) {
259 259
             return $avatarUrl;
260 260
         }
261
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
262
-        if (empty($authorIdOrEmail)) {
261
+        $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id );
262
+        if( empty($authorIdOrEmail) ) {
263 263
             $authorIdOrEmail = $this->current->email;
264 264
         }
265
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
265
+        if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) {
266 266
             return $newAvatar;
267 267
         }
268 268
         return $avatarUrl;
@@ -272,20 +272,20 @@  discard block
 block discarded – undo
272 272
      * @param string $text
273 273
      * @return string
274 274
      */
275
-    protected function getExcerpt($text)
275
+    protected function getExcerpt( $text )
276 276
     {
277
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
278
-        $split = extension_loaded('intl')
279
-            ? $this->getExcerptIntlSplit($text, $limit)
280
-            : $this->getExcerptSplit($text, $limit);
281
-        $hiddenText = substr($text, $split);
282
-        if (!empty($hiddenText)) {
283
-            $showMore = glsr(Builder::class)->span($hiddenText, [
277
+        $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) );
278
+        $split = extension_loaded( 'intl' )
279
+            ? $this->getExcerptIntlSplit( $text, $limit )
280
+            : $this->getExcerptSplit( $text, $limit );
281
+        $hiddenText = substr( $text, $split );
282
+        if( !empty($hiddenText) ) {
283
+            $showMore = glsr( Builder::class )->span( $hiddenText, [
284 284
                 'class' => 'glsr-hidden glsr-hidden-text',
285
-                'data-show-less' => __('Show less', 'site-reviews'),
286
-                'data-show-more' => __('Show more', 'site-reviews'),
287
-            ]);
288
-            $text = ltrim(substr($text, 0, $split)).$showMore;
285
+                'data-show-less' => __( 'Show less', 'site-reviews' ),
286
+                'data-show-more' => __( 'Show more', 'site-reviews' ),
287
+            ] );
288
+            $text = ltrim( substr( $text, 0, $split ) ).$showMore;
289 289
         }
290 290
         return $text;
291 291
     }
@@ -295,22 +295,22 @@  discard block
 block discarded – undo
295 295
      * @param int $limit
296 296
      * @return int
297 297
      */
298
-    protected function getExcerptIntlSplit($text, $limit)
298
+    protected function getExcerptIntlSplit( $text, $limit )
299 299
     {
300
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
301
-        $words->setText($text);
300
+        $words = IntlRuleBasedBreakIterator::createWordInstance( '' );
301
+        $words->setText( $text );
302 302
         $count = 0;
303
-        foreach ($words as $offset) {
304
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
303
+        foreach( $words as $offset ) {
304
+            if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) {
305 305
                 continue;
306 306
             }
307 307
             ++$count;
308
-            if ($count != $limit) {
308
+            if( $count != $limit ) {
309 309
                 continue;
310 310
             }
311 311
             return $offset;
312 312
         }
313
-        return strlen($text);
313
+        return strlen( $text );
314 314
     }
315 315
 
316 316
     /**
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
      * @param int $limit
319 319
      * @return int
320 320
      */
321
-    protected function getExcerptSplit($text, $limit)
321
+    protected function getExcerptSplit( $text, $limit )
322 322
     {
323
-        if (str_word_count($text, 0) > $limit) {
324
-            $words = array_keys(str_word_count($text, 2));
323
+        if( str_word_count( $text, 0 ) > $limit ) {
324
+            $words = array_keys( str_word_count( $text, 2 ) );
325 325
             return $words[$limit];
326 326
         }
327
-        return strlen($text);
327
+        return strlen( $text );
328 328
     }
329 329
 
330 330
     /**
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
      * @param mixed $fallback
333 333
      * @return mixed
334 334
      */
335
-    protected function getOption($path, $fallback = '')
335
+    protected function getOption( $path, $fallback = '' )
336 336
     {
337
-        if (array_key_exists($path, $this->options)) {
337
+        if( array_key_exists( $path, $this->options ) ) {
338 338
             return $this->options[$path];
339 339
         }
340 340
         return $fallback;
@@ -345,50 +345,50 @@  discard block
 block discarded – undo
345 345
      * @param string $value
346 346
      * @return bool
347 347
      */
348
-    protected function isHiddenOrEmpty($key, $value)
348
+    protected function isHiddenOrEmpty( $key, $value )
349 349
     {
350
-        return $this->isHidden($key) || empty($value);
350
+        return $this->isHidden( $key ) || empty($value);
351 351
     }
352 352
 
353 353
     /**
354 354
      * @param string $path
355 355
      * @return bool
356 356
      */
357
-    protected function isOptionEnabled($path)
357
+    protected function isOptionEnabled( $path )
358 358
     {
359
-        return 'yes' == $this->getOption($path);
359
+        return 'yes' == $this->getOption( $path );
360 360
     }
361 361
 
362 362
     /**
363 363
      * @param string $text
364 364
      * @return string
365 365
      */
366
-    protected function normalizeText($text)
366
+    protected function normalizeText( $text )
367 367
     {
368
-        $text = wp_kses($text, wp_kses_allowed_html());
369
-        $text = convert_smilies(strip_shortcodes($text));
370
-        $text = str_replace(']]>', ']]&gt;', $text);
371
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
372
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
373
-            $text = $this->getExcerpt($text);
368
+        $text = wp_kses( $text, wp_kses_allowed_html() );
369
+        $text = convert_smilies( strip_shortcodes( $text ) );
370
+        $text = str_replace( ']]>', ']]&gt;', $text );
371
+        $text = preg_replace( '/(\R){2,}/', '$1', $text );
372
+        if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) {
373
+            $text = $this->getExcerpt( $text );
374 374
         }
375
-        return wptexturize(nl2br($text));
375
+        return wptexturize( nl2br( $text ) );
376 376
     }
377 377
 
378 378
     /**
379 379
      * @return void
380 380
      */
381
-    protected function wrap(array &$renderedFields, Review $review)
381
+    protected function wrap( array &$renderedFields, Review $review )
382 382
     {
383
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review);
384
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
385
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
386
-            if (empty($value)) {
383
+        $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review );
384
+        array_walk( $renderedFields, function( &$value, $key ) use ($review) {
385
+            $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review );
386
+            if( empty($value) ) {
387 387
                 return;
388 388
             }
389
-            $value = glsr(Builder::class)->div($value, [
389
+            $value = glsr( Builder::class )->div( $value, [
390 390
                 'class' => 'glsr-review-'.$key,
391
-            ]);
391
+            ] );
392 392
         });
393 393
     }
394 394
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/ReviewsHtml.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -7,135 +7,135 @@
 block discarded – undo
7 7
 
8 8
 class ReviewsHtml extends ArrayObject
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    public $args;
10
+	/**
11
+	 * @var array
12
+	 */
13
+	public $args;
14 14
 
15
-    /**
16
-     * @var int
17
-     */
18
-    public $max_num_pages;
15
+	/**
16
+	 * @var int
17
+	 */
18
+	public $max_num_pages;
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    public $pagination;
20
+	/**
21
+	 * @var string
22
+	 */
23
+	public $pagination;
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    public $reviews;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	public $reviews;
29 29
 
30
-    public function __construct(array $reviews, $maxPageCount, array $args)
31
-    {
32
-        $this->args = $args;
33
-        $this->max_num_pages = $maxPageCount;
34
-        $this->reviews = $reviews;
35
-        $this->pagination = $this->buildPagination();
36
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
37
-    }
30
+	public function __construct(array $reviews, $maxPageCount, array $args)
31
+	{
32
+		$this->args = $args;
33
+		$this->max_num_pages = $maxPageCount;
34
+		$this->reviews = $reviews;
35
+		$this->pagination = $this->buildPagination();
36
+		parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
37
+	}
38 38
 
39
-    /**
40
-     * @return string
41
-     */
42
-    public function __toString()
43
-    {
44
-        return glsr(Template::class)->build('templates/reviews', [
45
-            'args' => $this->args,
46
-            'context' => [
47
-                'assigned_to' => $this->args['assigned_to'],
48
-                'category' => $this->args['category'],
49
-                'class' => $this->getClass(),
50
-                'id' => $this->args['id'],
51
-                'pagination' => $this->getPagination(),
52
-                'reviews' => $this->getReviews(),
53
-            ],
54
-        ]);
55
-    }
39
+	/**
40
+	 * @return string
41
+	 */
42
+	public function __toString()
43
+	{
44
+		return glsr(Template::class)->build('templates/reviews', [
45
+			'args' => $this->args,
46
+			'context' => [
47
+				'assigned_to' => $this->args['assigned_to'],
48
+				'category' => $this->args['category'],
49
+				'class' => $this->getClass(),
50
+				'id' => $this->args['id'],
51
+				'pagination' => $this->getPagination(),
52
+				'reviews' => $this->getReviews(),
53
+			],
54
+		]);
55
+	}
56 56
 
57
-    /**
58
-     * @return string
59
-     */
60
-    public function getPagination()
61
-    {
62
-        return wp_validate_boolean($this->args['pagination'])
63
-            ? $this->pagination
64
-            : '';
65
-    }
57
+	/**
58
+	 * @return string
59
+	 */
60
+	public function getPagination()
61
+	{
62
+		return wp_validate_boolean($this->args['pagination'])
63
+			? $this->pagination
64
+			: '';
65
+	}
66 66
 
67
-    /**
68
-     * @return string
69
-     */
70
-    public function getReviews()
71
-    {
72
-        $html = empty($this->reviews)
73
-            ? $this->getReviewsFallback()
74
-            : implode(PHP_EOL, $this->reviews);
75
-        $wrapper = '<div class="glsr-reviews">%s</div>';
76
-        $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper);
77
-        return sprintf($wrapper, $html);
78
-    }
67
+	/**
68
+	 * @return string
69
+	 */
70
+	public function getReviews()
71
+	{
72
+		$html = empty($this->reviews)
73
+			? $this->getReviewsFallback()
74
+			: implode(PHP_EOL, $this->reviews);
75
+		$wrapper = '<div class="glsr-reviews">%s</div>';
76
+		$wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper);
77
+		return sprintf($wrapper, $html);
78
+	}
79 79
 
80
-    /**
81
-     * @param mixed $key
82
-     * @return mixed
83
-     */
84
-    public function offsetGet($key)
85
-    {
86
-        if ('navigation' == $key) {
87
-            glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
88
-            return $this->pagination;
89
-        }
90
-        if (property_exists($this, $key)) {
91
-            return $this->{$key};
92
-        }
93
-        return array_key_exists($key, $this->reviews)
94
-            ? $this->reviews[$key]
95
-            : null;
96
-    }
80
+	/**
81
+	 * @param mixed $key
82
+	 * @return mixed
83
+	 */
84
+	public function offsetGet($key)
85
+	{
86
+		if ('navigation' == $key) {
87
+			glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
88
+			return $this->pagination;
89
+		}
90
+		if (property_exists($this, $key)) {
91
+			return $this->{$key};
92
+		}
93
+		return array_key_exists($key, $this->reviews)
94
+			? $this->reviews[$key]
95
+			: null;
96
+	}
97 97
 
98
-    /**
99
-     * @return string
100
-     */
101
-    protected function buildPagination()
102
-    {
103
-        $html = glsr(Partial::class)->build('pagination', [
104
-            'baseUrl' => glsr_get($this->args, 'pagedUrl'),
105
-            'current' => glsr_get($this->args, 'paged'),
106
-            'total' => $this->max_num_pages,
107
-        ]);
108
-        $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']);
109
-        $wrapper = '<div class="glsr-pagination">%s</div>';
110
-        $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper);
111
-        return sprintf($wrapper, $html);
112
-    }
98
+	/**
99
+	 * @return string
100
+	 */
101
+	protected function buildPagination()
102
+	{
103
+		$html = glsr(Partial::class)->build('pagination', [
104
+			'baseUrl' => glsr_get($this->args, 'pagedUrl'),
105
+			'current' => glsr_get($this->args, 'paged'),
106
+			'total' => $this->max_num_pages,
107
+		]);
108
+		$html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']);
109
+		$wrapper = '<div class="glsr-pagination">%s</div>';
110
+		$wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper);
111
+		return sprintf($wrapper, $html);
112
+	}
113 113
 
114
-    /**
115
-     * @return string
116
-     */
117
-    protected function getClass()
118
-    {
119
-        $defaults = [
120
-            'glsr-default',
121
-        ];
122
-        if ('ajax' == $this->args['pagination']) {
123
-            $defaults[] = 'glsr-ajax-pagination';
124
-        }
125
-        $classes = explode(' ', $this->args['class']);
126
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
127
-        return implode(' ', $classes);
128
-    }
114
+	/**
115
+	 * @return string
116
+	 */
117
+	protected function getClass()
118
+	{
119
+		$defaults = [
120
+			'glsr-default',
121
+		];
122
+		if ('ajax' == $this->args['pagination']) {
123
+			$defaults[] = 'glsr-ajax-pagination';
124
+		}
125
+		$classes = explode(' ', $this->args['class']);
126
+		$classes = array_unique(array_merge($defaults, array_filter($classes)));
127
+		return implode(' ', $classes);
128
+	}
129 129
 
130
-    /**
131
-     * @return string
132
-     */
133
-    protected function getReviewsFallback()
134
-    {
135
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
136
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
137
-        }
138
-        $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
139
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
140
-    }
130
+	/**
131
+	 * @return string
132
+	 */
133
+	protected function getReviewsFallback()
134
+	{
135
+		if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
136
+			$this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
137
+		}
138
+		$fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
139
+		return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
140
+	}
141 141
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
      */
28 28
     public $reviews;
29 29
 
30
-    public function __construct(array $reviews, $maxPageCount, array $args)
30
+    public function __construct( array $reviews, $maxPageCount, array $args )
31 31
     {
32 32
         $this->args = $args;
33 33
         $this->max_num_pages = $maxPageCount;
34 34
         $this->reviews = $reviews;
35 35
         $this->pagination = $this->buildPagination();
36
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
36
+        parent::__construct( $reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS );
37 37
     }
38 38
 
39 39
     /**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function __toString()
43 43
     {
44
-        return glsr(Template::class)->build('templates/reviews', [
44
+        return glsr( Template::class )->build( 'templates/reviews', [
45 45
             'args' => $this->args,
46 46
             'context' => [
47 47
                 'assigned_to' => $this->args['assigned_to'],
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
                 'pagination' => $this->getPagination(),
52 52
                 'reviews' => $this->getReviews(),
53 53
             ],
54
-        ]);
54
+        ] );
55 55
     }
56 56
 
57 57
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function getPagination()
61 61
     {
62
-        return wp_validate_boolean($this->args['pagination'])
62
+        return wp_validate_boolean( $this->args['pagination'] )
63 63
             ? $this->pagination
64 64
             : '';
65 65
     }
@@ -71,26 +71,26 @@  discard block
 block discarded – undo
71 71
     {
72 72
         $html = empty($this->reviews)
73 73
             ? $this->getReviewsFallback()
74
-            : implode(PHP_EOL, $this->reviews);
74
+            : implode( PHP_EOL, $this->reviews );
75 75
         $wrapper = '<div class="glsr-reviews">%s</div>';
76
-        $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper);
77
-        return sprintf($wrapper, $html);
76
+        $wrapper = apply_filters( 'site-reviews/reviews/reviews-wrapper', $wrapper );
77
+        return sprintf( $wrapper, $html );
78 78
     }
79 79
 
80 80
     /**
81 81
      * @param mixed $key
82 82
      * @return mixed
83 83
      */
84
-    public function offsetGet($key)
84
+    public function offsetGet( $key )
85 85
     {
86
-        if ('navigation' == $key) {
86
+        if( 'navigation' == $key ) {
87 87
             glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
88 88
             return $this->pagination;
89 89
         }
90
-        if (property_exists($this, $key)) {
90
+        if( property_exists( $this, $key ) ) {
91 91
             return $this->{$key};
92 92
         }
93
-        return array_key_exists($key, $this->reviews)
93
+        return array_key_exists( $key, $this->reviews )
94 94
             ? $this->reviews[$key]
95 95
             : null;
96 96
     }
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
      */
101 101
     protected function buildPagination()
102 102
     {
103
-        $html = glsr(Partial::class)->build('pagination', [
104
-            'baseUrl' => glsr_get($this->args, 'pagedUrl'),
105
-            'current' => glsr_get($this->args, 'paged'),
103
+        $html = glsr( Partial::class )->build( 'pagination', [
104
+            'baseUrl' => glsr_get( $this->args, 'pagedUrl' ),
105
+            'current' => glsr_get( $this->args, 'paged' ),
106 106
             'total' => $this->max_num_pages,
107
-        ]);
108
-        $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']);
107
+        ] );
108
+        $html .= sprintf( '<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json'] );
109 109
         $wrapper = '<div class="glsr-pagination">%s</div>';
110
-        $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper);
111
-        return sprintf($wrapper, $html);
110
+        $wrapper = apply_filters( 'site-reviews/reviews/pagination-wrapper', $wrapper );
111
+        return sprintf( $wrapper, $html );
112 112
     }
113 113
 
114 114
     /**
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
         $defaults = [
120 120
             'glsr-default',
121 121
         ];
122
-        if ('ajax' == $this->args['pagination']) {
122
+        if( 'ajax' == $this->args['pagination'] ) {
123 123
             $defaults[] = 'glsr-ajax-pagination';
124 124
         }
125
-        $classes = explode(' ', $this->args['class']);
126
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
127
-        return implode(' ', $classes);
125
+        $classes = explode( ' ', $this->args['class'] );
126
+        $classes = array_unique( array_merge( $defaults, array_filter( $classes ) ) );
127
+        return implode( ' ', $classes );
128 128
     }
129 129
 
130 130
     /**
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
      */
133 133
     protected function getReviewsFallback()
134 134
     {
135
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
136
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
135
+        if( empty($this->args['fallback']) && glsr( OptionManager::class )->getBool( 'settings.reviews.fallback' ) ) {
136
+            $this->args['fallback'] = __( 'There are no reviews yet. Be the first one to write one.', 'site-reviews' );
137 137
         }
138 138
         $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
139
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
139
+        return apply_filters( 'site-reviews/reviews/fallback', $fallback, $this->args );
140 140
     }
141 141
 }
Please login to merge, or discard this patch.
plugin/Modules/Notice.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -8,114 +8,114 @@
 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
-        if (empty($notices)) {
73
-            return;
74
-        }
75
-        return array_reduce($notices, function ($carry, $notice) {
76
-            return $carry.$this->buildNotice(json_decode($notice['message'], true));
77
-        });
78
-    }
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
+		if (empty($notices)) {
73
+			return;
74
+		}
75
+		return array_reduce($notices, function ($carry, $notice) {
76
+			return $carry.$this->buildNotice(json_decode($notice['message'], true));
77
+		});
78
+	}
79 79
 
80
-    /**
81
-     * @return string
82
-     */
83
-    protected function buildNotice(array $args)
84
-    {
85
-        $messages = array_reduce($args['messages'], function ($carry, $message) {
86
-            return $carry.glsr(Builder::class)->p($message);
87
-        });
88
-        $class = 'notice notice-'.$args['type'];
89
-        if ($args['inline']) {
90
-            $class.= ' inline';
91
-        }
92
-        if ($args['dismissible']) {
93
-            $class.= ' is-dismissible';
94
-        }
95
-        return glsr(Builder::class)->div($messages, [
96
-            'class' => $class,
97
-        ]);
98
-    }
80
+	/**
81
+	 * @return string
82
+	 */
83
+	protected function buildNotice(array $args)
84
+	{
85
+		$messages = array_reduce($args['messages'], function ($carry, $message) {
86
+			return $carry.glsr(Builder::class)->p($message);
87
+		});
88
+		$class = 'notice notice-'.$args['type'];
89
+		if ($args['inline']) {
90
+			$class.= ' inline';
91
+		}
92
+		if ($args['dismissible']) {
93
+			$class.= ' is-dismissible';
94
+		}
95
+		return glsr(Builder::class)->div($messages, [
96
+			'class' => $class,
97
+		]);
98
+	}
99 99
 
100
-    /**
101
-     * @return array
102
-     */
103
-    protected function normalize(array $args)
104
-    {
105
-        $defaults = [
106
-            'dismissible' => true,
107
-            'inline' => true,
108
-            'message' => '',
109
-            'type' => '',
110
-        ];
111
-        $args = shortcode_atts($defaults, $args);
112
-        if (!in_array($args['type'], ['error', 'warning', 'success'])) {
113
-            $args['type'] = 'success';
114
-        }
115
-        $args['messages'] = is_wp_error($args['message'])
116
-            ? (array) $args['message']->get_error_message()
117
-            : (array) $args['message'];
118
-        unset($args['message']);
119
-        return $args;
120
-    }
100
+	/**
101
+	 * @return array
102
+	 */
103
+	protected function normalize(array $args)
104
+	{
105
+		$defaults = [
106
+			'dismissible' => true,
107
+			'inline' => true,
108
+			'message' => '',
109
+			'type' => '',
110
+		];
111
+		$args = shortcode_atts($defaults, $args);
112
+		if (!in_array($args['type'], ['error', 'warning', 'success'])) {
113
+			$args['type'] = 'success';
114
+		}
115
+		$args['messages'] = is_wp_error($args['message'])
116
+			? (array) $args['message']->get_error_message()
117
+			: (array) $args['message'];
118
+		unset($args['message']);
119
+		return $args;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -13,41 +13,41 @@  discard block
 block discarded – undo
13 13
      * @param string|array|WP_Error $message
14 14
      * @return void
15 15
      */
16
-    public function add($type, $message, array $args = [])
16
+    public function add( $type, $message, array $args = [] )
17 17
     {
18
-        if (empty(array_filter([$message, $type]))) {
18
+        if( empty(array_filter( [$message, $type] )) ) {
19 19
             return;
20 20
         }
21 21
         $args['message'] = $message;
22 22
         $args['type'] = $type;
23
-        add_settings_error(Application::ID, '', json_encode($this->normalize($args)));
23
+        add_settings_error( Application::ID, '', json_encode( $this->normalize( $args ) ) );
24 24
     }
25 25
 
26 26
     /**
27 27
      * @param string|array|WP_Error $message
28 28
      * @return void
29 29
      */
30
-    public function addError($message, array $args = [])
30
+    public function addError( $message, array $args = [] )
31 31
     {
32
-        $this->add('error', $message, $args);
32
+        $this->add( 'error', $message, $args );
33 33
     }
34 34
 
35 35
     /**
36 36
      * @param string|array|WP_Error $message
37 37
      * @return void
38 38
      */
39
-    public function addSuccess($message, array $args = [])
39
+    public function addSuccess( $message, array $args = [] )
40 40
     {
41
-        $this->add('success', $message, $args);
41
+        $this->add( 'success', $message, $args );
42 42
     }
43 43
 
44 44
     /**
45 45
      * @param string|array|WP_Error $message
46 46
      * @return void
47 47
      */
48
-    public function addWarning($message, array $args = [])
48
+    public function addWarning( $message, array $args = [] )
49 49
     {
50
-        $this->add('warning', $message, $args);
50
+        $this->add( 'warning', $message, $args );
51 51
     }
52 52
 
53 53
     /**
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
     {
58 58
         global $wp_settings_errors;
59 59
         $wp_settings_errors = [];
60
-        delete_transient('settings_errors');
60
+        delete_transient( 'settings_errors' );
61 61
         return $this;
62 62
     }
63 63
 
@@ -66,41 +66,41 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function get()
68 68
     {
69
-        $notices = array_map('unserialize',
70
-            array_unique(array_map('serialize', get_settings_errors(Application::ID)))
69
+        $notices = array_map( 'unserialize',
70
+            array_unique( array_map( 'serialize', get_settings_errors( Application::ID ) ) )
71 71
         );
72
-        if (empty($notices)) {
72
+        if( empty($notices) ) {
73 73
             return;
74 74
         }
75
-        return array_reduce($notices, function ($carry, $notice) {
76
-            return $carry.$this->buildNotice(json_decode($notice['message'], true));
75
+        return array_reduce( $notices, function( $carry, $notice ) {
76
+            return $carry.$this->buildNotice( json_decode( $notice['message'], true ) );
77 77
         });
78 78
     }
79 79
 
80 80
     /**
81 81
      * @return string
82 82
      */
83
-    protected function buildNotice(array $args)
83
+    protected function buildNotice( array $args )
84 84
     {
85
-        $messages = array_reduce($args['messages'], function ($carry, $message) {
86
-            return $carry.glsr(Builder::class)->p($message);
85
+        $messages = array_reduce( $args['messages'], function( $carry, $message ) {
86
+            return $carry.glsr( Builder::class )->p( $message );
87 87
         });
88 88
         $class = 'notice notice-'.$args['type'];
89
-        if ($args['inline']) {
90
-            $class.= ' inline';
89
+        if( $args['inline'] ) {
90
+            $class .= ' inline';
91 91
         }
92
-        if ($args['dismissible']) {
93
-            $class.= ' is-dismissible';
92
+        if( $args['dismissible'] ) {
93
+            $class .= ' is-dismissible';
94 94
         }
95
-        return glsr(Builder::class)->div($messages, [
95
+        return glsr( Builder::class )->div( $messages, [
96 96
             'class' => $class,
97
-        ]);
97
+        ] );
98 98
     }
99 99
 
100 100
     /**
101 101
      * @return array
102 102
      */
103
-    protected function normalize(array $args)
103
+    protected function normalize( array $args )
104 104
     {
105 105
         $defaults = [
106 106
             'dismissible' => true,
@@ -108,13 +108,13 @@  discard block
 block discarded – undo
108 108
             'message' => '',
109 109
             'type' => '',
110 110
         ];
111
-        $args = shortcode_atts($defaults, $args);
112
-        if (!in_array($args['type'], ['error', 'warning', 'success'])) {
111
+        $args = shortcode_atts( $defaults, $args );
112
+        if( !in_array( $args['type'], ['error', 'warning', 'success'] ) ) {
113 113
             $args['type'] = 'success';
114 114
         }
115
-        $args['messages'] = is_wp_error($args['message'])
116
-            ? (array) $args['message']->get_error_message()
117
-            : (array) $args['message'];
115
+        $args['messages'] = is_wp_error( $args['message'] )
116
+            ? (array)$args['message']->get_error_message()
117
+            : (array)$args['message'];
118 118
         unset($args['message']);
119 119
         return $args;
120 120
     }
Please login to merge, or discard this patch.
plugin/Modules/Session.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -10,216 +10,216 @@
 block discarded – undo
10 10
  */
11 11
 class Session
12 12
 {
13
-    const DELIMITER = '__';
14
-
15
-    const SESSION_COOKIE = '_glsr_session';
16
-
17
-    /**
18
-     * @var int
19
-     */
20
-    protected $expiryTimestamp;
21
-
22
-    /**
23
-     * @var int
24
-     */
25
-    protected $expiryTimestampReset;
26
-
27
-    /**
28
-     * @var array
29
-     */
30
-    protected $sessionData;
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    protected $sessionId;
36
-
37
-    public function __construct()
38
-    {
39
-        $cookieId = filter_input(INPUT_COOKIE, static::SESSION_COOKIE);
40
-        if (false !== strpos($cookieId, static::DELIMITER)) {
41
-            $cookie = explode(static::DELIMITER, stripslashes($cookieId));
42
-            $this->sessionId = preg_replace('/[^A-Za-z0-9_]/', '', $cookie[0]);
43
-            $this->expiryTimestamp = absint($cookie[1]);
44
-            $this->expiryTimestampReset = absint($cookie[2]);
45
-            if (time() > $this->expiryTimestampReset) {
46
-                $this->setCookieExpiration();
47
-            }
48
-        } else {
49
-            $this->sessionId = $this->generateSessionId();
50
-            $this->setCookieExpiration();
51
-        }
52
-        $this->getSessionData();
53
-        $this->setCookie();
54
-    }
55
-
56
-    /**
57
-     * @return void
58
-     */
59
-    public function clear()
60
-    {
61
-        $this->setCookieExpiration();
62
-        $this->regenerateSessionId('and delete session!');
63
-    }
64
-
65
-    /**
66
-     * @return int|false
67
-     */
68
-    public function deleteAllSessions()
69
-    {
70
-        return glsr(SqlQueries::class)->deleteAllSessions(static::SESSION_COOKIE);
71
-    }
72
-
73
-    /**
74
-     * @param int $limit
75
-     * @return void
76
-     */
77
-    public function deleteExpiredSessions($limit = 1000)
78
-    {
79
-        if ($expiredSessions = implode("','", $this->getExpiredSessions($limit))) {
80
-            glsr(SqlQueries::class)->deleteExpiredSessions($expiredSessions);
81
-        }
82
-    }
83
-
84
-    /**
85
-     * @param string $key
86
-     * @param string|array $fallback
87
-     * @param bool|string $unset
88
-     * @return string|array
89
-     */
90
-    public function get($key, $fallback = '', $unset = false)
91
-    {
92
-        $key = sanitize_key($key);
93
-        $value = isset($this->sessionData[$key])
94
-            ? maybe_unserialize($this->sessionData[$key])
95
-            : $fallback;
96
-        if (isset($this->sessionData[$key]) && $unset) {
97
-            unset($this->sessionData[$key]);
98
-            $this->updateSession();
99
-        }
100
-        return $value;
101
-    }
102
-
103
-    /**
104
-     * @param string $key
105
-     * @param mixed $value
106
-     * @return mixed
107
-     */
108
-    public function set($key, $value)
109
-    {
110
-        $key = sanitize_key($key);
111
-        $this->sessionData[$key] = maybe_serialize($value);
112
-        $this->updateSession();
113
-        return $this->sessionData[$key];
114
-    }
115
-
116
-    /**
117
-     * @return void
118
-     */
119
-    protected function createSession()
120
-    {
121
-        add_option($this->getSessionId(), $this->sessionData, '', false);
122
-        add_option($this->getSessionId('expires'), $this->expiryTimestamp, '', false);
123
-    }
124
-
125
-    /**
126
-     * @return void
127
-     */
128
-    protected function deleteSession()
129
-    {
130
-        delete_option($this->getSessionId());
131
-        delete_option($this->getSessionId('expires'));
132
-    }
133
-
134
-    /**
135
-     * @return string
136
-     */
137
-    protected function generateSessionId()
138
-    {
139
-        return md5((new PasswordHash(8, false))->get_random_bytes(32));
140
-    }
141
-
142
-    /**
143
-     * @param int $limit
144
-     * @return array
145
-     */
146
-    protected function getExpiredSessions($limit)
147
-    {
148
-        $expiredSessions = [];
149
-        $sessions = glsr(SqlQueries::class)->getExpiredSessions(static::SESSION_COOKIE, absint($limit));
150
-        if (!empty($sessions)) {
151
-            $now = time();
152
-            foreach ($sessions as $session) {
153
-                if ($now <= $session->expiration) {
154
-                    continue;
155
-                }
156
-                $expiredSessions[] = $session->name;
157
-                $expiredSessions[] = str_replace('_expires_', '_', $session->name);
158
-            }
159
-        }
160
-        return $expiredSessions;
161
-    }
162
-
163
-    /**
164
-     * @param string $separator
165
-     * @return string
166
-     */
167
-    protected function getSessionId($separator = '')
168
-    {
169
-        return implode('_', array_filter([static::SESSION_COOKIE, $separator, $this->sessionId]));
170
-    }
171
-
172
-    /**
173
-     * @return array
174
-     */
175
-    protected function getSessionData()
176
-    {
177
-        return $this->sessionData = (array) get_option($this->getSessionId(), []);
178
-    }
179
-
180
-    /**
181
-     * @param bool|string $deleteOld
182
-     * @return void
183
-     */
184
-    protected function regenerateSessionId($deleteOld = false)
185
-    {
186
-        if ($deleteOld) {
187
-            $this->deleteSession();
188
-        }
189
-        $this->sessionId = $this->generateSessionId();
190
-        $this->setCookie();
191
-    }
192
-
193
-    /**
194
-     * @return void
195
-     */
196
-    protected function setCookie()
197
-    {
198
-        if (headers_sent()) {
199
-            return;
200
-        }
201
-        $cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset;
202
-        $cookiePath = preg_replace('|https?://[^/]+|i', '', trailingslashit((string) get_option('home')));
203
-        setcookie(static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath);
204
-    }
205
-
206
-    /**
207
-     * @return void
208
-     */
209
-    protected function setCookieExpiration()
210
-    {
211
-        $this->expiryTimestampReset = time() + (24 * 60); // 24 minutes
212
-        $this->expiryTimestamp = time() + (30 * 60); // 30 minutes
213
-    }
214
-
215
-    /**
216
-     * @return void
217
-     */
218
-    protected function updateSession()
219
-    {
220
-        if (false === get_option($this->getSessionId())) {
221
-            return $this->createSession();
222
-        }
223
-        update_option($this->getSessionId(), $this->sessionData, false);
224
-    }
13
+	const DELIMITER = '__';
14
+
15
+	const SESSION_COOKIE = '_glsr_session';
16
+
17
+	/**
18
+	 * @var int
19
+	 */
20
+	protected $expiryTimestamp;
21
+
22
+	/**
23
+	 * @var int
24
+	 */
25
+	protected $expiryTimestampReset;
26
+
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected $sessionData;
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	protected $sessionId;
36
+
37
+	public function __construct()
38
+	{
39
+		$cookieId = filter_input(INPUT_COOKIE, static::SESSION_COOKIE);
40
+		if (false !== strpos($cookieId, static::DELIMITER)) {
41
+			$cookie = explode(static::DELIMITER, stripslashes($cookieId));
42
+			$this->sessionId = preg_replace('/[^A-Za-z0-9_]/', '', $cookie[0]);
43
+			$this->expiryTimestamp = absint($cookie[1]);
44
+			$this->expiryTimestampReset = absint($cookie[2]);
45
+			if (time() > $this->expiryTimestampReset) {
46
+				$this->setCookieExpiration();
47
+			}
48
+		} else {
49
+			$this->sessionId = $this->generateSessionId();
50
+			$this->setCookieExpiration();
51
+		}
52
+		$this->getSessionData();
53
+		$this->setCookie();
54
+	}
55
+
56
+	/**
57
+	 * @return void
58
+	 */
59
+	public function clear()
60
+	{
61
+		$this->setCookieExpiration();
62
+		$this->regenerateSessionId('and delete session!');
63
+	}
64
+
65
+	/**
66
+	 * @return int|false
67
+	 */
68
+	public function deleteAllSessions()
69
+	{
70
+		return glsr(SqlQueries::class)->deleteAllSessions(static::SESSION_COOKIE);
71
+	}
72
+
73
+	/**
74
+	 * @param int $limit
75
+	 * @return void
76
+	 */
77
+	public function deleteExpiredSessions($limit = 1000)
78
+	{
79
+		if ($expiredSessions = implode("','", $this->getExpiredSessions($limit))) {
80
+			glsr(SqlQueries::class)->deleteExpiredSessions($expiredSessions);
81
+		}
82
+	}
83
+
84
+	/**
85
+	 * @param string $key
86
+	 * @param string|array $fallback
87
+	 * @param bool|string $unset
88
+	 * @return string|array
89
+	 */
90
+	public function get($key, $fallback = '', $unset = false)
91
+	{
92
+		$key = sanitize_key($key);
93
+		$value = isset($this->sessionData[$key])
94
+			? maybe_unserialize($this->sessionData[$key])
95
+			: $fallback;
96
+		if (isset($this->sessionData[$key]) && $unset) {
97
+			unset($this->sessionData[$key]);
98
+			$this->updateSession();
99
+		}
100
+		return $value;
101
+	}
102
+
103
+	/**
104
+	 * @param string $key
105
+	 * @param mixed $value
106
+	 * @return mixed
107
+	 */
108
+	public function set($key, $value)
109
+	{
110
+		$key = sanitize_key($key);
111
+		$this->sessionData[$key] = maybe_serialize($value);
112
+		$this->updateSession();
113
+		return $this->sessionData[$key];
114
+	}
115
+
116
+	/**
117
+	 * @return void
118
+	 */
119
+	protected function createSession()
120
+	{
121
+		add_option($this->getSessionId(), $this->sessionData, '', false);
122
+		add_option($this->getSessionId('expires'), $this->expiryTimestamp, '', false);
123
+	}
124
+
125
+	/**
126
+	 * @return void
127
+	 */
128
+	protected function deleteSession()
129
+	{
130
+		delete_option($this->getSessionId());
131
+		delete_option($this->getSessionId('expires'));
132
+	}
133
+
134
+	/**
135
+	 * @return string
136
+	 */
137
+	protected function generateSessionId()
138
+	{
139
+		return md5((new PasswordHash(8, false))->get_random_bytes(32));
140
+	}
141
+
142
+	/**
143
+	 * @param int $limit
144
+	 * @return array
145
+	 */
146
+	protected function getExpiredSessions($limit)
147
+	{
148
+		$expiredSessions = [];
149
+		$sessions = glsr(SqlQueries::class)->getExpiredSessions(static::SESSION_COOKIE, absint($limit));
150
+		if (!empty($sessions)) {
151
+			$now = time();
152
+			foreach ($sessions as $session) {
153
+				if ($now <= $session->expiration) {
154
+					continue;
155
+				}
156
+				$expiredSessions[] = $session->name;
157
+				$expiredSessions[] = str_replace('_expires_', '_', $session->name);
158
+			}
159
+		}
160
+		return $expiredSessions;
161
+	}
162
+
163
+	/**
164
+	 * @param string $separator
165
+	 * @return string
166
+	 */
167
+	protected function getSessionId($separator = '')
168
+	{
169
+		return implode('_', array_filter([static::SESSION_COOKIE, $separator, $this->sessionId]));
170
+	}
171
+
172
+	/**
173
+	 * @return array
174
+	 */
175
+	protected function getSessionData()
176
+	{
177
+		return $this->sessionData = (array) get_option($this->getSessionId(), []);
178
+	}
179
+
180
+	/**
181
+	 * @param bool|string $deleteOld
182
+	 * @return void
183
+	 */
184
+	protected function regenerateSessionId($deleteOld = false)
185
+	{
186
+		if ($deleteOld) {
187
+			$this->deleteSession();
188
+		}
189
+		$this->sessionId = $this->generateSessionId();
190
+		$this->setCookie();
191
+	}
192
+
193
+	/**
194
+	 * @return void
195
+	 */
196
+	protected function setCookie()
197
+	{
198
+		if (headers_sent()) {
199
+			return;
200
+		}
201
+		$cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset;
202
+		$cookiePath = preg_replace('|https?://[^/]+|i', '', trailingslashit((string) get_option('home')));
203
+		setcookie(static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath);
204
+	}
205
+
206
+	/**
207
+	 * @return void
208
+	 */
209
+	protected function setCookieExpiration()
210
+	{
211
+		$this->expiryTimestampReset = time() + (24 * 60); // 24 minutes
212
+		$this->expiryTimestamp = time() + (30 * 60); // 30 minutes
213
+	}
214
+
215
+	/**
216
+	 * @return void
217
+	 */
218
+	protected function updateSession()
219
+	{
220
+		if (false === get_option($this->getSessionId())) {
221
+			return $this->createSession();
222
+		}
223
+		update_option($this->getSessionId(), $this->sessionData, false);
224
+	}
225 225
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
 
37 37
     public function __construct()
38 38
     {
39
-        $cookieId = filter_input(INPUT_COOKIE, static::SESSION_COOKIE);
40
-        if (false !== strpos($cookieId, static::DELIMITER)) {
41
-            $cookie = explode(static::DELIMITER, stripslashes($cookieId));
42
-            $this->sessionId = preg_replace('/[^A-Za-z0-9_]/', '', $cookie[0]);
43
-            $this->expiryTimestamp = absint($cookie[1]);
44
-            $this->expiryTimestampReset = absint($cookie[2]);
45
-            if (time() > $this->expiryTimestampReset) {
39
+        $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE );
40
+        if( false !== strpos( $cookieId, static::DELIMITER ) ) {
41
+            $cookie = explode( static::DELIMITER, stripslashes( $cookieId ) );
42
+            $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] );
43
+            $this->expiryTimestamp = absint( $cookie[1] );
44
+            $this->expiryTimestampReset = absint( $cookie[2] );
45
+            if( time() > $this->expiryTimestampReset ) {
46 46
                 $this->setCookieExpiration();
47 47
             }
48 48
         } else {
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
     public function clear()
60 60
     {
61 61
         $this->setCookieExpiration();
62
-        $this->regenerateSessionId('and delete session!');
62
+        $this->regenerateSessionId( 'and delete session!' );
63 63
     }
64 64
 
65 65
     /**
@@ -67,17 +67,17 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public function deleteAllSessions()
69 69
     {
70
-        return glsr(SqlQueries::class)->deleteAllSessions(static::SESSION_COOKIE);
70
+        return glsr( SqlQueries::class )->deleteAllSessions( static::SESSION_COOKIE );
71 71
     }
72 72
 
73 73
     /**
74 74
      * @param int $limit
75 75
      * @return void
76 76
      */
77
-    public function deleteExpiredSessions($limit = 1000)
77
+    public function deleteExpiredSessions( $limit = 1000 )
78 78
     {
79
-        if ($expiredSessions = implode("','", $this->getExpiredSessions($limit))) {
80
-            glsr(SqlQueries::class)->deleteExpiredSessions($expiredSessions);
79
+        if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) {
80
+            glsr( SqlQueries::class )->deleteExpiredSessions( $expiredSessions );
81 81
         }
82 82
     }
83 83
 
@@ -87,13 +87,13 @@  discard block
 block discarded – undo
87 87
      * @param bool|string $unset
88 88
      * @return string|array
89 89
      */
90
-    public function get($key, $fallback = '', $unset = false)
90
+    public function get( $key, $fallback = '', $unset = false )
91 91
     {
92
-        $key = sanitize_key($key);
92
+        $key = sanitize_key( $key );
93 93
         $value = isset($this->sessionData[$key])
94
-            ? maybe_unserialize($this->sessionData[$key])
94
+            ? maybe_unserialize( $this->sessionData[$key] )
95 95
             : $fallback;
96
-        if (isset($this->sessionData[$key]) && $unset) {
96
+        if( isset($this->sessionData[$key]) && $unset ) {
97 97
             unset($this->sessionData[$key]);
98 98
             $this->updateSession();
99 99
         }
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
      * @param mixed $value
106 106
      * @return mixed
107 107
      */
108
-    public function set($key, $value)
108
+    public function set( $key, $value )
109 109
     {
110
-        $key = sanitize_key($key);
111
-        $this->sessionData[$key] = maybe_serialize($value);
110
+        $key = sanitize_key( $key );
111
+        $this->sessionData[$key] = maybe_serialize( $value );
112 112
         $this->updateSession();
113 113
         return $this->sessionData[$key];
114 114
     }
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
      */
119 119
     protected function createSession()
120 120
     {
121
-        add_option($this->getSessionId(), $this->sessionData, '', false);
122
-        add_option($this->getSessionId('expires'), $this->expiryTimestamp, '', false);
121
+        add_option( $this->getSessionId(), $this->sessionData, '', false );
122
+        add_option( $this->getSessionId( 'expires' ), $this->expiryTimestamp, '', false );
123 123
     }
124 124
 
125 125
     /**
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
      */
128 128
     protected function deleteSession()
129 129
     {
130
-        delete_option($this->getSessionId());
131
-        delete_option($this->getSessionId('expires'));
130
+        delete_option( $this->getSessionId() );
131
+        delete_option( $this->getSessionId( 'expires' ) );
132 132
     }
133 133
 
134 134
     /**
@@ -136,25 +136,25 @@  discard block
 block discarded – undo
136 136
      */
137 137
     protected function generateSessionId()
138 138
     {
139
-        return md5((new PasswordHash(8, false))->get_random_bytes(32));
139
+        return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) );
140 140
     }
141 141
 
142 142
     /**
143 143
      * @param int $limit
144 144
      * @return array
145 145
      */
146
-    protected function getExpiredSessions($limit)
146
+    protected function getExpiredSessions( $limit )
147 147
     {
148 148
         $expiredSessions = [];
149
-        $sessions = glsr(SqlQueries::class)->getExpiredSessions(static::SESSION_COOKIE, absint($limit));
150
-        if (!empty($sessions)) {
149
+        $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit ) );
150
+        if( !empty($sessions) ) {
151 151
             $now = time();
152
-            foreach ($sessions as $session) {
153
-                if ($now <= $session->expiration) {
152
+            foreach( $sessions as $session ) {
153
+                if( $now <= $session->expiration ) {
154 154
                     continue;
155 155
                 }
156 156
                 $expiredSessions[] = $session->name;
157
-                $expiredSessions[] = str_replace('_expires_', '_', $session->name);
157
+                $expiredSessions[] = str_replace( '_expires_', '_', $session->name );
158 158
             }
159 159
         }
160 160
         return $expiredSessions;
@@ -164,9 +164,9 @@  discard block
 block discarded – undo
164 164
      * @param string $separator
165 165
      * @return string
166 166
      */
167
-    protected function getSessionId($separator = '')
167
+    protected function getSessionId( $separator = '' )
168 168
     {
169
-        return implode('_', array_filter([static::SESSION_COOKIE, $separator, $this->sessionId]));
169
+        return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) );
170 170
     }
171 171
 
172 172
     /**
@@ -174,16 +174,16 @@  discard block
 block discarded – undo
174 174
      */
175 175
     protected function getSessionData()
176 176
     {
177
-        return $this->sessionData = (array) get_option($this->getSessionId(), []);
177
+        return $this->sessionData = (array)get_option( $this->getSessionId(), [] );
178 178
     }
179 179
 
180 180
     /**
181 181
      * @param bool|string $deleteOld
182 182
      * @return void
183 183
      */
184
-    protected function regenerateSessionId($deleteOld = false)
184
+    protected function regenerateSessionId( $deleteOld = false )
185 185
     {
186
-        if ($deleteOld) {
186
+        if( $deleteOld ) {
187 187
             $this->deleteSession();
188 188
         }
189 189
         $this->sessionId = $this->generateSessionId();
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
      */
196 196
     protected function setCookie()
197 197
     {
198
-        if (headers_sent()) {
198
+        if( headers_sent() ) {
199 199
             return;
200 200
         }
201 201
         $cookie = $this->sessionId.static::DELIMITER.$this->expiryTimestamp.static::DELIMITER.$this->expiryTimestampReset;
202
-        $cookiePath = preg_replace('|https?://[^/]+|i', '', trailingslashit((string) get_option('home')));
203
-        setcookie(static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath);
202
+        $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) );
203
+        setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath );
204 204
     }
205 205
 
206 206
     /**
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
      */
218 218
     protected function updateSession()
219 219
     {
220
-        if (false === get_option($this->getSessionId())) {
220
+        if( false === get_option( $this->getSessionId() ) ) {
221 221
             return $this->createSession();
222 222
         }
223
-        update_option($this->getSessionId(), $this->sessionData, false);
223
+        update_option( $this->getSessionId(), $this->sessionData, false );
224 224
     }
225 225
 }
Please login to merge, or discard this patch.
plugin/Modules/Translation.php 2 patches
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -10,272 +10,272 @@
 block discarded – undo
10 10
 
11 11
 class Translation
12 12
 {
13
-    const SEARCH_THRESHOLD = 3;
13
+	const SEARCH_THRESHOLD = 3;
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $entries;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $entries;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $results;
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $results;
24 24
 
25
-    /**
26
-     * Returns all saved custom translations with translation context.
27
-     * @return array
28
-     */
29
-    public function all()
30
-    {
31
-        $translations = $this->translations();
32
-        $entries = $this->filter($translations, $this->entries())->results();
33
-        array_walk($translations, function (&$entry) use ($entries) {
34
-            $entry['desc'] = array_key_exists($entry['id'], $entries)
35
-                ? $this->getEntryString($entries[$entry['id']], 'msgctxt')
36
-                : '';
37
-        });
38
-        return $translations;
39
-    }
25
+	/**
26
+	 * Returns all saved custom translations with translation context.
27
+	 * @return array
28
+	 */
29
+	public function all()
30
+	{
31
+		$translations = $this->translations();
32
+		$entries = $this->filter($translations, $this->entries())->results();
33
+		array_walk($translations, function (&$entry) use ($entries) {
34
+			$entry['desc'] = array_key_exists($entry['id'], $entries)
35
+				? $this->getEntryString($entries[$entry['id']], 'msgctxt')
36
+				: '';
37
+		});
38
+		return $translations;
39
+	}
40 40
 
41
-    /**
42
-     * @return array
43
-     */
44
-    public function entries()
45
-    {
46
-        if (!isset($this->entries)) {
47
-            $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
-            $entries = $this->extractEntriesFromPotFile($potFile);
49
-            $entries = apply_filters('site-reviews/translation/entries', $entries);
50
-            $this->entries = $entries;
51
-        }
52
-        return $this->entries;
53
-    }
41
+	/**
42
+	 * @return array
43
+	 */
44
+	public function entries()
45
+	{
46
+		if (!isset($this->entries)) {
47
+			$potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
+			$entries = $this->extractEntriesFromPotFile($potFile);
49
+			$entries = apply_filters('site-reviews/translation/entries', $entries);
50
+			$this->entries = $entries;
51
+		}
52
+		return $this->entries;
53
+	}
54 54
 
55
-    /**
56
-     * @param array|null $entriesToExclude
57
-     * @param array|null $entries
58
-     * @return static
59
-     */
60
-    public function exclude($entriesToExclude = null, $entries = null)
61
-    {
62
-        return $this->filter($entriesToExclude, $entries, false);
63
-    }
55
+	/**
56
+	 * @param array|null $entriesToExclude
57
+	 * @param array|null $entries
58
+	 * @return static
59
+	 */
60
+	public function exclude($entriesToExclude = null, $entries = null)
61
+	{
62
+		return $this->filter($entriesToExclude, $entries, false);
63
+	}
64 64
 
65
-    /**
66
-     * @param string $potFile
67
-     * @return array
68
-     */
69
-    public function extractEntriesFromPotFile($potFile, array $entries = [])
70
-    {
71
-        try {
72
-            $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
-            foreach ($potEntries as $key => $entry) {
74
-                $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
75
-            }
76
-        } catch (Exception $e) {
77
-            glsr_log()->error($e->getMessage());
78
-        }
79
-        return $entries;
80
-    }
65
+	/**
66
+	 * @param string $potFile
67
+	 * @return array
68
+	 */
69
+	public function extractEntriesFromPotFile($potFile, array $entries = [])
70
+	{
71
+		try {
72
+			$potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
+			foreach ($potEntries as $key => $entry) {
74
+				$entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
75
+			}
76
+		} catch (Exception $e) {
77
+			glsr_log()->error($e->getMessage());
78
+		}
79
+		return $entries;
80
+	}
81 81
 
82
-    /**
83
-     * @param array|null $filterWith
84
-     * @param array|null $entries
85
-     * @param bool $intersect
86
-     * @return static
87
-     */
88
-    public function filter($filterWith = null, $entries = null, $intersect = true)
89
-    {
90
-        if (!is_array($entries)) {
91
-            $entries = $this->results;
92
-        }
93
-        if (!is_array($filterWith)) {
94
-            $filterWith = $this->translations();
95
-        }
96
-        $keys = array_flip(glsr_array_column($filterWith, 'id'));
97
-        $this->results = $intersect
98
-            ? array_intersect_key($entries, $keys)
99
-            : array_diff_key($entries, $keys);
100
-        return $this;
101
-    }
82
+	/**
83
+	 * @param array|null $filterWith
84
+	 * @param array|null $entries
85
+	 * @param bool $intersect
86
+	 * @return static
87
+	 */
88
+	public function filter($filterWith = null, $entries = null, $intersect = true)
89
+	{
90
+		if (!is_array($entries)) {
91
+			$entries = $this->results;
92
+		}
93
+		if (!is_array($filterWith)) {
94
+			$filterWith = $this->translations();
95
+		}
96
+		$keys = array_flip(glsr_array_column($filterWith, 'id'));
97
+		$this->results = $intersect
98
+			? array_intersect_key($entries, $keys)
99
+			: array_diff_key($entries, $keys);
100
+		return $this;
101
+	}
102 102
 
103
-    /**
104
-     * @param string $template
105
-     * @return string
106
-     */
107
-    public function render($template, array $entry)
108
-    {
109
-        $data = array_combine(
110
-            array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
-            $entry
112
-        );
113
-        $data['data.class'] = $data['data.error'] = '';
114
-        if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
-            $data['data.class'] = 'is-invalid';
116
-            $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
-        }
118
-        return glsr(Template::class)->build('partials/translations/'.$template, [
119
-            'context' => $data,
120
-        ]);
121
-    }
103
+	/**
104
+	 * @param string $template
105
+	 * @return string
106
+	 */
107
+	public function render($template, array $entry)
108
+	{
109
+		$data = array_combine(
110
+			array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
+			$entry
112
+		);
113
+		$data['data.class'] = $data['data.error'] = '';
114
+		if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
+			$data['data.class'] = 'is-invalid';
116
+			$data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
+		}
118
+		return glsr(Template::class)->build('partials/translations/'.$template, [
119
+			'context' => $data,
120
+		]);
121
+	}
122 122
 
123
-    /**
124
-     * Returns a rendered string of all saved custom translations with translation context.
125
-     * @return string
126
-     */
127
-    public function renderAll()
128
-    {
129
-        $rendered = '';
130
-        foreach ($this->all() as $index => $entry) {
131
-            $entry['index'] = $index;
132
-            $entry['prefix'] = OptionManager::databaseKey();
133
-            $rendered.= $this->render($entry['type'], $entry);
134
-        }
135
-        return $rendered;
136
-    }
123
+	/**
124
+	 * Returns a rendered string of all saved custom translations with translation context.
125
+	 * @return string
126
+	 */
127
+	public function renderAll()
128
+	{
129
+		$rendered = '';
130
+		foreach ($this->all() as $index => $entry) {
131
+			$entry['index'] = $index;
132
+			$entry['prefix'] = OptionManager::databaseKey();
133
+			$rendered.= $this->render($entry['type'], $entry);
134
+		}
135
+		return $rendered;
136
+	}
137 137
 
138
-    /**
139
-     * @param bool $resetAfterRender
140
-     * @return string
141
-     */
142
-    public function renderResults($resetAfterRender = true)
143
-    {
144
-        $rendered = '';
145
-        foreach ($this->results as $id => $entry) {
146
-            $data = [
147
-                'desc' => $this->getEntryString($entry, 'msgctxt'),
148
-                'id' => $id,
149
-                'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
-                's1' => $this->getEntryString($entry, 'msgid'),
151
-            ];
152
-            $text = !empty($data['p1'])
153
-                ? sprintf('%s | %s', $data['s1'], $data['p1'])
154
-                : $data['s1'];
155
-            $rendered.= $this->render('result', [
156
-                'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
-                'text' => wp_strip_all_tags($text),
158
-            ]);
159
-        }
160
-        if ($resetAfterRender) {
161
-            $this->reset();
162
-        }
163
-        return $rendered;
164
-    }
138
+	/**
139
+	 * @param bool $resetAfterRender
140
+	 * @return string
141
+	 */
142
+	public function renderResults($resetAfterRender = true)
143
+	{
144
+		$rendered = '';
145
+		foreach ($this->results as $id => $entry) {
146
+			$data = [
147
+				'desc' => $this->getEntryString($entry, 'msgctxt'),
148
+				'id' => $id,
149
+				'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
+				's1' => $this->getEntryString($entry, 'msgid'),
151
+			];
152
+			$text = !empty($data['p1'])
153
+				? sprintf('%s | %s', $data['s1'], $data['p1'])
154
+				: $data['s1'];
155
+			$rendered.= $this->render('result', [
156
+				'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
+				'text' => wp_strip_all_tags($text),
158
+			]);
159
+		}
160
+		if ($resetAfterRender) {
161
+			$this->reset();
162
+		}
163
+		return $rendered;
164
+	}
165 165
 
166
-    /**
167
-     * @return void
168
-     */
169
-    public function reset()
170
-    {
171
-        $this->results = [];
172
-    }
166
+	/**
167
+	 * @return void
168
+	 */
169
+	public function reset()
170
+	{
171
+		$this->results = [];
172
+	}
173 173
 
174
-    /**
175
-     * @return array
176
-     */
177
-    public function results()
178
-    {
179
-        $results = $this->results;
180
-        $this->reset();
181
-        return $results;
182
-    }
174
+	/**
175
+	 * @return array
176
+	 */
177
+	public function results()
178
+	{
179
+		$results = $this->results;
180
+		$this->reset();
181
+		return $results;
182
+	}
183 183
 
184
-    /**
185
-     * @param string $needle
186
-     * @return static
187
-     */
188
-    public function search($needle = '')
189
-    {
190
-        $this->reset();
191
-        $needle = trim(strtolower($needle));
192
-        foreach ($this->entries() as $key => $entry) {
193
-            $single = strtolower($this->getEntryString($entry, 'msgid'));
194
-            $plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
-            if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
-                if (in_array($needle, [$single, $plural])) {
197
-                    $this->results[$key] = $entry;
198
-                }
199
-            } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
200
-                $this->results[$key] = $entry;
201
-            }
202
-        }
203
-        return $this;
204
-    }
184
+	/**
185
+	 * @param string $needle
186
+	 * @return static
187
+	 */
188
+	public function search($needle = '')
189
+	{
190
+		$this->reset();
191
+		$needle = trim(strtolower($needle));
192
+		foreach ($this->entries() as $key => $entry) {
193
+			$single = strtolower($this->getEntryString($entry, 'msgid'));
194
+			$plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
+			if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
+				if (in_array($needle, [$single, $plural])) {
197
+					$this->results[$key] = $entry;
198
+				}
199
+			} elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
200
+				$this->results[$key] = $entry;
201
+			}
202
+		}
203
+		return $this;
204
+	}
205 205
 
206
-    /**
207
-     * Store the translations to avoid unnecessary loops.
208
-     * @return array
209
-     */
210
-    public function translations()
211
-    {
212
-        static $translations;
213
-        if (empty($translations)) {
214
-            $settings = glsr(OptionManager::class)->get('settings');
215
-            $translations = isset($settings['strings'])
216
-                ? $this->normalizeSettings((array) $settings['strings'])
217
-                : [];
218
-        }
219
-        return $translations;
220
-    }
206
+	/**
207
+	 * Store the translations to avoid unnecessary loops.
208
+	 * @return array
209
+	 */
210
+	public function translations()
211
+	{
212
+		static $translations;
213
+		if (empty($translations)) {
214
+			$settings = glsr(OptionManager::class)->get('settings');
215
+			$translations = isset($settings['strings'])
216
+				? $this->normalizeSettings((array) $settings['strings'])
217
+				: [];
218
+		}
219
+		return $translations;
220
+	}
221 221
 
222
-    /**
223
-     * @param string $key
224
-     * @return string
225
-     */
226
-    protected function getEntryString(array $entry, $key)
227
-    {
228
-        return isset($entry[$key])
229
-            ? implode('', (array) $entry[$key])
230
-            : '';
231
-    }
222
+	/**
223
+	 * @param string $key
224
+	 * @return string
225
+	 */
226
+	protected function getEntryString(array $entry, $key)
227
+	{
228
+		return isset($entry[$key])
229
+			? implode('', (array) $entry[$key])
230
+			: '';
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    protected function normalize(array $entries)
237
-    {
238
-        $keys = [
239
-            'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240
-        ];
241
-        array_walk($entries, function (&$entry) use ($keys) {
242
-            foreach ($keys as $key) {
243
-                try {
244
-                    $entry = $this->normalizeEntryString($entry, $key);
245
-                } catch (\TypeError $error) {
246
-                    glsr_log()->once('error', 'Translation/normalize', $error);
247
-                    glsr_log()->once('debug', 'Translation/normalize', $entry);
248
-                }
249
-            }
250
-        });
251
-        return $entries;
252
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	protected function normalize(array $entries)
237
+	{
238
+		$keys = [
239
+			'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240
+		];
241
+		array_walk($entries, function (&$entry) use ($keys) {
242
+			foreach ($keys as $key) {
243
+				try {
244
+					$entry = $this->normalizeEntryString($entry, $key);
245
+				} catch (\TypeError $error) {
246
+					glsr_log()->once('error', 'Translation/normalize', $error);
247
+					glsr_log()->once('debug', 'Translation/normalize', $entry);
248
+				}
249
+			}
250
+		});
251
+		return $entries;
252
+	}
253 253
 
254
-    /**
255
-     * @param string $key
256
-     * @return array
257
-     */
258
-    protected function normalizeEntryString(array $entry, $key)
259
-    {
260
-        if (isset($entry[$key])) {
261
-            $entry[$key] = $this->getEntryString($entry, $key);
262
-        }
263
-        return $entry;
264
-    }
254
+	/**
255
+	 * @param string $key
256
+	 * @return array
257
+	 */
258
+	protected function normalizeEntryString(array $entry, $key)
259
+	{
260
+		if (isset($entry[$key])) {
261
+			$entry[$key] = $this->getEntryString($entry, $key);
262
+		}
263
+		return $entry;
264
+	}
265 265
 
266
-    /**
267
-     * @return array
268
-     */
269
-    protected function normalizeSettings(array $strings)
270
-    {
271
-        $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
-        $strings = array_filter($strings, 'is_array');
273
-        foreach ($strings as &$string) {
274
-            $string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
-            $string = wp_parse_args($string, $defaultString);
276
-        }
277
-        return array_filter($strings, function ($string) {
278
-            return !empty($string['id']);
279
-        });
280
-    }
266
+	/**
267
+	 * @return array
268
+	 */
269
+	protected function normalizeSettings(array $strings)
270
+	{
271
+		$defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
+		$strings = array_filter($strings, 'is_array');
273
+		foreach ($strings as &$string) {
274
+			$string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
+			$string = wp_parse_args($string, $defaultString);
276
+		}
277
+		return array_filter($strings, function ($string) {
278
+			return !empty($string['id']);
279
+		});
280
+	}
281 281
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     public function all()
30 30
     {
31 31
         $translations = $this->translations();
32
-        $entries = $this->filter($translations, $this->entries())->results();
33
-        array_walk($translations, function (&$entry) use ($entries) {
34
-            $entry['desc'] = array_key_exists($entry['id'], $entries)
35
-                ? $this->getEntryString($entries[$entry['id']], 'msgctxt')
32
+        $entries = $this->filter( $translations, $this->entries() )->results();
33
+        array_walk( $translations, function( &$entry ) use ($entries) {
34
+            $entry['desc'] = array_key_exists( $entry['id'], $entries )
35
+                ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' )
36 36
                 : '';
37 37
         });
38 38
         return $translations;
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function entries()
45 45
     {
46
-        if (!isset($this->entries)) {
47
-            $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
-            $entries = $this->extractEntriesFromPotFile($potFile);
49
-            $entries = apply_filters('site-reviews/translation/entries', $entries);
46
+        if( !isset($this->entries) ) {
47
+            $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' );
48
+            $entries = $this->extractEntriesFromPotFile( $potFile );
49
+            $entries = apply_filters( 'site-reviews/translation/entries', $entries );
50 50
             $this->entries = $entries;
51 51
         }
52 52
         return $this->entries;
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
      * @param array|null $entries
58 58
      * @return static
59 59
      */
60
-    public function exclude($entriesToExclude = null, $entries = null)
60
+    public function exclude( $entriesToExclude = null, $entries = null )
61 61
     {
62
-        return $this->filter($entriesToExclude, $entries, false);
62
+        return $this->filter( $entriesToExclude, $entries, false );
63 63
     }
64 64
 
65 65
     /**
66 66
      * @param string $potFile
67 67
      * @return array
68 68
      */
69
-    public function extractEntriesFromPotFile($potFile, array $entries = [])
69
+    public function extractEntriesFromPotFile( $potFile, array $entries = [] )
70 70
     {
71 71
         try {
72
-            $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
-            foreach ($potEntries as $key => $entry) {
74
-                $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
72
+            $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() );
73
+            foreach( $potEntries as $key => $entry ) {
74
+                $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry;
75 75
             }
76
-        } catch (Exception $e) {
77
-            glsr_log()->error($e->getMessage());
76
+        } catch( Exception $e ) {
77
+            glsr_log()->error( $e->getMessage() );
78 78
         }
79 79
         return $entries;
80 80
     }
@@ -85,18 +85,18 @@  discard block
 block discarded – undo
85 85
      * @param bool $intersect
86 86
      * @return static
87 87
      */
88
-    public function filter($filterWith = null, $entries = null, $intersect = true)
88
+    public function filter( $filterWith = null, $entries = null, $intersect = true )
89 89
     {
90
-        if (!is_array($entries)) {
90
+        if( !is_array( $entries ) ) {
91 91
             $entries = $this->results;
92 92
         }
93
-        if (!is_array($filterWith)) {
93
+        if( !is_array( $filterWith ) ) {
94 94
             $filterWith = $this->translations();
95 95
         }
96
-        $keys = array_flip(glsr_array_column($filterWith, 'id'));
96
+        $keys = array_flip( glsr_array_column( $filterWith, 'id' ) );
97 97
         $this->results = $intersect
98
-            ? array_intersect_key($entries, $keys)
99
-            : array_diff_key($entries, $keys);
98
+            ? array_intersect_key( $entries, $keys )
99
+            : array_diff_key( $entries, $keys );
100 100
         return $this;
101 101
     }
102 102
 
@@ -104,20 +104,20 @@  discard block
 block discarded – undo
104 104
      * @param string $template
105 105
      * @return string
106 106
      */
107
-    public function render($template, array $entry)
107
+    public function render( $template, array $entry )
108 108
     {
109 109
         $data = array_combine(
110
-            array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
110
+            array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ),
111 111
             $entry
112 112
         );
113 113
         $data['data.class'] = $data['data.error'] = '';
114
-        if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
114
+        if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) {
115 115
             $data['data.class'] = 'is-invalid';
116
-            $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
116
+            $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' );
117 117
         }
118
-        return glsr(Template::class)->build('partials/translations/'.$template, [
118
+        return glsr( Template::class )->build( 'partials/translations/'.$template, [
119 119
             'context' => $data,
120
-        ]);
120
+        ] );
121 121
     }
122 122
 
123 123
     /**
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
     public function renderAll()
128 128
     {
129 129
         $rendered = '';
130
-        foreach ($this->all() as $index => $entry) {
130
+        foreach( $this->all() as $index => $entry ) {
131 131
             $entry['index'] = $index;
132 132
             $entry['prefix'] = OptionManager::databaseKey();
133
-            $rendered.= $this->render($entry['type'], $entry);
133
+            $rendered .= $this->render( $entry['type'], $entry );
134 134
         }
135 135
         return $rendered;
136 136
     }
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
      * @param bool $resetAfterRender
140 140
      * @return string
141 141
      */
142
-    public function renderResults($resetAfterRender = true)
142
+    public function renderResults( $resetAfterRender = true )
143 143
     {
144 144
         $rendered = '';
145
-        foreach ($this->results as $id => $entry) {
145
+        foreach( $this->results as $id => $entry ) {
146 146
             $data = [
147
-                'desc' => $this->getEntryString($entry, 'msgctxt'),
147
+                'desc' => $this->getEntryString( $entry, 'msgctxt' ),
148 148
                 'id' => $id,
149
-                'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
-                's1' => $this->getEntryString($entry, 'msgid'),
149
+                'p1' => $this->getEntryString( $entry, 'msgid_plural' ),
150
+                's1' => $this->getEntryString( $entry, 'msgid' ),
151 151
             ];
152 152
             $text = !empty($data['p1'])
153
-                ? sprintf('%s | %s', $data['s1'], $data['p1'])
153
+                ? sprintf( '%s | %s', $data['s1'], $data['p1'] )
154 154
                 : $data['s1'];
155
-            $rendered.= $this->render('result', [
156
-                'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
-                'text' => wp_strip_all_tags($text),
158
-            ]);
155
+            $rendered .= $this->render( 'result', [
156
+                'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ),
157
+                'text' => wp_strip_all_tags( $text ),
158
+            ] );
159 159
         }
160
-        if ($resetAfterRender) {
160
+        if( $resetAfterRender ) {
161 161
             $this->reset();
162 162
         }
163 163
         return $rendered;
@@ -185,18 +185,18 @@  discard block
 block discarded – undo
185 185
      * @param string $needle
186 186
      * @return static
187 187
      */
188
-    public function search($needle = '')
188
+    public function search( $needle = '' )
189 189
     {
190 190
         $this->reset();
191
-        $needle = trim(strtolower($needle));
192
-        foreach ($this->entries() as $key => $entry) {
193
-            $single = strtolower($this->getEntryString($entry, 'msgid'));
194
-            $plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
-            if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
-                if (in_array($needle, [$single, $plural])) {
191
+        $needle = trim( strtolower( $needle ) );
192
+        foreach( $this->entries() as $key => $entry ) {
193
+            $single = strtolower( $this->getEntryString( $entry, 'msgid' ) );
194
+            $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) );
195
+            if( strlen( $needle ) < static::SEARCH_THRESHOLD ) {
196
+                if( in_array( $needle, [$single, $plural] ) ) {
197 197
                     $this->results[$key] = $entry;
198 198
                 }
199
-            } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
199
+            } elseif( false !== strpos( sprintf( '%s %s', $single, $plural ), $needle ) ) {
200 200
                 $this->results[$key] = $entry;
201 201
             }
202 202
         }
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
     public function translations()
211 211
     {
212 212
         static $translations;
213
-        if (empty($translations)) {
214
-            $settings = glsr(OptionManager::class)->get('settings');
213
+        if( empty($translations) ) {
214
+            $settings = glsr( OptionManager::class )->get( 'settings' );
215 215
             $translations = isset($settings['strings'])
216
-                ? $this->normalizeSettings((array) $settings['strings'])
216
+                ? $this->normalizeSettings( (array)$settings['strings'] )
217 217
                 : [];
218 218
         }
219 219
         return $translations;
@@ -223,28 +223,28 @@  discard block
 block discarded – undo
223 223
      * @param string $key
224 224
      * @return string
225 225
      */
226
-    protected function getEntryString(array $entry, $key)
226
+    protected function getEntryString( array $entry, $key )
227 227
     {
228 228
         return isset($entry[$key])
229
-            ? implode('', (array) $entry[$key])
229
+            ? implode( '', (array)$entry[$key] )
230 230
             : '';
231 231
     }
232 232
 
233 233
     /**
234 234
      * @return array
235 235
      */
236
-    protected function normalize(array $entries)
236
+    protected function normalize( array $entries )
237 237
     {
238 238
         $keys = [
239 239
             'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240 240
         ];
241
-        array_walk($entries, function (&$entry) use ($keys) {
242
-            foreach ($keys as $key) {
241
+        array_walk( $entries, function( &$entry ) use ($keys) {
242
+            foreach( $keys as $key ) {
243 243
                 try {
244
-                    $entry = $this->normalizeEntryString($entry, $key);
245
-                } catch (\TypeError $error) {
246
-                    glsr_log()->once('error', 'Translation/normalize', $error);
247
-                    glsr_log()->once('debug', 'Translation/normalize', $entry);
244
+                    $entry = $this->normalizeEntryString( $entry, $key );
245
+                } catch( \TypeError $error ) {
246
+                    glsr_log()->once( 'error', 'Translation/normalize', $error );
247
+                    glsr_log()->once( 'debug', 'Translation/normalize', $entry );
248 248
                 }
249 249
             }
250 250
         });
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
      * @param string $key
256 256
      * @return array
257 257
      */
258
-    protected function normalizeEntryString(array $entry, $key)
258
+    protected function normalizeEntryString( array $entry, $key )
259 259
     {
260
-        if (isset($entry[$key])) {
261
-            $entry[$key] = $this->getEntryString($entry, $key);
260
+        if( isset($entry[$key]) ) {
261
+            $entry[$key] = $this->getEntryString( $entry, $key );
262 262
         }
263 263
         return $entry;
264 264
     }
@@ -266,15 +266,15 @@  discard block
 block discarded – undo
266 266
     /**
267 267
      * @return array
268 268
      */
269
-    protected function normalizeSettings(array $strings)
269
+    protected function normalizeSettings( array $strings )
270 270
     {
271
-        $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
-        $strings = array_filter($strings, 'is_array');
273
-        foreach ($strings as &$string) {
271
+        $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' );
272
+        $strings = array_filter( $strings, 'is_array' );
273
+        foreach( $strings as &$string ) {
274 274
             $string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
-            $string = wp_parse_args($string, $defaultString);
275
+            $string = wp_parse_args( $string, $defaultString );
276 276
         }
277
-        return array_filter($strings, function ($string) {
277
+        return array_filter( $strings, function( $string ) {
278 278
             return !empty($string['id']);
279 279
         });
280 280
     }
Please login to merge, or discard this patch.