Passed
Push — master ( 6b35fa...ccb079 )
by Paul
10:24 queued 05:13
created
plugin/Modules/Html/Fields/YesNo.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -4,38 +4,38 @@
 block discarded – undo
4 4
 
5 5
 class YesNo extends Field
6 6
 {
7
-    /**
8
-     * @return string|void
9
-     */
10
-    public function build()
11
-    {
12
-        $this->builder->tag = 'input';
13
-        $this->mergeFieldArgs();
14
-        return $this->builder->getTag();
15
-    }
7
+	/**
8
+	 * @return string|void
9
+	 */
10
+	public function build()
11
+	{
12
+		$this->builder->tag = 'input';
13
+		$this->mergeFieldArgs();
14
+		return $this->builder->getTag();
15
+	}
16 16
 
17
-    /**
18
-     * @return array
19
-     */
20
-    public static function defaults()
21
-    {
22
-        return [
23
-            'class' => 'inline',
24
-        ];
25
-    }
17
+	/**
18
+	 * @return array
19
+	 */
20
+	public static function defaults()
21
+	{
22
+		return [
23
+			'class' => 'inline',
24
+		];
25
+	}
26 26
 
27
-    /**
28
-     * @return array
29
-     */
30
-    public static function required()
31
-    {
32
-        return [
33
-            'is_multi' => true,
34
-            'options' => [
35
-                'no' => __('No', 'site-reviews'),
36
-                'yes' => __('Yes', 'site-reviews'),
37
-            ],
38
-            'type' => 'radio',
39
-        ];
40
-    }
27
+	/**
28
+	 * @return array
29
+	 */
30
+	public static function required()
31
+	{
32
+		return [
33
+			'is_multi' => true,
34
+			'options' => [
35
+				'no' => __('No', 'site-reviews'),
36
+				'yes' => __('Yes', 'site-reviews'),
37
+			],
38
+			'type' => 'radio',
39
+		];
40
+	}
41 41
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@
 block discarded – undo
32 32
         return [
33 33
             'is_multi' => true,
34 34
             'options' => [
35
-                'no' => __('No', 'site-reviews'),
36
-                'yes' => __('Yes', 'site-reviews'),
35
+                'no' => __( 'No', 'site-reviews' ),
36
+                'yes' => __( 'Yes', 'site-reviews' ),
37 37
             ],
38 38
             'type' => 'radio',
39 39
         ];
Please login to merge, or discard this patch.
plugin/Modules/Html/Fields/Number.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -4,13 +4,13 @@
 block discarded – undo
4 4
 
5 5
 class Number extends Field
6 6
 {
7
-    /**
8
-     * @return array
9
-     */
10
-    public static function defaults()
11
-    {
12
-        return [
13
-            'class' => 'small-text',
14
-        ];
15
-    }
7
+	/**
8
+	 * @return array
9
+	 */
10
+	public static function defaults()
11
+	{
12
+		return [
13
+			'class' => 'small-text',
14
+		];
15
+	}
16 16
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Fields/Checkbox.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,23 +4,23 @@
 block discarded – undo
4 4
 
5 5
 class Checkbox extends Field
6 6
 {
7
-    /**
8
-     * @return array
9
-     */
10
-    public static function defaults()
11
-    {
12
-        return [
13
-            'value' => 1,
14
-        ];
15
-    }
7
+	/**
8
+	 * @return array
9
+	 */
10
+	public static function defaults()
11
+	{
12
+		return [
13
+			'value' => 1,
14
+		];
15
+	}
16 16
 
17
-    /**
18
-     * @return array
19
-     */
20
-    public static function required()
21
-    {
22
-        return [
23
-            'is_multi' => true,
24
-        ];
25
-    }
17
+	/**
18
+	 * @return array
19
+	 */
20
+	public static function required()
21
+	{
22
+		return [
23
+			'is_multi' => true,
24
+		];
25
+	}
26 26
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Fields/Rating.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 class Rating extends Field
8 8
 {
9
-    /**
10
-     * @return string|void
11
-     */
12
-    public function build()
13
-    {
14
-        $this->builder->tag = 'select';
15
-        $this->mergeFieldArgs();
16
-        return $this->builder->getTag();
17
-    }
9
+	/**
10
+	 * @return string|void
11
+	 */
12
+	public function build()
13
+	{
14
+		$this->builder->tag = 'select';
15
+		$this->mergeFieldArgs();
16
+		return $this->builder->getTag();
17
+	}
18 18
 
19
-    /**
20
-     * @return array
21
-     */
22
-    public static function required()
23
-    {
24
-        $options = ['' => __('Select a Rating', 'site-reviews')];
25
-        foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) {
26
-            $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating);
27
-        }
28
-        return [
29
-            'class' => 'glsr-star-rating',
30
-            'options' => $options,
31
-            'type' => 'select',
32
-        ];
33
-    }
19
+	/**
20
+	 * @return array
21
+	 */
22
+	public static function required()
23
+	{
24
+		$options = ['' => __('Select a Rating', 'site-reviews')];
25
+		foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) {
26
+			$options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating);
27
+		}
28
+		return [
29
+			'class' => 'glsr-star-rating',
30
+			'options' => $options,
31
+			'type' => 'select',
32
+		];
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,9 +21,9 @@
 block discarded – undo
21 21
      */
22 22
     public static function required()
23 23
     {
24
-        $options = ['' => __('Select a Rating', 'site-reviews')];
25
-        foreach (range(glsr()->constant('MAX_RATING', RatingModule::class), 1) as $rating) {
26
-            $options[$rating] = sprintf(_n('%s Star', '%s Stars', $rating, 'site-reviews'), $rating);
24
+        $options = ['' => __( 'Select a Rating', 'site-reviews' )];
25
+        foreach( range( glsr()->constant( 'MAX_RATING', RatingModule::class ), 1 ) as $rating ) {
26
+            $options[$rating] = sprintf( _n( '%s Star', '%s Stars', $rating, 'site-reviews' ), $rating );
27 27
         }
28 28
         return [
29 29
             'class' => 'glsr-star-rating',
Please login to merge, or discard this patch.
plugin/Modules/Html/Form.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -4,36 +4,36 @@
 block discarded – undo
4 4
 
5 5
 class Form
6 6
 {
7
-    /**
8
-     * @param string $id
9
-     * @return string
10
-     */
11
-    public function buildFields($id)
12
-    {
13
-        return array_reduce($this->getFields($id), function ($carry, $field) {
14
-            return $carry.$field;
15
-        });
16
-    }
7
+	/**
8
+	 * @param string $id
9
+	 * @return string
10
+	 */
11
+	public function buildFields($id)
12
+	{
13
+		return array_reduce($this->getFields($id), function ($carry, $field) {
14
+			return $carry.$field;
15
+		});
16
+	}
17 17
 
18
-    /**
19
-     * @param string $id
20
-     * @return array
21
-     */
22
-    public function getFields($id)
23
-    {
24
-        $fields = [];
25
-        foreach (glsr()->config('forms/'.$id) as $name => $field) {
26
-            $fields[] = new Field(wp_parse_args($field, ['name' => $name]));
27
-        }
28
-        return $fields;
29
-    }
18
+	/**
19
+	 * @param string $id
20
+	 * @return array
21
+	 */
22
+	public function getFields($id)
23
+	{
24
+		$fields = [];
25
+		foreach (glsr()->config('forms/'.$id) as $name => $field) {
26
+			$fields[] = new Field(wp_parse_args($field, ['name' => $name]));
27
+		}
28
+		return $fields;
29
+	}
30 30
 
31
-    /**
32
-     * @param string $id
33
-     * @return void
34
-     */
35
-    public function renderFields($id)
36
-    {
37
-        echo $this->buildFields($id);
38
-    }
31
+	/**
32
+	 * @param string $id
33
+	 * @return void
34
+	 */
35
+	public function renderFields($id)
36
+	{
37
+		echo $this->buildFields($id);
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  discard block
 block discarded – undo
8 8
      * @param string $id
9 9
      * @return string
10 10
      */
11
-    public function buildFields($id)
11
+    public function buildFields( $id )
12 12
     {
13
-        return array_reduce($this->getFields($id), function ($carry, $field) {
13
+        return array_reduce( $this->getFields( $id ), function( $carry, $field ) {
14 14
             return $carry.$field;
15 15
         });
16 16
     }
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
      * @param string $id
20 20
      * @return array
21 21
      */
22
-    public function getFields($id)
22
+    public function getFields( $id )
23 23
     {
24 24
         $fields = [];
25
-        foreach (glsr()->config('forms/'.$id) as $name => $field) {
26
-            $fields[] = new Field(wp_parse_args($field, ['name' => $name]));
25
+        foreach( glsr()->config( 'forms/'.$id ) as $name => $field ) {
26
+            $fields[] = new Field( wp_parse_args( $field, ['name' => $name] ) );
27 27
         }
28 28
         return $fields;
29 29
     }
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
      * @param string $id
33 33
      * @return void
34 34
      */
35
-    public function renderFields($id)
35
+    public function renderFields( $id )
36 36
     {
37
-        echo $this->buildFields($id);
37
+        echo $this->buildFields( $id );
38 38
     }
39 39
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviewsForm.php 3 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -302,7 +302,8 @@
 block discarded – undo
302 302
         }
303 303
         if (in_array($field->field['type'], ['radio', 'checkbox'])) {
304 304
             $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
305
-        } else {
305
+        }
306
+        else {
306 307
             $field->field['value'] = $this->values[$field->field['path']];
307 308
         }
308 309
     }
Please login to merge, or discard this patch.
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -12,297 +12,297 @@
 block discarded – undo
12 12
 
13 13
 class SiteReviewsForm
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $errors;
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $errors;
24 24
 
25
-    /**
26
-     * @var string
27
-     */
28
-    protected $message;
25
+	/**
26
+	 * @var string
27
+	 */
28
+	protected $message;
29 29
 
30
-    /**
31
-     * @var array
32
-     */
33
-    protected $required;
30
+	/**
31
+	 * @var array
32
+	 */
33
+	protected $required;
34 34
 
35
-    /**
36
-     * @var array
37
-     */
38
-    protected $values;
35
+	/**
36
+	 * @var array
37
+	 */
38
+	protected $values;
39 39
 
40
-    /**
41
-     * @return void|string
42
-     */
43
-    public function build(array $args = [])
44
-    {
45
-        $this->args = $args;
46
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
47
-            return $this->buildLoginRegister();
48
-        }
49
-        $this->errors = glsr()->sessionGet($args['id'].'errors', []);
50
-        $this->message = glsr()->sessionGet($args['id'].'message', '');
51
-        $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []);
52
-        $this->values = glsr()->sessionGet($args['id'].'values', []);
53
-        $fields = array_reduce($this->getFields(), function ($carry, $field) {
54
-            return $carry.$field;
55
-        });
56
-        return glsr(Template::class)->build('templates/reviews-form', [
57
-            'args' => $args,
58
-            'context' => [
59
-                'class' => $this->getClass(),
60
-                'fields' => $fields,
61
-                'id' => $this->args['id'],
62
-                'response' => $this->buildResponse(),
63
-                'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(),
64
-            ],
65
-        ]);
66
-    }
40
+	/**
41
+	 * @return void|string
42
+	 */
43
+	public function build(array $args = [])
44
+	{
45
+		$this->args = $args;
46
+		if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
47
+			return $this->buildLoginRegister();
48
+		}
49
+		$this->errors = glsr()->sessionGet($args['id'].'errors', []);
50
+		$this->message = glsr()->sessionGet($args['id'].'message', '');
51
+		$this->required = glsr(OptionManager::class)->get('settings.submissions.required', []);
52
+		$this->values = glsr()->sessionGet($args['id'].'values', []);
53
+		$fields = array_reduce($this->getFields(), function ($carry, $field) {
54
+			return $carry.$field;
55
+		});
56
+		return glsr(Template::class)->build('templates/reviews-form', [
57
+			'args' => $args,
58
+			'context' => [
59
+				'class' => $this->getClass(),
60
+				'fields' => $fields,
61
+				'id' => $this->args['id'],
62
+				'response' => $this->buildResponse(),
63
+				'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(),
64
+			],
65
+		]);
66
+	}
67 67
 
68
-    /**
69
-     * @return string
70
-     */
71
-    protected function buildLoginRegister()
72
-    {
73
-        return glsr(Template::class)->build('templates/login-register', [
74
-            'context' => [
75
-                'text' => trim($this->getLoginText().' '.$this->getRegisterText()),
76
-            ],
77
-        ]);
78
-    }
68
+	/**
69
+	 * @return string
70
+	 */
71
+	protected function buildLoginRegister()
72
+	{
73
+		return glsr(Template::class)->build('templates/login-register', [
74
+			'context' => [
75
+				'text' => trim($this->getLoginText().' '.$this->getRegisterText()),
76
+			],
77
+		]);
78
+	}
79 79
 
80
-    /**
81
-     * @return void|string
82
-     */
83
-    protected function buildRecaptcha()
84
-    {
85
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
86
-            return;
87
-        }
88
-        return glsr(Builder::class)->div([
89
-            'class' => 'glsr-recaptcha-holder',
90
-            'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'),
91
-            'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')),
92
-            'data-size' => 'invisible',
93
-        ]);
94
-    }
80
+	/**
81
+	 * @return void|string
82
+	 */
83
+	protected function buildRecaptcha()
84
+	{
85
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
86
+			return;
87
+		}
88
+		return glsr(Builder::class)->div([
89
+			'class' => 'glsr-recaptcha-holder',
90
+			'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'),
91
+			'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')),
92
+			'data-size' => 'invisible',
93
+		]);
94
+	}
95 95
 
96
-    /**
97
-     * @return string
98
-     */
99
-    protected function buildResponse()
100
-    {
101
-        $classes = !empty($this->errors)
102
-            ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class']
103
-            : '';
104
-        return glsr(Template::class)->build('templates/form/response', [
105
-            'context' => [
106
-                'class' => $classes,
107
-                'message' => wpautop($this->message),
108
-            ],
109
-            'has_errors' => !empty($this->errors),
110
-        ]);
111
-    }
96
+	/**
97
+	 * @return string
98
+	 */
99
+	protected function buildResponse()
100
+	{
101
+		$classes = !empty($this->errors)
102
+			? glsr(StyleValidationDefaults::class)->defaults()['message_error_class']
103
+			: '';
104
+		return glsr(Template::class)->build('templates/form/response', [
105
+			'context' => [
106
+				'class' => $classes,
107
+				'message' => wpautop($this->message),
108
+			],
109
+			'has_errors' => !empty($this->errors),
110
+		]);
111
+	}
112 112
 
113
-    /**
114
-     * @return string
115
-     */
116
-    protected function buildSubmitButton()
117
-    {
118
-        return glsr(Template::class)->build('templates/form/submit-button', [
119
-            'context' => [
120
-                'text' => __('Submit your review', 'site-reviews'),
121
-            ],
122
-        ]);
123
-    }
113
+	/**
114
+	 * @return string
115
+	 */
116
+	protected function buildSubmitButton()
117
+	{
118
+		return glsr(Template::class)->build('templates/form/submit-button', [
119
+			'context' => [
120
+				'text' => __('Submit your review', 'site-reviews'),
121
+			],
122
+		]);
123
+	}
124 124
 
125
-    /**
126
-     * @return string
127
-     */
128
-    protected function getClass()
129
-    {
130
-        return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']);
131
-    }
125
+	/**
126
+	 * @return string
127
+	 */
128
+	protected function getClass()
129
+	{
130
+		return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']);
131
+	}
132 132
 
133
-    /**
134
-     * @return array
135
-     */
136
-    protected function getFields()
137
-    {
138
-        $hiddenFields = $this->getHiddenFields();
139
-        $hiddenFields[] = $this->getHoneypotField();
140
-        $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form'));
141
-        $paths = array_map(function ($obj) {
142
-            return $obj->field['path'];
143
-        }, $hiddenFields);
144
-        foreach ($fields as $field) {
145
-            $index = array_search($field->field['path'], $paths);
146
-            if (false === $index) {
147
-                continue;
148
-            }
149
-            unset($hiddenFields[$index]);
150
-        }
151
-        return array_merge($hiddenFields, $fields);
152
-    }
133
+	/**
134
+	 * @return array
135
+	 */
136
+	protected function getFields()
137
+	{
138
+		$hiddenFields = $this->getHiddenFields();
139
+		$hiddenFields[] = $this->getHoneypotField();
140
+		$fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form'));
141
+		$paths = array_map(function ($obj) {
142
+			return $obj->field['path'];
143
+		}, $hiddenFields);
144
+		foreach ($fields as $field) {
145
+			$index = array_search($field->field['path'], $paths);
146
+			if (false === $index) {
147
+				continue;
148
+			}
149
+			unset($hiddenFields[$index]);
150
+		}
151
+		return array_merge($hiddenFields, $fields);
152
+	}
153 153
 
154
-    /**
155
-     * @return string
156
-     */
157
-    protected function getLoginText()
158
-    {
159
-        $loginLink = glsr(Builder::class)->a([
160
-            'href' => wp_login_url(strval(get_permalink())),
161
-            'text' => __('logged in', 'site-reviews'),
162
-        ]);
163
-        return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink);
164
-    }
154
+	/**
155
+	 * @return string
156
+	 */
157
+	protected function getLoginText()
158
+	{
159
+		$loginLink = glsr(Builder::class)->a([
160
+			'href' => wp_login_url(strval(get_permalink())),
161
+			'text' => __('logged in', 'site-reviews'),
162
+		]);
163
+		return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink);
164
+	}
165 165
 
166
-    /**
167
-     * @return void|string
168
-     */
169
-    protected function getRegisterText()
170
-    {
171
-        if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) {
172
-            return;
173
-        }
174
-        $registerLink = glsr(Builder::class)->a([
175
-            'href' => wp_registration_url(),
176
-            'text' => __('register', 'site-reviews'),
177
-        ]);
178
-        return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink);
179
-    }
166
+	/**
167
+	 * @return void|string
168
+	 */
169
+	protected function getRegisterText()
170
+	{
171
+		if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) {
172
+			return;
173
+		}
174
+		$registerLink = glsr(Builder::class)->a([
175
+			'href' => wp_registration_url(),
176
+			'text' => __('register', 'site-reviews'),
177
+		]);
178
+		return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink);
179
+	}
180 180
 
181
-    /**
182
-     * @return array
183
-     */
184
-    protected function getHiddenFields()
185
-    {
186
-        $fields = [[
187
-            'name' => '_action',
188
-            'value' => 'submit-review',
189
-        ], [
190
-            'name' => '_counter',
191
-        ], [
192
-            'name' => '_nonce',
193
-            'value' => wp_create_nonce('submit-review'),
194
-        ], [
195
-            'name' => '_post_id',
196
-            'value' => get_the_ID(),
197
-        ], [
198
-            'name' => '_referer',
199
-            'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')),
200
-        ], [
201
-            'name' => 'assign_to',
202
-            'value' => $this->args['assign_to'],
203
-        ], [
204
-            'name' => 'category',
205
-            'value' => $this->args['category'],
206
-        ], [
207
-            'name' => 'excluded',
208
-            'value' => $this->args['hide'],
209
-        ], [
210
-            'name' => 'form_id',
211
-            'value' => $this->args['id'],
212
-        ]];
213
-        return array_map(function ($field) {
214
-            return new Field(wp_parse_args($field, ['type' => 'hidden']));
215
-        }, $fields);
216
-    }
181
+	/**
182
+	 * @return array
183
+	 */
184
+	protected function getHiddenFields()
185
+	{
186
+		$fields = [[
187
+			'name' => '_action',
188
+			'value' => 'submit-review',
189
+		], [
190
+			'name' => '_counter',
191
+		], [
192
+			'name' => '_nonce',
193
+			'value' => wp_create_nonce('submit-review'),
194
+		], [
195
+			'name' => '_post_id',
196
+			'value' => get_the_ID(),
197
+		], [
198
+			'name' => '_referer',
199
+			'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')),
200
+		], [
201
+			'name' => 'assign_to',
202
+			'value' => $this->args['assign_to'],
203
+		], [
204
+			'name' => 'category',
205
+			'value' => $this->args['category'],
206
+		], [
207
+			'name' => 'excluded',
208
+			'value' => $this->args['hide'],
209
+		], [
210
+			'name' => 'form_id',
211
+			'value' => $this->args['id'],
212
+		]];
213
+		return array_map(function ($field) {
214
+			return new Field(wp_parse_args($field, ['type' => 'hidden']));
215
+		}, $fields);
216
+	}
217 217
 
218
-    /**
219
-     * @return Field
220
-     */
221
-    protected function getHoneypotField()
222
-    {
223
-        return new Field([
224
-            'name' => 'gotcha',
225
-            'type' => 'honeypot',
226
-        ]);
227
-    }
218
+	/**
219
+	 * @return Field
220
+	 */
221
+	protected function getHoneypotField()
222
+	{
223
+		return new Field([
224
+			'name' => 'gotcha',
225
+			'type' => 'honeypot',
226
+		]);
227
+	}
228 228
 
229
-    /**
230
-     * @return void
231
-     */
232
-    protected function normalizeFieldId(Field &$field)
233
-    {
234
-        if (empty($this->args['id']) || empty($field->field['id'])) {
235
-            return;
236
-        }
237
-        $field->field['id'].= '-'.$this->args['id'];
238
-    }
229
+	/**
230
+	 * @return void
231
+	 */
232
+	protected function normalizeFieldId(Field &$field)
233
+	{
234
+		if (empty($this->args['id']) || empty($field->field['id'])) {
235
+			return;
236
+		}
237
+		$field->field['id'].= '-'.$this->args['id'];
238
+	}
239 239
 
240
-    /**
241
-     * @return void
242
-     */
243
-    protected function normalizeFieldClass(Field &$field)
244
-    {
245
-        if (!isset($field->field['class'])) {
246
-            $field->field['class'] = '';
247
-        }
248
-        $field->field['class'] = trim($field->field['class'].' glsr-field-control');
249
-    }
240
+	/**
241
+	 * @return void
242
+	 */
243
+	protected function normalizeFieldClass(Field &$field)
244
+	{
245
+		if (!isset($field->field['class'])) {
246
+			$field->field['class'] = '';
247
+		}
248
+		$field->field['class'] = trim($field->field['class'].' glsr-field-control');
249
+	}
250 250
 
251
-    /**
252
-     * @return void
253
-     */
254
-    protected function normalizeFieldErrors(Field &$field)
255
-    {
256
-        if (!array_key_exists($field->field['path'], $this->errors)) {
257
-            return;
258
-        }
259
-        $field->field['errors'] = $this->errors[$field->field['path']];
260
-    }
251
+	/**
252
+	 * @return void
253
+	 */
254
+	protected function normalizeFieldErrors(Field &$field)
255
+	{
256
+		if (!array_key_exists($field->field['path'], $this->errors)) {
257
+			return;
258
+		}
259
+		$field->field['errors'] = $this->errors[$field->field['path']];
260
+	}
261 261
 
262
-    /**
263
-     * @return void
264
-     */
265
-    protected function normalizeFieldRequired(Field &$field)
266
-    {
267
-        if (!in_array($field->field['path'], $this->required)) {
268
-            return;
269
-        }
270
-        $field->field['required'] = true;
271
-    }
262
+	/**
263
+	 * @return void
264
+	 */
265
+	protected function normalizeFieldRequired(Field &$field)
266
+	{
267
+		if (!in_array($field->field['path'], $this->required)) {
268
+			return;
269
+		}
270
+		$field->field['required'] = true;
271
+	}
272 272
 
273
-    /**
274
-     * @return array
275
-     */
276
-    protected function normalizeFields($fields)
277
-    {
278
-        $normalizedFields = [];
279
-        foreach ($fields as $field) {
280
-            if (in_array($field->field['path'], $this->args['hide'])) {
281
-                continue;
282
-            }
283
-            $field->field['is_public'] = true;
284
-            $this->normalizeFieldClass($field);
285
-            $this->normalizeFieldErrors($field);
286
-            $this->normalizeFieldRequired($field);
287
-            $this->normalizeFieldValue($field);
288
-            $this->normalizeFieldId($field);
289
-            $normalizedFields[] = $field;
290
-        }
291
-        return $normalizedFields;
292
-    }
273
+	/**
274
+	 * @return array
275
+	 */
276
+	protected function normalizeFields($fields)
277
+	{
278
+		$normalizedFields = [];
279
+		foreach ($fields as $field) {
280
+			if (in_array($field->field['path'], $this->args['hide'])) {
281
+				continue;
282
+			}
283
+			$field->field['is_public'] = true;
284
+			$this->normalizeFieldClass($field);
285
+			$this->normalizeFieldErrors($field);
286
+			$this->normalizeFieldRequired($field);
287
+			$this->normalizeFieldValue($field);
288
+			$this->normalizeFieldId($field);
289
+			$normalizedFields[] = $field;
290
+		}
291
+		return $normalizedFields;
292
+	}
293 293
 
294
-    /**
295
-     * @return void
296
-     */
297
-    protected function normalizeFieldValue(Field &$field)
298
-    {
299
-        if (!array_key_exists($field->field['path'], $this->values)) {
300
-            return;
301
-        }
302
-        if (in_array($field->field['type'], ['radio', 'checkbox'])) {
303
-            $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
304
-        } else {
305
-            $field->field['value'] = $this->values[$field->field['path']];
306
-        }
307
-    }
294
+	/**
295
+	 * @return void
296
+	 */
297
+	protected function normalizeFieldValue(Field &$field)
298
+	{
299
+		if (!array_key_exists($field->field['path'], $this->values)) {
300
+			return;
301
+		}
302
+		if (in_array($field->field['type'], ['radio', 'checkbox'])) {
303
+			$field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
304
+		} else {
305
+			$field->field['value'] = $this->values[$field->field['path']];
306
+		}
307
+	}
308 308
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -40,20 +40,20 @@  discard block
 block discarded – undo
40 40
     /**
41 41
      * @return void|string
42 42
      */
43
-    public function build(array $args = [])
43
+    public function build( array $args = [] )
44 44
     {
45 45
         $this->args = $args;
46
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
46
+        if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) {
47 47
             return $this->buildLoginRegister();
48 48
         }
49
-        $this->errors = glsr()->sessionGet($args['id'].'errors', []);
50
-        $this->message = glsr()->sessionGet($args['id'].'message', '');
51
-        $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []);
52
-        $this->values = glsr()->sessionGet($args['id'].'values', []);
53
-        $fields = array_reduce($this->getFields(), function ($carry, $field) {
49
+        $this->errors = glsr()->sessionGet( $args['id'].'errors', [] );
50
+        $this->message = glsr()->sessionGet( $args['id'].'message', '' );
51
+        $this->required = glsr( OptionManager::class )->get( 'settings.submissions.required', [] );
52
+        $this->values = glsr()->sessionGet( $args['id'].'values', [] );
53
+        $fields = array_reduce( $this->getFields(), function( $carry, $field ) {
54 54
             return $carry.$field;
55 55
         });
56
-        return glsr(Template::class)->build('templates/reviews-form', [
56
+        return glsr( Template::class )->build( 'templates/reviews-form', [
57 57
             'args' => $args,
58 58
             'context' => [
59 59
                 'class' => $this->getClass(),
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
                 'response' => $this->buildResponse(),
63 63
                 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(),
64 64
             ],
65
-        ]);
65
+        ] );
66 66
     }
67 67
 
68 68
     /**
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
      */
71 71
     protected function buildLoginRegister()
72 72
     {
73
-        return glsr(Template::class)->build('templates/login-register', [
73
+        return glsr( Template::class )->build( 'templates/login-register', [
74 74
             'context' => [
75
-                'text' => trim($this->getLoginText().' '.$this->getRegisterText()),
75
+                'text' => trim( $this->getLoginText().' '.$this->getRegisterText() ),
76 76
             ],
77
-        ]);
77
+        ] );
78 78
     }
79 79
 
80 80
     /**
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
      */
83 83
     protected function buildRecaptcha()
84 84
     {
85
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
85
+        if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) {
86 86
             return;
87 87
         }
88
-        return glsr(Builder::class)->div([
88
+        return glsr( Builder::class )->div( [
89 89
             'class' => 'glsr-recaptcha-holder',
90
-            'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'),
91
-            'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')),
90
+            'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ),
91
+            'data-sitekey' => sanitize_text_field( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.key' ) ),
92 92
             'data-size' => 'invisible',
93
-        ]);
93
+        ] );
94 94
     }
95 95
 
96 96
     /**
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
     protected function buildResponse()
100 100
     {
101 101
         $classes = !empty($this->errors)
102
-            ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class']
102
+            ? glsr( StyleValidationDefaults::class )->defaults()['message_error_class']
103 103
             : '';
104
-        return glsr(Template::class)->build('templates/form/response', [
104
+        return glsr( Template::class )->build( 'templates/form/response', [
105 105
             'context' => [
106 106
                 'class' => $classes,
107
-                'message' => wpautop($this->message),
107
+                'message' => wpautop( $this->message ),
108 108
             ],
109 109
             'has_errors' => !empty($this->errors),
110
-        ]);
110
+        ] );
111 111
     }
112 112
 
113 113
     /**
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
      */
116 116
     protected function buildSubmitButton()
117 117
     {
118
-        return glsr(Template::class)->build('templates/form/submit-button', [
118
+        return glsr( Template::class )->build( 'templates/form/submit-button', [
119 119
             'context' => [
120
-                'text' => __('Submit your review', 'site-reviews'),
120
+                'text' => __( 'Submit your review', 'site-reviews' ),
121 121
             ],
122
-        ]);
122
+        ] );
123 123
     }
124 124
 
125 125
     /**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     protected function getClass()
129 129
     {
130
-        return trim('glsr-form glsr-'.glsr(Style::class)->get().' '.$this->args['class']);
130
+        return trim( 'glsr-form glsr-'.glsr( Style::class )->get().' '.$this->args['class'] );
131 131
     }
132 132
 
133 133
     /**
@@ -137,18 +137,18 @@  discard block
 block discarded – undo
137 137
     {
138 138
         $hiddenFields = $this->getHiddenFields();
139 139
         $hiddenFields[] = $this->getHoneypotField();
140
-        $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form'));
141
-        $paths = array_map(function ($obj) {
140
+        $fields = $this->normalizeFields( glsr( Form::class )->getFields( 'submission-form' ) );
141
+        $paths = array_map( function( $obj ) {
142 142
             return $obj->field['path'];
143
-        }, $hiddenFields);
144
-        foreach ($fields as $field) {
145
-            $index = array_search($field->field['path'], $paths);
146
-            if (false === $index) {
143
+        }, $hiddenFields );
144
+        foreach( $fields as $field ) {
145
+            $index = array_search( $field->field['path'], $paths );
146
+            if( false === $index ) {
147 147
                 continue;
148 148
             }
149 149
             unset($hiddenFields[$index]);
150 150
         }
151
-        return array_merge($hiddenFields, $fields);
151
+        return array_merge( $hiddenFields, $fields );
152 152
     }
153 153
 
154 154
     /**
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
      */
157 157
     protected function getLoginText()
158 158
     {
159
-        $loginLink = glsr(Builder::class)->a([
160
-            'href' => wp_login_url(strval(get_permalink())),
161
-            'text' => __('logged in', 'site-reviews'),
162
-        ]);
163
-        return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink);
159
+        $loginLink = glsr( Builder::class )->a( [
160
+            'href' => wp_login_url( strval( get_permalink() ) ),
161
+            'text' => __( 'logged in', 'site-reviews' ),
162
+        ] );
163
+        return sprintf( __( 'You must be %s to submit a review.', 'site-reviews' ), $loginLink );
164 164
     }
165 165
 
166 166
     /**
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
      */
169 169
     protected function getRegisterText()
170 170
     {
171
-        if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) {
171
+        if( !get_option( 'users_can_register' ) || !glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) {
172 172
             return;
173 173
         }
174
-        $registerLink = glsr(Builder::class)->a([
174
+        $registerLink = glsr( Builder::class )->a( [
175 175
             'href' => wp_registration_url(),
176
-            'text' => __('register', 'site-reviews'),
177
-        ]);
178
-        return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink);
176
+            'text' => __( 'register', 'site-reviews' ),
177
+        ] );
178
+        return sprintf( __( 'You may also %s for an account.', 'site-reviews' ), $registerLink );
179 179
     }
180 180
 
181 181
     /**
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
             'name' => '_counter',
191 191
         ], [
192 192
             'name' => '_nonce',
193
-            'value' => wp_create_nonce('submit-review'),
193
+            'value' => wp_create_nonce( 'submit-review' ),
194 194
         ], [
195 195
             'name' => '_post_id',
196 196
             'value' => get_the_ID(),
197 197
         ], [
198 198
             'name' => '_referer',
199
-            'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')),
199
+            'value' => wp_unslash( filter_input( INPUT_SERVER, 'REQUEST_URI' ) ),
200 200
         ], [
201 201
             'name' => 'assign_to',
202 202
             'value' => $this->args['assign_to'],
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
             'name' => 'form_id',
211 211
             'value' => $this->args['id'],
212 212
         ]];
213
-        return array_map(function ($field) {
214
-            return new Field(wp_parse_args($field, ['type' => 'hidden']));
215
-        }, $fields);
213
+        return array_map( function( $field ) {
214
+            return new Field( wp_parse_args( $field, ['type' => 'hidden'] ) );
215
+        }, $fields );
216 216
     }
217 217
 
218 218
     /**
@@ -220,40 +220,40 @@  discard block
 block discarded – undo
220 220
      */
221 221
     protected function getHoneypotField()
222 222
     {
223
-        return new Field([
223
+        return new Field( [
224 224
             'name' => 'gotcha',
225 225
             'type' => 'honeypot',
226
-        ]);
226
+        ] );
227 227
     }
228 228
 
229 229
     /**
230 230
      * @return void
231 231
      */
232
-    protected function normalizeFieldId(Field &$field)
232
+    protected function normalizeFieldId( Field &$field )
233 233
     {
234
-        if (empty($this->args['id']) || empty($field->field['id'])) {
234
+        if( empty($this->args['id']) || empty($field->field['id']) ) {
235 235
             return;
236 236
         }
237
-        $field->field['id'].= '-'.$this->args['id'];
237
+        $field->field['id'] .= '-'.$this->args['id'];
238 238
     }
239 239
 
240 240
     /**
241 241
      * @return void
242 242
      */
243
-    protected function normalizeFieldClass(Field &$field)
243
+    protected function normalizeFieldClass( Field &$field )
244 244
     {
245
-        if (!isset($field->field['class'])) {
245
+        if( !isset($field->field['class']) ) {
246 246
             $field->field['class'] = '';
247 247
         }
248
-        $field->field['class'] = trim($field->field['class'].' glsr-field-control');
248
+        $field->field['class'] = trim( $field->field['class'].' glsr-field-control' );
249 249
     }
250 250
 
251 251
     /**
252 252
      * @return void
253 253
      */
254
-    protected function normalizeFieldErrors(Field &$field)
254
+    protected function normalizeFieldErrors( Field &$field )
255 255
     {
256
-        if (!array_key_exists($field->field['path'], $this->errors)) {
256
+        if( !array_key_exists( $field->field['path'], $this->errors ) ) {
257 257
             return;
258 258
         }
259 259
         $field->field['errors'] = $this->errors[$field->field['path']];
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
     /**
263 263
      * @return void
264 264
      */
265
-    protected function normalizeFieldRequired(Field &$field)
265
+    protected function normalizeFieldRequired( Field &$field )
266 266
     {
267
-        if (!in_array($field->field['path'], $this->required)) {
267
+        if( !in_array( $field->field['path'], $this->required ) ) {
268 268
             return;
269 269
         }
270 270
         $field->field['required'] = true;
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
     /**
274 274
      * @return array
275 275
      */
276
-    protected function normalizeFields($fields)
276
+    protected function normalizeFields( $fields )
277 277
     {
278 278
         $normalizedFields = [];
279
-        foreach ($fields as $field) {
280
-            if (in_array($field->field['path'], $this->args['hide'])) {
279
+        foreach( $fields as $field ) {
280
+            if( in_array( $field->field['path'], $this->args['hide'] ) ) {
281 281
                 continue;
282 282
             }
283 283
             $field->field['is_public'] = true;
284
-            $this->normalizeFieldClass($field);
285
-            $this->normalizeFieldErrors($field);
286
-            $this->normalizeFieldRequired($field);
287
-            $this->normalizeFieldValue($field);
288
-            $this->normalizeFieldId($field);
284
+            $this->normalizeFieldClass( $field );
285
+            $this->normalizeFieldErrors( $field );
286
+            $this->normalizeFieldRequired( $field );
287
+            $this->normalizeFieldValue( $field );
288
+            $this->normalizeFieldId( $field );
289 289
             $normalizedFields[] = $field;
290 290
         }
291 291
         return $normalizedFields;
@@ -294,12 +294,12 @@  discard block
 block discarded – undo
294 294
     /**
295 295
      * @return void
296 296
      */
297
-    protected function normalizeFieldValue(Field &$field)
297
+    protected function normalizeFieldValue( Field &$field )
298 298
     {
299
-        if (!array_key_exists($field->field['path'], $this->values)) {
299
+        if( !array_key_exists( $field->field['path'], $this->values ) ) {
300 300
             return;
301 301
         }
302
-        if (in_array($field->field['type'], ['radio', 'checkbox'])) {
302
+        if( in_array( $field->field['type'], ['radio', 'checkbox'] ) ) {
303 303
             $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']];
304 304
         } else {
305 305
             $field->field['value'] = $this->values[$field->field['path']];
Please login to merge, or discard this patch.
plugin/Modules/Console.php 3 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -415,7 +415,8 @@
 block discarded – undo
415 415
     {
416 416
         if ($value instanceof DateTime) {
417 417
             $value = $value->format('Y-m-d H:i:s');
418
-        } elseif ($this->isObjectOrArray($value)) {
418
+        }
419
+        elseif ($this->isObjectOrArray($value)) {
419 420
             $value = json_encode($value);
420 421
         }
421 422
         return (string) $value;
Please login to merge, or discard this patch.
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -10,437 +10,437 @@
 block discarded – undo
10 10
 
11 11
 class Console
12 12
 {
13
-    const DEBUG = 0;      // Detailed debug information
14
-    const INFO = 1;       // Interesting events
15
-    const NOTICE = 2;     // Normal but significant events
16
-    const WARNING = 4;    // Exceptional occurrences that are not errors
17
-    const ERROR = 8;      // Runtime errors that do not require immediate action
18
-    const CRITICAL = 16;  // Critical conditions
19
-    const ALERT = 32;     // Action must be taken immediately
20
-    const EMERGENCY = 64; // System is unusable
21
-
22
-    protected $file;
23
-    protected $log;
24
-    protected $logOnceKey = 'glsr_log_once';
25
-
26
-    public function __construct()
27
-    {
28
-        $this->file = glsr()->path('console.log');
29
-        $this->log = file_exists($this->file)
30
-            ? file_get_contents($this->file)
31
-            : '';
32
-        $this->reset();
33
-    }
34
-
35
-    /**
36
-     * @return string
37
-     */
38
-    public function __toString()
39
-    {
40
-        return $this->get();
41
-    }
42
-
43
-    /**
44
-     * Action must be taken immediately
45
-     * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
46
-     * @param mixed $message
47
-     * @param array $context
48
-     * @return static
49
-     */
50
-    public function alert($message, array $context = [])
51
-    {
52
-        return $this->log(static::ALERT, $message, $context);
53
-    }
54
-
55
-    /**
56
-     * @return void
57
-     */
58
-    public function clear()
59
-    {
60
-        $this->log = '';
61
-        file_put_contents($this->file, $this->log);
62
-    }
63
-
64
-    /**
65
-     * Critical conditions
66
-     * Example: Application component unavailable, unexpected exception.
67
-     * @param mixed $message
68
-     * @param array $context
69
-     * @return static
70
-     */
71
-    public function critical($message, array $context = [])
72
-    {
73
-        return $this->log(static::CRITICAL, $message, $context);
74
-    }
75
-
76
-    /**
77
-     * Detailed debug information.
78
-     * @param mixed $message
79
-     * @param array $context
80
-     * @return static
81
-     */
82
-    public function debug($message, array $context = [])
83
-    {
84
-        return $this->log(static::DEBUG, $message, $context);
85
-    }
86
-
87
-    /**
88
-     * System is unusable.
89
-     * @param mixed $message
90
-     * @param array $context
91
-     * @return static
92
-     */
93
-    public function emergency($message, array $context = [])
94
-    {
95
-        return $this->log(static::EMERGENCY, $message, $context);
96
-    }
97
-
98
-    /**
99
-     * Runtime errors that do not require immediate action but should typically be logged and monitored.
100
-     * @param mixed $message
101
-     * @param array $context
102
-     * @return static
103
-     */
104
-    public function error($message, array $context = [])
105
-    {
106
-        return $this->log(static::ERROR, $message, $context);
107
-    }
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function get()
113
-    {
114
-        return empty($this->log)
115
-            ? __('Console is empty', 'site-reviews')
116
-            : $this->log;
117
-    }
118
-
119
-    /**
120
-     * @return int
121
-     */
122
-    public function getLevel()
123
-    {
124
-        return intval(apply_filters('site-reviews/console/level', static::INFO));
125
-    }
126
-
127
-    /**
128
-     * @return array
129
-     */
130
-    public function getLevels()
131
-    {
132
-        $constants = (new ReflectionClass(__CLASS__))->getConstants();
133
-        return array_map('strtolower', array_flip($constants));
134
-    }
135
-
136
-    /**
137
-     * @return string
138
-     */
139
-    public function humanLevel()
140
-    {
141
-        $level = $this->getLevel();
142
-        return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
143
-    }
144
-
145
-    /**
146
-     * @param string|null $valueIfEmpty
147
-     * @return string
148
-     */
149
-    public function humanSize($valueIfEmpty = null)
150
-    {
151
-        $bytes = $this->size();
152
-        if (empty($bytes) && is_string($valueIfEmpty)) {
153
-            return $valueIfEmpty;
154
-        }
155
-        $exponent = floor(log(max($bytes, 1), 1024));
156
-        return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157
-    }
158
-
159
-    /**
160
-     * Interesting events
161
-     * Example: User logs in, SQL logs.
162
-     * @param mixed $message
163
-     * @param array $context
164
-     * @return static
165
-     */
166
-    public function info($message, array $context = [])
167
-    {
168
-        return $this->log(static::INFO, $message, $context);
169
-    }
170
-
171
-    /**
172
-     * @param int $level
173
-     * @param mixed $message
174
-     * @param array $context
175
-     * @param string $backtraceLine
176
-     * @return static
177
-     */
178
-    public function log($level, $message, $context = [], $backtraceLine = '')
179
-    {
180
-        if (empty($backtraceLine)) {
181
-            $backtraceLine = $this->getBacktraceLine();
182
-        }
183
-        if ($this->canLogEntry($level, $backtraceLine)) {
184
-            $levelName = Arr::get($this->getLevels(), $level);
185
-            $context = Arr::consolidateArray($context);
186
-            $backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
-            $message = $this->interpolate($message, $context);
188
-            $entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
-            file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
-            apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
191
-            $this->reset();
192
-        }
193
-        return $this;
194
-    }
195
-
196
-    /**
197
-     * @return void
198
-     */
199
-    public function logOnce()
200
-    {
201
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
202
-        $levels = $this->getLevels();
203
-        foreach ($once as $entry) {
204
-            $levelName = Arr::get($entry, 'level');
205
-            if (!in_array($levelName, $levels)) {
206
-                continue;
207
-            }
208
-            $level = Arr::get(array_flip($levels), $levelName);
209
-            $message = Arr::get($entry, 'message');
210
-            $backtraceLine = Arr::get($entry, 'backtrace');
211
-            $this->log($level, $message, [], $backtraceLine);
212
-        }
213
-        glsr()->{$this->logOnceKey} = [];
214
-    }
215
-
216
-    /**
217
-     * Normal but significant events.
218
-     * @param mixed $message
219
-     * @param array $context
220
-     * @return static
221
-     */
222
-    public function notice($message, array $context = [])
223
-    {
224
-        return $this->log(static::NOTICE, $message, $context);
225
-    }
226
-
227
-    /**
228
-     * @param string $levelName
229
-     * @param string $handle
230
-     * @param mixed $data
231
-     * @return void
232
-     */
233
-    public function once($levelName, $handle, $data)
234
-    {
235
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
-        $filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
-            return Arr::get($entry, 'level') == $levelName
238
-                && Arr::get($entry, 'handle') == $handle;
239
-        });
240
-        if (!empty($filtered)) {
241
-            return;
242
-        }
243
-        $once[] = [
244
-            'backtrace' => $this->getBacktraceLineFromData($data),
245
-            'handle' => $handle,
246
-            'level' => $levelName,
247
-            'message' => '[RECURRING] '.$this->getMessageFromData($data),
248
-        ];
249
-        glsr()->{$this->logOnceKey} = $once;
250
-    }
251
-
252
-    /**
253
-     * @return int
254
-     */
255
-    public function size()
256
-    {
257
-        return file_exists($this->file)
258
-            ? filesize($this->file)
259
-            : 0;
260
-    }
261
-
262
-    /**
263
-     * Exceptional occurrences that are not errors
264
-     * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
265
-     * @param mixed $message
266
-     * @param array $context
267
-     * @return static
268
-     */
269
-    public function warning($message, array $context = [])
270
-    {
271
-        return $this->log(static::WARNING, $message, $context);
272
-    }
273
-
274
-    /**
275
-     * @param array $backtrace
276
-     * @param int $index
277
-     * @return string
278
-     */
279
-    protected function buildBacktraceLine($backtrace, $index)
280
-    {
281
-        return sprintf('%s:%s',
282
-            Arr::get($backtrace, $index.'.file'), // realpath
283
-            Arr::get($backtrace, $index.'.line')
284
-        );
285
-    }
286
-
287
-    /**
288
-     * @param string $levelName
289
-     * @param mixed $message
290
-     * @param string $backtraceLine
291
-     * @return string
292
-     */
293
-    protected function buildLogEntry($levelName, $message, $backtraceLine = '')
294
-    {
295
-        return sprintf('[%s] %s [%s] %s',
296
-            current_time('mysql'),
297
-            strtoupper($levelName),
298
-            $backtraceLine,
299
-            $message
300
-        );
301
-    }
302
-
303
-    /**
304
-     * @param int $level
305
-     * @return bool
306
-     */
307
-    protected function canLogEntry($level, $backtraceLine)
308
-    {
309
-        $levelExists = array_key_exists($level, $this->getLevels());
310
-        if (!Str::contains($backtraceLine, glsr()->path())) {
311
-            return $levelExists; // ignore level restriction if triggered outside of the plugin
312
-        }
313
-        return $levelExists && $level >= $this->getLevel();
314
-    }
315
-
316
-    /**
317
-     * @return void|string
318
-     */
319
-    protected function getBacktraceLine()
320
-    {
321
-        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
-        $search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
-        if (false !== $search) {
324
-            return $this->buildBacktraceLine($backtrace, (int) $search);
325
-        }
326
-        $search = array_search('log', glsr_array_column($backtrace, 'function'));
327
-        if (false !== $search) {
328
-            $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
329
-                ? $search + 4
330
-                : $search + 1;
331
-            return $this->buildBacktraceLine($backtrace, $index);
332
-        }
333
-        return 'Unknown';
334
-    }
335
-
336
-    /**
337
-     * @param mixed $data
338
-     * @return string
339
-     */
340
-    protected function getBacktraceLineFromData($data)
341
-    {
342
-        $backtrace = $data instanceof Throwable
343
-            ? $data->getTrace()
344
-            : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
-        return $this->buildBacktraceLine($backtrace, 0);
346
-    }
347
-
348
-    /**
349
-     * @param mixed $data
350
-     * @return string
351
-     */
352
-    protected function getMessageFromData($data)
353
-    {
354
-        return $data instanceof Throwable
355
-            ? $this->normalizeThrowableMessage($data->getMessage())
356
-            : print_r($data, 1);
357
-    }
358
-
359
-    /**
360
-     * Interpolates context values into the message placeholders.
361
-     * @param mixed $message
362
-     * @param array $context
363
-     * @return string
364
-     */
365
-    protected function interpolate($message, $context = [])
366
-    {
367
-        if ($this->isObjectOrArray($message) || !is_array($context)) {
368
-            return print_r($message, true);
369
-        }
370
-        $replace = [];
371
-        foreach ($context as $key => $value) {
372
-            $replace['{'.$key.'}'] = $this->normalizeValue($value);
373
-        }
374
-        return strtr($message, $replace);
375
-    }
376
-
377
-    /**
378
-     * @param mixed $value
379
-     * @return bool
380
-     */
381
-    protected function isObjectOrArray($value)
382
-    {
383
-        return is_object($value) || is_array($value);
384
-    }
385
-
386
-    /**
387
-     * @param string $backtraceLine
388
-     * @return string
389
-     */
390
-    protected function normalizeBacktraceLine($backtraceLine)
391
-    {
392
-        $search = [
393
-            glsr()->path('plugin/'),
394
-            glsr()->path('plugin/', false),
395
-            trailingslashit(glsr()->path()),
396
-            trailingslashit(glsr()->path('', false)),
397
-            WP_CONTENT_DIR,
398
-            ABSPATH,
399
-        ];
400
-        return str_replace(array_unique($search), '', $backtraceLine);
401
-    }
402
-
403
-    /**
404
-     * @param string $message
405
-     * @return string
406
-     */
407
-    protected function normalizeThrowableMessage($message)
408
-    {
409
-        $calledIn = strpos($message, ', called in');
410
-        return false !== $calledIn
411
-            ? substr($message, 0, $calledIn)
412
-            : $message;
413
-    }
414
-
415
-    /**
416
-     * @param mixed $value
417
-     * @return string
418
-     */
419
-    protected function normalizeValue($value)
420
-    {
421
-        if ($value instanceof DateTime) {
422
-            $value = $value->format('Y-m-d H:i:s');
423
-        } elseif ($this->isObjectOrArray($value)) {
424
-            $value = json_encode($value);
425
-        }
426
-        return (string) $value;
427
-    }
428
-
429
-    /**
430
-     * @return void
431
-     */
432
-    protected function reset()
433
-    {
434
-        if ($this->size() <= pow(1024, 2) / 8) {
435
-            return;
436
-        }
437
-        $this->clear();
438
-        file_put_contents(
439
-            $this->file,
440
-            $this->buildLogEntry(
441
-                static::NOTICE,
442
-                __('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
443
-            )
444
-        );
445
-    }
13
+	const DEBUG = 0;      // Detailed debug information
14
+	const INFO = 1;       // Interesting events
15
+	const NOTICE = 2;     // Normal but significant events
16
+	const WARNING = 4;    // Exceptional occurrences that are not errors
17
+	const ERROR = 8;      // Runtime errors that do not require immediate action
18
+	const CRITICAL = 16;  // Critical conditions
19
+	const ALERT = 32;     // Action must be taken immediately
20
+	const EMERGENCY = 64; // System is unusable
21
+
22
+	protected $file;
23
+	protected $log;
24
+	protected $logOnceKey = 'glsr_log_once';
25
+
26
+	public function __construct()
27
+	{
28
+		$this->file = glsr()->path('console.log');
29
+		$this->log = file_exists($this->file)
30
+			? file_get_contents($this->file)
31
+			: '';
32
+		$this->reset();
33
+	}
34
+
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function __toString()
39
+	{
40
+		return $this->get();
41
+	}
42
+
43
+	/**
44
+	 * Action must be taken immediately
45
+	 * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
46
+	 * @param mixed $message
47
+	 * @param array $context
48
+	 * @return static
49
+	 */
50
+	public function alert($message, array $context = [])
51
+	{
52
+		return $this->log(static::ALERT, $message, $context);
53
+	}
54
+
55
+	/**
56
+	 * @return void
57
+	 */
58
+	public function clear()
59
+	{
60
+		$this->log = '';
61
+		file_put_contents($this->file, $this->log);
62
+	}
63
+
64
+	/**
65
+	 * Critical conditions
66
+	 * Example: Application component unavailable, unexpected exception.
67
+	 * @param mixed $message
68
+	 * @param array $context
69
+	 * @return static
70
+	 */
71
+	public function critical($message, array $context = [])
72
+	{
73
+		return $this->log(static::CRITICAL, $message, $context);
74
+	}
75
+
76
+	/**
77
+	 * Detailed debug information.
78
+	 * @param mixed $message
79
+	 * @param array $context
80
+	 * @return static
81
+	 */
82
+	public function debug($message, array $context = [])
83
+	{
84
+		return $this->log(static::DEBUG, $message, $context);
85
+	}
86
+
87
+	/**
88
+	 * System is unusable.
89
+	 * @param mixed $message
90
+	 * @param array $context
91
+	 * @return static
92
+	 */
93
+	public function emergency($message, array $context = [])
94
+	{
95
+		return $this->log(static::EMERGENCY, $message, $context);
96
+	}
97
+
98
+	/**
99
+	 * Runtime errors that do not require immediate action but should typically be logged and monitored.
100
+	 * @param mixed $message
101
+	 * @param array $context
102
+	 * @return static
103
+	 */
104
+	public function error($message, array $context = [])
105
+	{
106
+		return $this->log(static::ERROR, $message, $context);
107
+	}
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function get()
113
+	{
114
+		return empty($this->log)
115
+			? __('Console is empty', 'site-reviews')
116
+			: $this->log;
117
+	}
118
+
119
+	/**
120
+	 * @return int
121
+	 */
122
+	public function getLevel()
123
+	{
124
+		return intval(apply_filters('site-reviews/console/level', static::INFO));
125
+	}
126
+
127
+	/**
128
+	 * @return array
129
+	 */
130
+	public function getLevels()
131
+	{
132
+		$constants = (new ReflectionClass(__CLASS__))->getConstants();
133
+		return array_map('strtolower', array_flip($constants));
134
+	}
135
+
136
+	/**
137
+	 * @return string
138
+	 */
139
+	public function humanLevel()
140
+	{
141
+		$level = $this->getLevel();
142
+		return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
143
+	}
144
+
145
+	/**
146
+	 * @param string|null $valueIfEmpty
147
+	 * @return string
148
+	 */
149
+	public function humanSize($valueIfEmpty = null)
150
+	{
151
+		$bytes = $this->size();
152
+		if (empty($bytes) && is_string($valueIfEmpty)) {
153
+			return $valueIfEmpty;
154
+		}
155
+		$exponent = floor(log(max($bytes, 1), 1024));
156
+		return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157
+	}
158
+
159
+	/**
160
+	 * Interesting events
161
+	 * Example: User logs in, SQL logs.
162
+	 * @param mixed $message
163
+	 * @param array $context
164
+	 * @return static
165
+	 */
166
+	public function info($message, array $context = [])
167
+	{
168
+		return $this->log(static::INFO, $message, $context);
169
+	}
170
+
171
+	/**
172
+	 * @param int $level
173
+	 * @param mixed $message
174
+	 * @param array $context
175
+	 * @param string $backtraceLine
176
+	 * @return static
177
+	 */
178
+	public function log($level, $message, $context = [], $backtraceLine = '')
179
+	{
180
+		if (empty($backtraceLine)) {
181
+			$backtraceLine = $this->getBacktraceLine();
182
+		}
183
+		if ($this->canLogEntry($level, $backtraceLine)) {
184
+			$levelName = Arr::get($this->getLevels(), $level);
185
+			$context = Arr::consolidateArray($context);
186
+			$backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
+			$message = $this->interpolate($message, $context);
188
+			$entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
+			file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
+			apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
191
+			$this->reset();
192
+		}
193
+		return $this;
194
+	}
195
+
196
+	/**
197
+	 * @return void
198
+	 */
199
+	public function logOnce()
200
+	{
201
+		$once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
202
+		$levels = $this->getLevels();
203
+		foreach ($once as $entry) {
204
+			$levelName = Arr::get($entry, 'level');
205
+			if (!in_array($levelName, $levels)) {
206
+				continue;
207
+			}
208
+			$level = Arr::get(array_flip($levels), $levelName);
209
+			$message = Arr::get($entry, 'message');
210
+			$backtraceLine = Arr::get($entry, 'backtrace');
211
+			$this->log($level, $message, [], $backtraceLine);
212
+		}
213
+		glsr()->{$this->logOnceKey} = [];
214
+	}
215
+
216
+	/**
217
+	 * Normal but significant events.
218
+	 * @param mixed $message
219
+	 * @param array $context
220
+	 * @return static
221
+	 */
222
+	public function notice($message, array $context = [])
223
+	{
224
+		return $this->log(static::NOTICE, $message, $context);
225
+	}
226
+
227
+	/**
228
+	 * @param string $levelName
229
+	 * @param string $handle
230
+	 * @param mixed $data
231
+	 * @return void
232
+	 */
233
+	public function once($levelName, $handle, $data)
234
+	{
235
+		$once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
+		$filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
+			return Arr::get($entry, 'level') == $levelName
238
+				&& Arr::get($entry, 'handle') == $handle;
239
+		});
240
+		if (!empty($filtered)) {
241
+			return;
242
+		}
243
+		$once[] = [
244
+			'backtrace' => $this->getBacktraceLineFromData($data),
245
+			'handle' => $handle,
246
+			'level' => $levelName,
247
+			'message' => '[RECURRING] '.$this->getMessageFromData($data),
248
+		];
249
+		glsr()->{$this->logOnceKey} = $once;
250
+	}
251
+
252
+	/**
253
+	 * @return int
254
+	 */
255
+	public function size()
256
+	{
257
+		return file_exists($this->file)
258
+			? filesize($this->file)
259
+			: 0;
260
+	}
261
+
262
+	/**
263
+	 * Exceptional occurrences that are not errors
264
+	 * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
265
+	 * @param mixed $message
266
+	 * @param array $context
267
+	 * @return static
268
+	 */
269
+	public function warning($message, array $context = [])
270
+	{
271
+		return $this->log(static::WARNING, $message, $context);
272
+	}
273
+
274
+	/**
275
+	 * @param array $backtrace
276
+	 * @param int $index
277
+	 * @return string
278
+	 */
279
+	protected function buildBacktraceLine($backtrace, $index)
280
+	{
281
+		return sprintf('%s:%s',
282
+			Arr::get($backtrace, $index.'.file'), // realpath
283
+			Arr::get($backtrace, $index.'.line')
284
+		);
285
+	}
286
+
287
+	/**
288
+	 * @param string $levelName
289
+	 * @param mixed $message
290
+	 * @param string $backtraceLine
291
+	 * @return string
292
+	 */
293
+	protected function buildLogEntry($levelName, $message, $backtraceLine = '')
294
+	{
295
+		return sprintf('[%s] %s [%s] %s',
296
+			current_time('mysql'),
297
+			strtoupper($levelName),
298
+			$backtraceLine,
299
+			$message
300
+		);
301
+	}
302
+
303
+	/**
304
+	 * @param int $level
305
+	 * @return bool
306
+	 */
307
+	protected function canLogEntry($level, $backtraceLine)
308
+	{
309
+		$levelExists = array_key_exists($level, $this->getLevels());
310
+		if (!Str::contains($backtraceLine, glsr()->path())) {
311
+			return $levelExists; // ignore level restriction if triggered outside of the plugin
312
+		}
313
+		return $levelExists && $level >= $this->getLevel();
314
+	}
315
+
316
+	/**
317
+	 * @return void|string
318
+	 */
319
+	protected function getBacktraceLine()
320
+	{
321
+		$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
+		$search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
+		if (false !== $search) {
324
+			return $this->buildBacktraceLine($backtrace, (int) $search);
325
+		}
326
+		$search = array_search('log', glsr_array_column($backtrace, 'function'));
327
+		if (false !== $search) {
328
+			$index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
329
+				? $search + 4
330
+				: $search + 1;
331
+			return $this->buildBacktraceLine($backtrace, $index);
332
+		}
333
+		return 'Unknown';
334
+	}
335
+
336
+	/**
337
+	 * @param mixed $data
338
+	 * @return string
339
+	 */
340
+	protected function getBacktraceLineFromData($data)
341
+	{
342
+		$backtrace = $data instanceof Throwable
343
+			? $data->getTrace()
344
+			: debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
+		return $this->buildBacktraceLine($backtrace, 0);
346
+	}
347
+
348
+	/**
349
+	 * @param mixed $data
350
+	 * @return string
351
+	 */
352
+	protected function getMessageFromData($data)
353
+	{
354
+		return $data instanceof Throwable
355
+			? $this->normalizeThrowableMessage($data->getMessage())
356
+			: print_r($data, 1);
357
+	}
358
+
359
+	/**
360
+	 * Interpolates context values into the message placeholders.
361
+	 * @param mixed $message
362
+	 * @param array $context
363
+	 * @return string
364
+	 */
365
+	protected function interpolate($message, $context = [])
366
+	{
367
+		if ($this->isObjectOrArray($message) || !is_array($context)) {
368
+			return print_r($message, true);
369
+		}
370
+		$replace = [];
371
+		foreach ($context as $key => $value) {
372
+			$replace['{'.$key.'}'] = $this->normalizeValue($value);
373
+		}
374
+		return strtr($message, $replace);
375
+	}
376
+
377
+	/**
378
+	 * @param mixed $value
379
+	 * @return bool
380
+	 */
381
+	protected function isObjectOrArray($value)
382
+	{
383
+		return is_object($value) || is_array($value);
384
+	}
385
+
386
+	/**
387
+	 * @param string $backtraceLine
388
+	 * @return string
389
+	 */
390
+	protected function normalizeBacktraceLine($backtraceLine)
391
+	{
392
+		$search = [
393
+			glsr()->path('plugin/'),
394
+			glsr()->path('plugin/', false),
395
+			trailingslashit(glsr()->path()),
396
+			trailingslashit(glsr()->path('', false)),
397
+			WP_CONTENT_DIR,
398
+			ABSPATH,
399
+		];
400
+		return str_replace(array_unique($search), '', $backtraceLine);
401
+	}
402
+
403
+	/**
404
+	 * @param string $message
405
+	 * @return string
406
+	 */
407
+	protected function normalizeThrowableMessage($message)
408
+	{
409
+		$calledIn = strpos($message, ', called in');
410
+		return false !== $calledIn
411
+			? substr($message, 0, $calledIn)
412
+			: $message;
413
+	}
414
+
415
+	/**
416
+	 * @param mixed $value
417
+	 * @return string
418
+	 */
419
+	protected function normalizeValue($value)
420
+	{
421
+		if ($value instanceof DateTime) {
422
+			$value = $value->format('Y-m-d H:i:s');
423
+		} elseif ($this->isObjectOrArray($value)) {
424
+			$value = json_encode($value);
425
+		}
426
+		return (string) $value;
427
+	}
428
+
429
+	/**
430
+	 * @return void
431
+	 */
432
+	protected function reset()
433
+	{
434
+		if ($this->size() <= pow(1024, 2) / 8) {
435
+			return;
436
+		}
437
+		$this->clear();
438
+		file_put_contents(
439
+			$this->file,
440
+			$this->buildLogEntry(
441
+				static::NOTICE,
442
+				__('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
443
+			)
444
+		);
445
+	}
446 446
 }
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -10,13 +10,13 @@  discard block
 block discarded – undo
10 10
 
11 11
 class Console
12 12
 {
13
-    const DEBUG = 0;      // Detailed debug information
14
-    const INFO = 1;       // Interesting events
15
-    const NOTICE = 2;     // Normal but significant events
16
-    const WARNING = 4;    // Exceptional occurrences that are not errors
17
-    const ERROR = 8;      // Runtime errors that do not require immediate action
18
-    const CRITICAL = 16;  // Critical conditions
19
-    const ALERT = 32;     // Action must be taken immediately
13
+    const DEBUG = 0; // Detailed debug information
14
+    const INFO = 1; // Interesting events
15
+    const NOTICE = 2; // Normal but significant events
16
+    const WARNING = 4; // Exceptional occurrences that are not errors
17
+    const ERROR = 8; // Runtime errors that do not require immediate action
18
+    const CRITICAL = 16; // Critical conditions
19
+    const ALERT = 32; // Action must be taken immediately
20 20
     const EMERGENCY = 64; // System is unusable
21 21
 
22 22
     protected $file;
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
 
26 26
     public function __construct()
27 27
     {
28
-        $this->file = glsr()->path('console.log');
29
-        $this->log = file_exists($this->file)
30
-            ? file_get_contents($this->file)
28
+        $this->file = glsr()->path( 'console.log' );
29
+        $this->log = file_exists( $this->file )
30
+            ? file_get_contents( $this->file )
31 31
             : '';
32 32
         $this->reset();
33 33
     }
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
      * @param array $context
48 48
      * @return static
49 49
      */
50
-    public function alert($message, array $context = [])
50
+    public function alert( $message, array $context = [] )
51 51
     {
52
-        return $this->log(static::ALERT, $message, $context);
52
+        return $this->log( static::ALERT, $message, $context );
53 53
     }
54 54
 
55 55
     /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     public function clear()
59 59
     {
60 60
         $this->log = '';
61
-        file_put_contents($this->file, $this->log);
61
+        file_put_contents( $this->file, $this->log );
62 62
     }
63 63
 
64 64
     /**
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
      * @param array $context
69 69
      * @return static
70 70
      */
71
-    public function critical($message, array $context = [])
71
+    public function critical( $message, array $context = [] )
72 72
     {
73
-        return $this->log(static::CRITICAL, $message, $context);
73
+        return $this->log( static::CRITICAL, $message, $context );
74 74
     }
75 75
 
76 76
     /**
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
      * @param array $context
80 80
      * @return static
81 81
      */
82
-    public function debug($message, array $context = [])
82
+    public function debug( $message, array $context = [] )
83 83
     {
84
-        return $this->log(static::DEBUG, $message, $context);
84
+        return $this->log( static::DEBUG, $message, $context );
85 85
     }
86 86
 
87 87
     /**
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
      * @param array $context
91 91
      * @return static
92 92
      */
93
-    public function emergency($message, array $context = [])
93
+    public function emergency( $message, array $context = [] )
94 94
     {
95
-        return $this->log(static::EMERGENCY, $message, $context);
95
+        return $this->log( static::EMERGENCY, $message, $context );
96 96
     }
97 97
 
98 98
     /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
      * @param array $context
102 102
      * @return static
103 103
      */
104
-    public function error($message, array $context = [])
104
+    public function error( $message, array $context = [] )
105 105
     {
106
-        return $this->log(static::ERROR, $message, $context);
106
+        return $this->log( static::ERROR, $message, $context );
107 107
     }
108 108
 
109 109
     /**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     public function get()
113 113
     {
114 114
         return empty($this->log)
115
-            ? __('Console is empty', 'site-reviews')
115
+            ? __( 'Console is empty', 'site-reviews' )
116 116
             : $this->log;
117 117
     }
118 118
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function getLevel()
123 123
     {
124
-        return intval(apply_filters('site-reviews/console/level', static::INFO));
124
+        return intval( apply_filters( 'site-reviews/console/level', static::INFO ) );
125 125
     }
126 126
 
127 127
     /**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
      */
130 130
     public function getLevels()
131 131
     {
132
-        $constants = (new ReflectionClass(__CLASS__))->getConstants();
133
-        return array_map('strtolower', array_flip($constants));
132
+        $constants = (new ReflectionClass( __CLASS__ ))->getConstants();
133
+        return array_map( 'strtolower', array_flip( $constants ) );
134 134
     }
135 135
 
136 136
     /**
@@ -139,21 +139,21 @@  discard block
 block discarded – undo
139 139
     public function humanLevel()
140 140
     {
141 141
         $level = $this->getLevel();
142
-        return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
142
+        return sprintf( '%s (%d)', strtoupper( Arr::get( $this->getLevels(), $level, 'unknown' ) ), $level );
143 143
     }
144 144
 
145 145
     /**
146 146
      * @param string|null $valueIfEmpty
147 147
      * @return string
148 148
      */
149
-    public function humanSize($valueIfEmpty = null)
149
+    public function humanSize( $valueIfEmpty = null )
150 150
     {
151 151
         $bytes = $this->size();
152
-        if (empty($bytes) && is_string($valueIfEmpty)) {
152
+        if( empty($bytes) && is_string( $valueIfEmpty ) ) {
153 153
             return $valueIfEmpty;
154 154
         }
155
-        $exponent = floor(log(max($bytes, 1), 1024));
156
-        return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
155
+        $exponent = floor( log( max( $bytes, 1 ), 1024 ) );
156
+        return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157 157
     }
158 158
 
159 159
     /**
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
      * @param array $context
164 164
      * @return static
165 165
      */
166
-    public function info($message, array $context = [])
166
+    public function info( $message, array $context = [] )
167 167
     {
168
-        return $this->log(static::INFO, $message, $context);
168
+        return $this->log( static::INFO, $message, $context );
169 169
     }
170 170
 
171 171
     /**
@@ -175,19 +175,19 @@  discard block
 block discarded – undo
175 175
      * @param string $backtraceLine
176 176
      * @return static
177 177
      */
178
-    public function log($level, $message, $context = [], $backtraceLine = '')
178
+    public function log( $level, $message, $context = [], $backtraceLine = '' )
179 179
     {
180
-        if (empty($backtraceLine)) {
180
+        if( empty($backtraceLine) ) {
181 181
             $backtraceLine = $this->getBacktraceLine();
182 182
         }
183
-        if ($this->canLogEntry($level, $backtraceLine)) {
184
-            $levelName = Arr::get($this->getLevels(), $level);
185
-            $context = Arr::consolidateArray($context);
186
-            $backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
-            $message = $this->interpolate($message, $context);
188
-            $entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
-            file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
-            apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
183
+        if( $this->canLogEntry( $level, $backtraceLine ) ) {
184
+            $levelName = Arr::get( $this->getLevels(), $level );
185
+            $context = Arr::consolidateArray( $context );
186
+            $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine );
187
+            $message = $this->interpolate( $message, $context );
188
+            $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine );
189
+            file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX );
190
+            apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed
191 191
             $this->reset();
192 192
         }
193 193
         return $this;
@@ -198,17 +198,17 @@  discard block
 block discarded – undo
198 198
      */
199 199
     public function logOnce()
200 200
     {
201
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
201
+        $once = Arr::consolidateArray( glsr()->{$this->logOnceKey});
202 202
         $levels = $this->getLevels();
203
-        foreach ($once as $entry) {
204
-            $levelName = Arr::get($entry, 'level');
205
-            if (!in_array($levelName, $levels)) {
203
+        foreach( $once as $entry ) {
204
+            $levelName = Arr::get( $entry, 'level' );
205
+            if( !in_array( $levelName, $levels ) ) {
206 206
                 continue;
207 207
             }
208
-            $level = Arr::get(array_flip($levels), $levelName);
209
-            $message = Arr::get($entry, 'message');
210
-            $backtraceLine = Arr::get($entry, 'backtrace');
211
-            $this->log($level, $message, [], $backtraceLine);
208
+            $level = Arr::get( array_flip( $levels ), $levelName );
209
+            $message = Arr::get( $entry, 'message' );
210
+            $backtraceLine = Arr::get( $entry, 'backtrace' );
211
+            $this->log( $level, $message, [], $backtraceLine );
212 212
         }
213 213
         glsr()->{$this->logOnceKey} = [];
214 214
     }
@@ -219,9 +219,9 @@  discard block
 block discarded – undo
219 219
      * @param array $context
220 220
      * @return static
221 221
      */
222
-    public function notice($message, array $context = [])
222
+    public function notice( $message, array $context = [] )
223 223
     {
224
-        return $this->log(static::NOTICE, $message, $context);
224
+        return $this->log( static::NOTICE, $message, $context );
225 225
     }
226 226
 
227 227
     /**
@@ -230,21 +230,21 @@  discard block
 block discarded – undo
230 230
      * @param mixed $data
231 231
      * @return void
232 232
      */
233
-    public function once($levelName, $handle, $data)
233
+    public function once( $levelName, $handle, $data )
234 234
     {
235
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
-        $filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
-            return Arr::get($entry, 'level') == $levelName
238
-                && Arr::get($entry, 'handle') == $handle;
235
+        $once = Arr::consolidateArray( glsr()->{$this->logOnceKey});
236
+        $filtered = array_filter( $once, function( $entry ) use ($levelName, $handle) {
237
+            return Arr::get( $entry, 'level' ) == $levelName
238
+                && Arr::get( $entry, 'handle' ) == $handle;
239 239
         });
240
-        if (!empty($filtered)) {
240
+        if( !empty($filtered) ) {
241 241
             return;
242 242
         }
243 243
         $once[] = [
244
-            'backtrace' => $this->getBacktraceLineFromData($data),
244
+            'backtrace' => $this->getBacktraceLineFromData( $data ),
245 245
             'handle' => $handle,
246 246
             'level' => $levelName,
247
-            'message' => '[RECURRING] '.$this->getMessageFromData($data),
247
+            'message' => '[RECURRING] '.$this->getMessageFromData( $data ),
248 248
         ];
249 249
         glsr()->{$this->logOnceKey} = $once;
250 250
     }
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
      */
255 255
     public function size()
256 256
     {
257
-        return file_exists($this->file)
258
-            ? filesize($this->file)
257
+        return file_exists( $this->file )
258
+            ? filesize( $this->file )
259 259
             : 0;
260 260
     }
261 261
 
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
      * @param array $context
267 267
      * @return static
268 268
      */
269
-    public function warning($message, array $context = [])
269
+    public function warning( $message, array $context = [] )
270 270
     {
271
-        return $this->log(static::WARNING, $message, $context);
271
+        return $this->log( static::WARNING, $message, $context );
272 272
     }
273 273
 
274 274
     /**
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
      * @param int $index
277 277
      * @return string
278 278
      */
279
-    protected function buildBacktraceLine($backtrace, $index)
279
+    protected function buildBacktraceLine( $backtrace, $index )
280 280
     {
281
-        return sprintf('%s:%s',
282
-            Arr::get($backtrace, $index.'.file'), // realpath
283
-            Arr::get($backtrace, $index.'.line')
281
+        return sprintf( '%s:%s',
282
+            Arr::get( $backtrace, $index.'.file' ), // realpath
283
+            Arr::get( $backtrace, $index.'.line' )
284 284
         );
285 285
     }
286 286
 
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
      * @param string $backtraceLine
291 291
      * @return string
292 292
      */
293
-    protected function buildLogEntry($levelName, $message, $backtraceLine = '')
293
+    protected function buildLogEntry( $levelName, $message, $backtraceLine = '' )
294 294
     {
295
-        return sprintf('[%s] %s [%s] %s',
296
-            current_time('mysql'),
297
-            strtoupper($levelName),
295
+        return sprintf( '[%s] %s [%s] %s',
296
+            current_time( 'mysql' ),
297
+            strtoupper( $levelName ),
298 298
             $backtraceLine,
299 299
             $message
300 300
         );
@@ -304,10 +304,10 @@  discard block
 block discarded – undo
304 304
      * @param int $level
305 305
      * @return bool
306 306
      */
307
-    protected function canLogEntry($level, $backtraceLine)
307
+    protected function canLogEntry( $level, $backtraceLine )
308 308
     {
309
-        $levelExists = array_key_exists($level, $this->getLevels());
310
-        if (!Str::contains($backtraceLine, glsr()->path())) {
309
+        $levelExists = array_key_exists( $level, $this->getLevels() );
310
+        if( !Str::contains( $backtraceLine, glsr()->path() ) ) {
311 311
             return $levelExists; // ignore level restriction if triggered outside of the plugin
312 312
         }
313 313
         return $levelExists && $level >= $this->getLevel();
@@ -318,17 +318,17 @@  discard block
 block discarded – undo
318 318
      */
319 319
     protected function getBacktraceLine()
320 320
     {
321
-        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
-        $search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
-        if (false !== $search) {
324
-            return $this->buildBacktraceLine($backtrace, (int) $search);
321
+        $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 );
322
+        $search = array_search( 'glsr_log', glsr_array_column( $backtrace, 'function' ) );
323
+        if( false !== $search ) {
324
+            return $this->buildBacktraceLine( $backtrace, (int)$search );
325 325
         }
326
-        $search = array_search('log', glsr_array_column($backtrace, 'function'));
327
-        if (false !== $search) {
328
-            $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
326
+        $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) );
327
+        if( false !== $search ) {
328
+            $index = '{closure}' == Arr::get( $backtrace, ($search + 2).'.function' )
329 329
                 ? $search + 4
330 330
                 : $search + 1;
331
-            return $this->buildBacktraceLine($backtrace, $index);
331
+            return $this->buildBacktraceLine( $backtrace, $index );
332 332
         }
333 333
         return 'Unknown';
334 334
     }
@@ -337,23 +337,23 @@  discard block
 block discarded – undo
337 337
      * @param mixed $data
338 338
      * @return string
339 339
      */
340
-    protected function getBacktraceLineFromData($data)
340
+    protected function getBacktraceLineFromData( $data )
341 341
     {
342 342
         $backtrace = $data instanceof Throwable
343 343
             ? $data->getTrace()
344
-            : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
-        return $this->buildBacktraceLine($backtrace, 0);
344
+            : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 );
345
+        return $this->buildBacktraceLine( $backtrace, 0 );
346 346
     }
347 347
 
348 348
     /**
349 349
      * @param mixed $data
350 350
      * @return string
351 351
      */
352
-    protected function getMessageFromData($data)
352
+    protected function getMessageFromData( $data )
353 353
     {
354 354
         return $data instanceof Throwable
355
-            ? $this->normalizeThrowableMessage($data->getMessage())
356
-            : print_r($data, 1);
355
+            ? $this->normalizeThrowableMessage( $data->getMessage() )
356
+            : print_r( $data, 1 );
357 357
     }
358 358
 
359 359
     /**
@@ -362,53 +362,53 @@  discard block
 block discarded – undo
362 362
      * @param array $context
363 363
      * @return string
364 364
      */
365
-    protected function interpolate($message, $context = [])
365
+    protected function interpolate( $message, $context = [] )
366 366
     {
367
-        if ($this->isObjectOrArray($message) || !is_array($context)) {
368
-            return print_r($message, true);
367
+        if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) {
368
+            return print_r( $message, true );
369 369
         }
370 370
         $replace = [];
371
-        foreach ($context as $key => $value) {
372
-            $replace['{'.$key.'}'] = $this->normalizeValue($value);
371
+        foreach( $context as $key => $value ) {
372
+            $replace['{'.$key.'}'] = $this->normalizeValue( $value );
373 373
         }
374
-        return strtr($message, $replace);
374
+        return strtr( $message, $replace );
375 375
     }
376 376
 
377 377
     /**
378 378
      * @param mixed $value
379 379
      * @return bool
380 380
      */
381
-    protected function isObjectOrArray($value)
381
+    protected function isObjectOrArray( $value )
382 382
     {
383
-        return is_object($value) || is_array($value);
383
+        return is_object( $value ) || is_array( $value );
384 384
     }
385 385
 
386 386
     /**
387 387
      * @param string $backtraceLine
388 388
      * @return string
389 389
      */
390
-    protected function normalizeBacktraceLine($backtraceLine)
390
+    protected function normalizeBacktraceLine( $backtraceLine )
391 391
     {
392 392
         $search = [
393
-            glsr()->path('plugin/'),
394
-            glsr()->path('plugin/', false),
395
-            trailingslashit(glsr()->path()),
396
-            trailingslashit(glsr()->path('', false)),
393
+            glsr()->path( 'plugin/' ),
394
+            glsr()->path( 'plugin/', false ),
395
+            trailingslashit( glsr()->path() ),
396
+            trailingslashit( glsr()->path( '', false ) ),
397 397
             WP_CONTENT_DIR,
398 398
             ABSPATH,
399 399
         ];
400
-        return str_replace(array_unique($search), '', $backtraceLine);
400
+        return str_replace( array_unique( $search ), '', $backtraceLine );
401 401
     }
402 402
 
403 403
     /**
404 404
      * @param string $message
405 405
      * @return string
406 406
      */
407
-    protected function normalizeThrowableMessage($message)
407
+    protected function normalizeThrowableMessage( $message )
408 408
     {
409
-        $calledIn = strpos($message, ', called in');
409
+        $calledIn = strpos( $message, ', called in' );
410 410
         return false !== $calledIn
411
-            ? substr($message, 0, $calledIn)
411
+            ? substr( $message, 0, $calledIn )
412 412
             : $message;
413 413
     }
414 414
 
@@ -416,14 +416,14 @@  discard block
 block discarded – undo
416 416
      * @param mixed $value
417 417
      * @return string
418 418
      */
419
-    protected function normalizeValue($value)
419
+    protected function normalizeValue( $value )
420 420
     {
421
-        if ($value instanceof DateTime) {
422
-            $value = $value->format('Y-m-d H:i:s');
423
-        } elseif ($this->isObjectOrArray($value)) {
424
-            $value = json_encode($value);
421
+        if( $value instanceof DateTime ) {
422
+            $value = $value->format( 'Y-m-d H:i:s' );
423
+        } elseif( $this->isObjectOrArray( $value ) ) {
424
+            $value = json_encode( $value );
425 425
         }
426
-        return (string) $value;
426
+        return (string)$value;
427 427
     }
428 428
 
429 429
     /**
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      */
432 432
     protected function reset()
433 433
     {
434
-        if ($this->size() <= pow(1024, 2) / 8) {
434
+        if( $this->size() <= pow( 1024, 2 ) / 8 ) {
435 435
             return;
436 436
         }
437 437
         $this->clear();
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
             $this->file,
440 440
             $this->buildLogEntry(
441 441
                 static::NOTICE,
442
-                __('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
442
+                __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' )
443 443
             )
444 444
         );
445 445
     }
Please login to merge, or discard this patch.
plugin/Modules/Schema/Thing.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@
 block discarded – undo
19 19
  */
20 20
 class Thing extends BaseType
21 21
 {
22
-    /**
23
-     * @var array
24
-     * @see http://schema.org/{property_name}
25
-     */
26
-    public $allowed = [
27
-        'additionalType', 'alternateName', 'description', 'disambiguatingDescription', 'identifier',
28
-        'image', 'mainEntityOfPage', 'name', 'potentialAction', 'sameAs', 'url',
29
-    ];
22
+	/**
23
+	 * @var array
24
+	 * @see http://schema.org/{property_name}
25
+	 */
26
+	public $allowed = [
27
+		'additionalType', 'alternateName', 'description', 'disambiguatingDescription', 'identifier',
28
+		'image', 'mainEntityOfPage', 'name', 'potentialAction', 'sameAs', 'url',
29
+	];
30 30
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema/UnknownType.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,19 +4,19 @@
 block discarded – undo
4 4
 
5 5
 class UnknownType extends BaseType
6 6
 {
7
-    /**
8
-     * @var array
9
-     * @see http://schema.org/{property_name}
10
-     */
11
-    public $allowed = [
12
-        'aggregateRating',
13
-    ];
7
+	/**
8
+	 * @var array
9
+	 * @see http://schema.org/{property_name}
10
+	 */
11
+	public $allowed = [
12
+		'aggregateRating',
13
+	];
14 14
 
15
-    /**
16
-     * @var array
17
-     * @see http://schema.org/{property_name}
18
-     */
19
-    public $parents = [
20
-        'Thing',
21
-    ];
15
+	/**
16
+	 * @var array
17
+	 * @see http://schema.org/{property_name}
18
+	 */
19
+	public $parents = [
20
+		'Thing',
21
+	];
22 22
 }
Please login to merge, or discard this patch.