Passed
Push — master ( 876108...8633df )
by Paul
06:37
created
plugin/Database/OptionManager.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -9,153 +9,153 @@
 block discarded – undo
9 9
 
10 10
 class OptionManager
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    protected $options;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	protected $options;
16 16
 
17
-    /**
18
-     * @return string
19
-     */
20
-    public static function databaseKey($version = null)
21
-    {
22
-        if (null === $version) {
23
-            $version = explode('.', glsr()->version);
24
-            $version = array_shift($version);
25
-        }
26
-        return Str::snakeCase(
27
-            Application::ID.'-v'.intval($version)
28
-        );
29
-    }
17
+	/**
18
+	 * @return string
19
+	 */
20
+	public static function databaseKey($version = null)
21
+	{
22
+		if (null === $version) {
23
+			$version = explode('.', glsr()->version);
24
+			$version = array_shift($version);
25
+		}
26
+		return Str::snakeCase(
27
+			Application::ID.'-v'.intval($version)
28
+		);
29
+	}
30 30
 
31
-    /**
32
-     * @return array
33
-     */
34
-    public function all()
35
-    {
36
-        if (empty($this->options)) {
37
-            $this->reset();
38
-        }
39
-        return $this->options;
40
-    }
31
+	/**
32
+	 * @return array
33
+	 */
34
+	public function all()
35
+	{
36
+		if (empty($this->options)) {
37
+			$this->reset();
38
+		}
39
+		return $this->options;
40
+	}
41 41
 
42
-    /**
43
-     * @param string $path
44
-     * @return bool
45
-     */
46
-    public function delete($path)
47
-    {
48
-        $keys = explode('.', $path);
49
-        $last = array_pop($keys);
50
-        $options = $this->all();
51
-        $pointer = &$options;
52
-        foreach ($keys as $key) {
53
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
54
-                continue;
55
-            }
56
-            $pointer = &$pointer[$key];
57
-        }
58
-        unset($pointer[$last]);
59
-        return $this->set($options);
60
-    }
42
+	/**
43
+	 * @param string $path
44
+	 * @return bool
45
+	 */
46
+	public function delete($path)
47
+	{
48
+		$keys = explode('.', $path);
49
+		$last = array_pop($keys);
50
+		$options = $this->all();
51
+		$pointer = &$options;
52
+		foreach ($keys as $key) {
53
+			if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
54
+				continue;
55
+			}
56
+			$pointer = &$pointer[$key];
57
+		}
58
+		unset($pointer[$last]);
59
+		return $this->set($options);
60
+	}
61 61
 
62
-    /**
63
-     * @param string $path
64
-     * @param mixed $fallback
65
-     * @param string $cast
66
-     * @return mixed
67
-     */
68
-    public function get($path = '', $fallback = '', $cast = '')
69
-    {
70
-        $result = Arr::get($this->all(), $path, $fallback);
71
-        return Helper::castTo($cast, $result);
72
-    }
62
+	/**
63
+	 * @param string $path
64
+	 * @param mixed $fallback
65
+	 * @param string $cast
66
+	 * @return mixed
67
+	 */
68
+	public function get($path = '', $fallback = '', $cast = '')
69
+	{
70
+		$result = Arr::get($this->all(), $path, $fallback);
71
+		return Helper::castTo($cast, $result);
72
+	}
73 73
 
74
-    /**
75
-     * @param string $path
76
-     * @return bool
77
-     */
78
-    public function getBool($path)
79
-    {
80
-        return Helper::castTo('bool', $this->get($path));
81
-    }
74
+	/**
75
+	 * @param string $path
76
+	 * @return bool
77
+	 */
78
+	public function getBool($path)
79
+	{
80
+		return Helper::castTo('bool', $this->get($path));
81
+	}
82 82
 
83
-    /**
84
-     * @param string $path
85
-     * @param mixed $fallback
86
-     * @param string $cast
87
-     * @return mixed
88
-     */
89
-    public function getWP($path, $fallback = '', $cast = '')
90
-    {
91
-        $option = get_option($path, $fallback);
92
-        if (empty($option)) {
93
-            $option = $fallback;
94
-        }
95
-        return Helper::castTo($cast, $option);
96
-    }
83
+	/**
84
+	 * @param string $path
85
+	 * @param mixed $fallback
86
+	 * @param string $cast
87
+	 * @return mixed
88
+	 */
89
+	public function getWP($path, $fallback = '', $cast = '')
90
+	{
91
+		$option = get_option($path, $fallback);
92
+		if (empty($option)) {
93
+			$option = $fallback;
94
+		}
95
+		return Helper::castTo($cast, $option);
96
+	}
97 97
 
98
-    /**
99
-     * @return string
100
-     */
101
-    public function json()
102
-    {
103
-        return json_encode($this->all());
104
-    }
98
+	/**
99
+	 * @return string
100
+	 */
101
+	public function json()
102
+	{
103
+		return json_encode($this->all());
104
+	}
105 105
 
106
-    /**
107
-     * @return array
108
-     */
109
-    public function normalize(array $options = [])
110
-    {
111
-        $options = wp_parse_args(
112
-            Arr::flattenArray($options),
113
-            glsr(DefaultsManager::class)->defaults()
114
-        );
115
-        array_walk($options, function (&$value) {
116
-            if (!is_string($value)) {
117
-                return;
118
-            }
119
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
120
-        });
121
-        return Arr::convertDotNotationArray($options);
122
-    }
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function normalize(array $options = [])
110
+	{
111
+		$options = wp_parse_args(
112
+			Arr::flattenArray($options),
113
+			glsr(DefaultsManager::class)->defaults()
114
+		);
115
+		array_walk($options, function (&$value) {
116
+			if (!is_string($value)) {
117
+				return;
118
+			}
119
+			$value = wp_kses($value, wp_kses_allowed_html('post'));
120
+		});
121
+		return Arr::convertDotNotationArray($options);
122
+	}
123 123
 
124
-    /**
125
-     * @return bool
126
-     */
127
-    public function isRecaptchaEnabled()
128
-    {
129
-        $integration = $this->get('settings.submissions.recaptcha.integration');
130
-        return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131
-    }
124
+	/**
125
+	 * @return bool
126
+	 */
127
+	public function isRecaptchaEnabled()
128
+	{
129
+		$integration = $this->get('settings.submissions.recaptcha.integration');
130
+		return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131
+	}
132 132
 
133
-    /**
134
-     * @return array
135
-     */
136
-    public function reset()
137
-    {
138
-        $options = $this->getWP(static::databaseKey(), []);
139
-        if (!is_array($options) || empty($options)) {
140
-            delete_option(static::databaseKey());
141
-            $options = glsr()->defaults ?: [];
142
-        }
143
-        $this->options = $options;
144
-    }
133
+	/**
134
+	 * @return array
135
+	 */
136
+	public function reset()
137
+	{
138
+		$options = $this->getWP(static::databaseKey(), []);
139
+		if (!is_array($options) || empty($options)) {
140
+			delete_option(static::databaseKey());
141
+			$options = glsr()->defaults ?: [];
142
+		}
143
+		$this->options = $options;
144
+	}
145 145
 
146
-    /**
147
-     * @param string|array $pathOrOptions
148
-     * @param mixed $value
149
-     * @return bool
150
-     */
151
-    public function set($pathOrOptions, $value = '')
152
-    {
153
-        if (is_string($pathOrOptions)) {
154
-            $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
155
-        }
156
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
157
-            $this->reset();
158
-        }
159
-        return $result;
160
-    }
146
+	/**
147
+	 * @param string|array $pathOrOptions
148
+	 * @param mixed $value
149
+	 * @return bool
150
+	 */
151
+	public function set($pathOrOptions, $value = '')
152
+	{
153
+		if (is_string($pathOrOptions)) {
154
+			$pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
155
+		}
156
+		if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
157
+			$this->reset();
158
+		}
159
+		return $result;
160
+	}
161 161
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
     /**
18 18
      * @return string
19 19
      */
20
-    public static function databaseKey($version = null)
20
+    public static function databaseKey( $version = null )
21 21
     {
22
-        if (null === $version) {
23
-            $version = explode('.', glsr()->version);
24
-            $version = array_shift($version);
22
+        if( null === $version ) {
23
+            $version = explode( '.', glsr()->version );
24
+            $version = array_shift( $version );
25 25
         }
26 26
         return Str::snakeCase(
27
-            Application::ID.'-v'.intval($version)
27
+            Application::ID.'-v'.intval( $version )
28 28
         );
29 29
     }
30 30
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function all()
35 35
     {
36
-        if (empty($this->options)) {
36
+        if( empty($this->options) ) {
37 37
             $this->reset();
38 38
         }
39 39
         return $this->options;
@@ -43,20 +43,20 @@  discard block
 block discarded – undo
43 43
      * @param string $path
44 44
      * @return bool
45 45
      */
46
-    public function delete($path)
46
+    public function delete( $path )
47 47
     {
48
-        $keys = explode('.', $path);
49
-        $last = array_pop($keys);
48
+        $keys = explode( '.', $path );
49
+        $last = array_pop( $keys );
50 50
         $options = $this->all();
51 51
         $pointer = &$options;
52
-        foreach ($keys as $key) {
53
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
52
+        foreach( $keys as $key ) {
53
+            if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) {
54 54
                 continue;
55 55
             }
56 56
             $pointer = &$pointer[$key];
57 57
         }
58 58
         unset($pointer[$last]);
59
-        return $this->set($options);
59
+        return $this->set( $options );
60 60
     }
61 61
 
62 62
     /**
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
      * @param string $cast
66 66
      * @return mixed
67 67
      */
68
-    public function get($path = '', $fallback = '', $cast = '')
68
+    public function get( $path = '', $fallback = '', $cast = '' )
69 69
     {
70
-        $result = Arr::get($this->all(), $path, $fallback);
71
-        return Helper::castTo($cast, $result);
70
+        $result = Arr::get( $this->all(), $path, $fallback );
71
+        return Helper::castTo( $cast, $result );
72 72
     }
73 73
 
74 74
     /**
75 75
      * @param string $path
76 76
      * @return bool
77 77
      */
78
-    public function getBool($path)
78
+    public function getBool( $path )
79 79
     {
80
-        return Helper::castTo('bool', $this->get($path));
80
+        return Helper::castTo( 'bool', $this->get( $path ) );
81 81
     }
82 82
 
83 83
     /**
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
      * @param string $cast
87 87
      * @return mixed
88 88
      */
89
-    public function getWP($path, $fallback = '', $cast = '')
89
+    public function getWP( $path, $fallback = '', $cast = '' )
90 90
     {
91
-        $option = get_option($path, $fallback);
92
-        if (empty($option)) {
91
+        $option = get_option( $path, $fallback );
92
+        if( empty($option) ) {
93 93
             $option = $fallback;
94 94
         }
95
-        return Helper::castTo($cast, $option);
95
+        return Helper::castTo( $cast, $option );
96 96
     }
97 97
 
98 98
     /**
@@ -100,25 +100,25 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function json()
102 102
     {
103
-        return json_encode($this->all());
103
+        return json_encode( $this->all() );
104 104
     }
105 105
 
106 106
     /**
107 107
      * @return array
108 108
      */
109
-    public function normalize(array $options = [])
109
+    public function normalize( array $options = [] )
110 110
     {
111 111
         $options = wp_parse_args(
112
-            Arr::flattenArray($options),
113
-            glsr(DefaultsManager::class)->defaults()
112
+            Arr::flattenArray( $options ),
113
+            glsr( DefaultsManager::class )->defaults()
114 114
         );
115
-        array_walk($options, function (&$value) {
116
-            if (!is_string($value)) {
115
+        array_walk( $options, function( &$value ) {
116
+            if( !is_string( $value ) ) {
117 117
                 return;
118 118
             }
119
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
119
+            $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) );
120 120
         });
121
-        return Arr::convertDotNotationArray($options);
121
+        return Arr::convertDotNotationArray( $options );
122 122
     }
123 123
 
124 124
     /**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function isRecaptchaEnabled()
128 128
     {
129
-        $integration = $this->get('settings.submissions.recaptcha.integration');
129
+        $integration = $this->get( 'settings.submissions.recaptcha.integration' );
130 130
         return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131 131
     }
132 132
 
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function reset()
137 137
     {
138
-        $options = $this->getWP(static::databaseKey(), []);
139
-        if (!is_array($options) || empty($options)) {
140
-            delete_option(static::databaseKey());
138
+        $options = $this->getWP( static::databaseKey(), [] );
139
+        if( !is_array( $options ) || empty($options) ) {
140
+            delete_option( static::databaseKey() );
141 141
             $options = glsr()->defaults ?: [];
142 142
         }
143 143
         $this->options = $options;
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
      * @param mixed $value
149 149
      * @return bool
150 150
      */
151
-    public function set($pathOrOptions, $value = '')
151
+    public function set( $pathOrOptions, $value = '' )
152 152
     {
153
-        if (is_string($pathOrOptions)) {
154
-            $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
153
+        if( is_string( $pathOrOptions ) ) {
154
+            $pathOrOptions = Arr::set( $this->all(), $pathOrOptions, $value );
155 155
         }
156
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
156
+        if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) {
157 157
             $this->reset();
158 158
         }
159 159
         return $result;
Please login to merge, or discard this patch.
plugin/Commands/RegisterPostType.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -9,77 +9,77 @@
 block discarded – undo
9 9
 
10 10
 class RegisterPostType
11 11
 {
12
-    public $args;
13
-    public $columns;
14
-    public $plural;
15
-    public $postType;
16
-    public $single;
12
+	public $args;
13
+	public $columns;
14
+	public $plural;
15
+	public $postType;
16
+	public $single;
17 17
 
18
-    public function __construct($input)
19
-    {
20
-        $args = glsr(PostTypeDefaults::class)->merge($input);
21
-        $this->normalize($args);
22
-        $this->normalizeColumns();
23
-        $this->normalizeLabels();
24
-    }
18
+	public function __construct($input)
19
+	{
20
+		$args = glsr(PostTypeDefaults::class)->merge($input);
21
+		$this->normalize($args);
22
+		$this->normalizeColumns();
23
+		$this->normalizeLabels();
24
+	}
25 25
 
26
-    /**
27
-     * @return void
28
-     */
29
-    protected function normalize(array $args)
30
-    {
31
-        foreach ($args as $key => $value) {
32
-            $property = Helper::buildPropertyName($key);
33
-            if (!property_exists($this, $property)) {
34
-                continue;
35
-            }
36
-            $this->$property = $value;
37
-            unset($args[$key]);
38
-        }
39
-        $this->args = wp_parse_args($args, [
40
-            'menu_name' => $this->plural,
41
-        ]);
42
-    }
26
+	/**
27
+	 * @return void
28
+	 */
29
+	protected function normalize(array $args)
30
+	{
31
+		foreach ($args as $key => $value) {
32
+			$property = Helper::buildPropertyName($key);
33
+			if (!property_exists($this, $property)) {
34
+				continue;
35
+			}
36
+			$this->$property = $value;
37
+			unset($args[$key]);
38
+		}
39
+		$this->args = wp_parse_args($args, [
40
+			'menu_name' => $this->plural,
41
+		]);
42
+	}
43 43
 
44
-    /**
45
-     * @return void
46
-     */
47
-    protected function normalizeLabels()
48
-    {
49
-        $this->args['labels'] = wp_parse_args($this->args['labels'], [
50
-            'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural),
51
-            'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural),
52
-            'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single),
53
-            'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single),
54
-            'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single),
55
-            'menu_name' => $this->args['menu_name'],
56
-            'name' => $this->plural,
57
-            'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single),
58
-            'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural),
59
-            'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural),
60
-            'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural),
61
-            'singular_name' => $this->single,
62
-            'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single),
63
-            'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single),
64
-        ]);
65
-        unset($this->args['menu_name']);
66
-    }
44
+	/**
45
+	 * @return void
46
+	 */
47
+	protected function normalizeLabels()
48
+	{
49
+		$this->args['labels'] = wp_parse_args($this->args['labels'], [
50
+			'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural),
51
+			'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural),
52
+			'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single),
53
+			'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single),
54
+			'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single),
55
+			'menu_name' => $this->args['menu_name'],
56
+			'name' => $this->plural,
57
+			'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single),
58
+			'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural),
59
+			'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural),
60
+			'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural),
61
+			'singular_name' => $this->single,
62
+			'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single),
63
+			'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single),
64
+		]);
65
+		unset($this->args['menu_name']);
66
+	}
67 67
 
68
-    /**
69
-     * @return void
70
-     */
71
-    protected function normalizeColumns()
72
-    {
73
-        $this->columns = ['cb' => ''] + $this->columns;
74
-        if (array_key_exists('category', $this->columns)) {
75
-            $keys = array_keys($this->columns);
76
-            $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY;
77
-            $this->columns = array_combine($keys, $this->columns);
78
-        }
79
-        if (array_key_exists('pinned', $this->columns)) {
80
-            $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>',
81
-                ['class' => 'pinned-icon']
82
-            );
83
-        }
84
-    }
68
+	/**
69
+	 * @return void
70
+	 */
71
+	protected function normalizeColumns()
72
+	{
73
+		$this->columns = ['cb' => ''] + $this->columns;
74
+		if (array_key_exists('category', $this->columns)) {
75
+			$keys = array_keys($this->columns);
76
+			$keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY;
77
+			$this->columns = array_combine($keys, $this->columns);
78
+		}
79
+		if (array_key_exists('pinned', $this->columns)) {
80
+			$this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>',
81
+				['class' => 'pinned-icon']
82
+			);
83
+		}
84
+	}
85 85
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
     public $postType;
16 16
     public $single;
17 17
 
18
-    public function __construct($input)
18
+    public function __construct( $input )
19 19
     {
20
-        $args = glsr(PostTypeDefaults::class)->merge($input);
21
-        $this->normalize($args);
20
+        $args = glsr( PostTypeDefaults::class )->merge( $input );
21
+        $this->normalize( $args );
22 22
         $this->normalizeColumns();
23 23
         $this->normalizeLabels();
24 24
     }
@@ -26,19 +26,19 @@  discard block
 block discarded – undo
26 26
     /**
27 27
      * @return void
28 28
      */
29
-    protected function normalize(array $args)
29
+    protected function normalize( array $args )
30 30
     {
31
-        foreach ($args as $key => $value) {
32
-            $property = Helper::buildPropertyName($key);
33
-            if (!property_exists($this, $property)) {
31
+        foreach( $args as $key => $value ) {
32
+            $property = Helper::buildPropertyName( $key );
33
+            if( !property_exists( $this, $property ) ) {
34 34
                 continue;
35 35
             }
36 36
             $this->$property = $value;
37 37
             unset($args[$key]);
38 38
         }
39
-        $this->args = wp_parse_args($args, [
39
+        $this->args = wp_parse_args( $args, [
40 40
             'menu_name' => $this->plural,
41
-        ]);
41
+        ] );
42 42
     }
43 43
 
44 44
     /**
@@ -46,22 +46,22 @@  discard block
 block discarded – undo
46 46
      */
47 47
     protected function normalizeLabels()
48 48
     {
49
-        $this->args['labels'] = wp_parse_args($this->args['labels'], [
50
-            'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural),
51
-            'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural),
52
-            'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single),
53
-            'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single),
54
-            'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single),
49
+        $this->args['labels'] = wp_parse_args( $this->args['labels'], [
50
+            'add_new_item' => sprintf( _x( 'Add New %s', 'Add New Post', 'site-reviews' ), $this->plural ),
51
+            'all_items' => sprintf( _x( 'All %s', 'All Posts', 'site-reviews' ), $this->plural ),
52
+            'archives' => sprintf( _x( '%s Archives', 'Post Archives', 'site-reviews' ), $this->single ),
53
+            'edit_item' => sprintf( _x( 'Edit %s', 'Edit Post', 'site-reviews' ), $this->single ),
54
+            'insert_into_item' => sprintf( _x( 'Insert into %s', 'Insert into Post', 'site-reviews' ), $this->single ),
55 55
             'menu_name' => $this->args['menu_name'],
56 56
             'name' => $this->plural,
57
-            'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single),
58
-            'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural),
59
-            'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural),
60
-            'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural),
57
+            'new_item' => sprintf( _x( 'New %s', 'New Post', 'site-reviews' ), $this->single ),
58
+            'not_found' => sprintf( _x( 'No %s found', 'No Posts found', 'site-reviews' ), $this->plural ),
59
+            'not_found_in_trash' => sprintf( _x( 'No %s found in Trash', 'No Posts found in Trash', 'site-reviews' ), $this->plural ),
60
+            'search_items' => sprintf( _x( 'Search %s', 'Search Posts', 'site-reviews' ), $this->plural ),
61 61
             'singular_name' => $this->single,
62
-            'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single),
63
-            'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single),
64
-        ]);
62
+            'uploaded_to_this_item' => sprintf( _x( 'Uploaded to this %s', 'Uploaded to this Post', 'site-reviews' ), $this->single ),
63
+            'view_item' => sprintf( _x( 'View %s', 'View Post', 'site-reviews' ), $this->single ),
64
+        ] );
65 65
         unset($this->args['menu_name']);
66 66
     }
67 67
 
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
     protected function normalizeColumns()
72 72
     {
73 73
         $this->columns = ['cb' => ''] + $this->columns;
74
-        if (array_key_exists('category', $this->columns)) {
75
-            $keys = array_keys($this->columns);
76
-            $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY;
77
-            $this->columns = array_combine($keys, $this->columns);
74
+        if( array_key_exists( 'category', $this->columns ) ) {
75
+            $keys = array_keys( $this->columns );
76
+            $keys[array_search( 'category', $keys )] = 'taxonomy-'.Application::TAXONOMY;
77
+            $this->columns = array_combine( $keys, $this->columns );
78 78
         }
79
-        if (array_key_exists('pinned', $this->columns)) {
80
-            $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>',
79
+        if( array_key_exists( 'pinned', $this->columns ) ) {
80
+            $this->columns['pinned'] = glsr( Builder::class )->span( '<span>'.$this->columns['pinned'].'</span>',
81 81
                 ['class' => 'pinned-icon']
82 82
             );
83 83
         }
Please login to merge, or discard this patch.
plugin/Commands/CreateReview.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -6,140 +6,140 @@
 block discarded – undo
6 6
 
7 7
 class CreateReview
8 8
 {
9
-    public $ajax_request;
10
-    public $assigned_to;
11
-    public $author;
12
-    public $avatar;
13
-    public $blacklisted;
14
-    public $category;
15
-    public $content;
16
-    public $custom;
17
-    public $date;
18
-    public $email;
19
-    public $form_id;
20
-    public $ip_address;
21
-    public $post_id;
22
-    public $rating;
23
-    public $referer;
24
-    public $request;
25
-    public $response;
26
-    public $terms;
27
-    public $title;
28
-    public $url;
9
+	public $ajax_request;
10
+	public $assigned_to;
11
+	public $author;
12
+	public $avatar;
13
+	public $blacklisted;
14
+	public $category;
15
+	public $content;
16
+	public $custom;
17
+	public $date;
18
+	public $email;
19
+	public $form_id;
20
+	public $ip_address;
21
+	public $post_id;
22
+	public $rating;
23
+	public $referer;
24
+	public $request;
25
+	public $response;
26
+	public $terms;
27
+	public $title;
28
+	public $url;
29 29
 
30
-    public function __construct($input)
31
-    {
32
-        $this->request = $input;
33
-        $this->ajax_request = isset($input['_ajax_request']);
34
-        $this->assigned_to = $this->getNumeric('assign_to');
35
-        $this->author = sanitize_text_field($this->getUser('name'));
36
-        $this->avatar = $this->getAvatar();
37
-        $this->blacklisted = isset($input['blacklisted']);
38
-        $this->category = $this->getCategory();
39
-        $this->content = sanitize_textarea_field($this->get('content'));
40
-        $this->custom = $this->getCustom();
41
-        $this->date = $this->getDate('date');
42
-        $this->email = sanitize_email($this->getUser('email'));
43
-        $this->form_id = sanitize_key($this->get('form_id'));
44
-        $this->ip_address = $this->get('ip_address');
45
-        $this->post_id = intval($this->get('_post_id'));
46
-        $this->rating = intval($this->get('rating'));
47
-        $this->referer = $this->get('_referer');
48
-        $this->response = sanitize_textarea_field($this->get('response'));
49
-        $this->terms = !empty($input['terms']);
50
-        $this->title = sanitize_text_field($this->get('title'));
51
-        $this->url = esc_url_raw($this->get('url'));
52
-    }
30
+	public function __construct($input)
31
+	{
32
+		$this->request = $input;
33
+		$this->ajax_request = isset($input['_ajax_request']);
34
+		$this->assigned_to = $this->getNumeric('assign_to');
35
+		$this->author = sanitize_text_field($this->getUser('name'));
36
+		$this->avatar = $this->getAvatar();
37
+		$this->blacklisted = isset($input['blacklisted']);
38
+		$this->category = $this->getCategory();
39
+		$this->content = sanitize_textarea_field($this->get('content'));
40
+		$this->custom = $this->getCustom();
41
+		$this->date = $this->getDate('date');
42
+		$this->email = sanitize_email($this->getUser('email'));
43
+		$this->form_id = sanitize_key($this->get('form_id'));
44
+		$this->ip_address = $this->get('ip_address');
45
+		$this->post_id = intval($this->get('_post_id'));
46
+		$this->rating = intval($this->get('rating'));
47
+		$this->referer = $this->get('_referer');
48
+		$this->response = sanitize_textarea_field($this->get('response'));
49
+		$this->terms = !empty($input['terms']);
50
+		$this->title = sanitize_text_field($this->get('title'));
51
+		$this->url = esc_url_raw($this->get('url'));
52
+	}
53 53
 
54
-    /**
55
-     * @param string $key
56
-     * @return string
57
-     */
58
-    protected function get($key)
59
-    {
60
-        return (string) Arr::get($this->request, $key);
61
-    }
54
+	/**
55
+	 * @param string $key
56
+	 * @return string
57
+	 */
58
+	protected function get($key)
59
+	{
60
+		return (string) Arr::get($this->request, $key);
61
+	}
62 62
 
63
-    /**
64
-     * @return string
65
-     */
66
-    protected function getAvatar()
67
-    {
68
-        $avatar = $this->get('avatar');
69
-        return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
-            ? (string) get_avatar_url($this->get('email'))
71
-            : $avatar;
72
-    }
63
+	/**
64
+	 * @return string
65
+	 */
66
+	protected function getAvatar()
67
+	{
68
+		$avatar = $this->get('avatar');
69
+		return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
+			? (string) get_avatar_url($this->get('email'))
71
+			: $avatar;
72
+	}
73 73
 
74
-    /**
75
-     * @return string
76
-     */
77
-    protected function getCategory()
78
-    {
79
-        $categories = Arr::convertStringToArray($this->get('category'));
80
-        return sanitize_key(Arr::get($categories, 0));
81
-    }
74
+	/**
75
+	 * @return string
76
+	 */
77
+	protected function getCategory()
78
+	{
79
+		$categories = Arr::convertStringToArray($this->get('category'));
80
+		return sanitize_key(Arr::get($categories, 0));
81
+	}
82 82
 
83
-    /**
84
-     * @return array
85
-     */
86
-    protected function getCustom()
87
-    {
88
-        $unset = [
89
-            '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token',
90
-            '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91
-            'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92
-        ];
93
-        $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
94
-        $custom = $this->request;
95
-        foreach ($unset as $value) {
96
-            unset($custom[$value]);
97
-        }
98
-        return $custom;
99
-    }
83
+	/**
84
+	 * @return array
85
+	 */
86
+	protected function getCustom()
87
+	{
88
+		$unset = [
89
+			'_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token',
90
+			'_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91
+			'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92
+		];
93
+		$unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
94
+		$custom = $this->request;
95
+		foreach ($unset as $value) {
96
+			unset($custom[$value]);
97
+		}
98
+		return $custom;
99
+	}
100 100
 
101
-    /**
102
-     * @param string $key
103
-     * @return string
104
-     */
105
-    protected function getDate($key)
106
-    {
107
-        $date = strtotime($this->get($key));
108
-        if (false === $date) {
109
-            $date = time();
110
-        }
111
-        return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
112
-    }
101
+	/**
102
+	 * @param string $key
103
+	 * @return string
104
+	 */
105
+	protected function getDate($key)
106
+	{
107
+		$date = strtotime($this->get($key));
108
+		if (false === $date) {
109
+			$date = time();
110
+		}
111
+		return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
112
+	}
113 113
 
114
-    /**
115
-     * @param string $key
116
-     * @return string
117
-     */
118
-    protected function getUser($key)
119
-    {
120
-        $value = $this->get($key);
121
-        if (empty($value)) {
122
-            $user = wp_get_current_user();
123
-            $userValues = [
124
-                'email' => 'user_email',
125
-                'name' => 'display_name',
126
-            ];
127
-            if ($user->exists() && array_key_exists($key, $userValues)) {
128
-                return $user->{$userValues[$key]};
129
-            }
130
-        }
131
-        return $value;
132
-    }
114
+	/**
115
+	 * @param string $key
116
+	 * @return string
117
+	 */
118
+	protected function getUser($key)
119
+	{
120
+		$value = $this->get($key);
121
+		if (empty($value)) {
122
+			$user = wp_get_current_user();
123
+			$userValues = [
124
+				'email' => 'user_email',
125
+				'name' => 'display_name',
126
+			];
127
+			if ($user->exists() && array_key_exists($key, $userValues)) {
128
+				return $user->{$userValues[$key]};
129
+			}
130
+		}
131
+		return $value;
132
+	}
133 133
 
134
-    /**
135
-     * @param string $key
136
-     * @return string
137
-     */
138
-    protected function getNumeric($key)
139
-    {
140
-        $value = $this->get($key);
141
-        return is_numeric($value)
142
-            ? $value
143
-            : '';
144
-    }
134
+	/**
135
+	 * @param string $key
136
+	 * @return string
137
+	 */
138
+	protected function getNumeric($key)
139
+	{
140
+		$value = $this->get($key);
141
+		return is_numeric($value)
142
+			? $value
143
+			: '';
144
+	}
145 145
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -27,37 +27,37 @@  discard block
 block discarded – undo
27 27
     public $title;
28 28
     public $url;
29 29
 
30
-    public function __construct($input)
30
+    public function __construct( $input )
31 31
     {
32 32
         $this->request = $input;
33 33
         $this->ajax_request = isset($input['_ajax_request']);
34
-        $this->assigned_to = $this->getNumeric('assign_to');
35
-        $this->author = sanitize_text_field($this->getUser('name'));
34
+        $this->assigned_to = $this->getNumeric( 'assign_to' );
35
+        $this->author = sanitize_text_field( $this->getUser( 'name' ) );
36 36
         $this->avatar = $this->getAvatar();
37 37
         $this->blacklisted = isset($input['blacklisted']);
38 38
         $this->category = $this->getCategory();
39
-        $this->content = sanitize_textarea_field($this->get('content'));
39
+        $this->content = sanitize_textarea_field( $this->get( 'content' ) );
40 40
         $this->custom = $this->getCustom();
41
-        $this->date = $this->getDate('date');
42
-        $this->email = sanitize_email($this->getUser('email'));
43
-        $this->form_id = sanitize_key($this->get('form_id'));
44
-        $this->ip_address = $this->get('ip_address');
45
-        $this->post_id = intval($this->get('_post_id'));
46
-        $this->rating = intval($this->get('rating'));
47
-        $this->referer = $this->get('_referer');
48
-        $this->response = sanitize_textarea_field($this->get('response'));
41
+        $this->date = $this->getDate( 'date' );
42
+        $this->email = sanitize_email( $this->getUser( 'email' ) );
43
+        $this->form_id = sanitize_key( $this->get( 'form_id' ) );
44
+        $this->ip_address = $this->get( 'ip_address' );
45
+        $this->post_id = intval( $this->get( '_post_id' ) );
46
+        $this->rating = intval( $this->get( 'rating' ) );
47
+        $this->referer = $this->get( '_referer' );
48
+        $this->response = sanitize_textarea_field( $this->get( 'response' ) );
49 49
         $this->terms = !empty($input['terms']);
50
-        $this->title = sanitize_text_field($this->get('title'));
51
-        $this->url = esc_url_raw($this->get('url'));
50
+        $this->title = sanitize_text_field( $this->get( 'title' ) );
51
+        $this->url = esc_url_raw( $this->get( 'url' ) );
52 52
     }
53 53
 
54 54
     /**
55 55
      * @param string $key
56 56
      * @return string
57 57
      */
58
-    protected function get($key)
58
+    protected function get( $key )
59 59
     {
60
-        return (string) Arr::get($this->request, $key);
60
+        return (string)Arr::get( $this->request, $key );
61 61
     }
62 62
 
63 63
     /**
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
      */
66 66
     protected function getAvatar()
67 67
     {
68
-        $avatar = $this->get('avatar');
69
-        return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
-            ? (string) get_avatar_url($this->get('email'))
68
+        $avatar = $this->get( 'avatar' );
69
+        return !filter_var( $avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED )
70
+            ? (string)get_avatar_url( $this->get( 'email' ) )
71 71
             : $avatar;
72 72
     }
73 73
 
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
      */
77 77
     protected function getCategory()
78 78
     {
79
-        $categories = Arr::convertStringToArray($this->get('category'));
80
-        return sanitize_key(Arr::get($categories, 0));
79
+        $categories = Arr::convertStringToArray( $this->get( 'category' ) );
80
+        return sanitize_key( Arr::get( $categories, 0 ) );
81 81
     }
82 82
 
83 83
     /**
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
             '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91 91
             'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92 92
         ];
93
-        $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
93
+        $unset = apply_filters( 'site-reviews/create/unset-keys-from-custom', $unset );
94 94
         $custom = $this->request;
95
-        foreach ($unset as $value) {
95
+        foreach( $unset as $value ) {
96 96
             unset($custom[$value]);
97 97
         }
98 98
         return $custom;
@@ -102,29 +102,29 @@  discard block
 block discarded – undo
102 102
      * @param string $key
103 103
      * @return string
104 104
      */
105
-    protected function getDate($key)
105
+    protected function getDate( $key )
106 106
     {
107
-        $date = strtotime($this->get($key));
108
-        if (false === $date) {
107
+        $date = strtotime( $this->get( $key ) );
108
+        if( false === $date ) {
109 109
             $date = time();
110 110
         }
111
-        return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
111
+        return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date ) );
112 112
     }
113 113
 
114 114
     /**
115 115
      * @param string $key
116 116
      * @return string
117 117
      */
118
-    protected function getUser($key)
118
+    protected function getUser( $key )
119 119
     {
120
-        $value = $this->get($key);
121
-        if (empty($value)) {
120
+        $value = $this->get( $key );
121
+        if( empty($value) ) {
122 122
             $user = wp_get_current_user();
123 123
             $userValues = [
124 124
                 'email' => 'user_email',
125 125
                 'name' => 'display_name',
126 126
             ];
127
-            if ($user->exists() && array_key_exists($key, $userValues)) {
127
+            if( $user->exists() && array_key_exists( $key, $userValues ) ) {
128 128
                 return $user->{$userValues[$key]};
129 129
             }
130 130
         }
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
      * @param string $key
136 136
      * @return string
137 137
      */
138
-    protected function getNumeric($key)
138
+    protected function getNumeric( $key )
139 139
     {
140
-        $value = $this->get($key);
141
-        return is_numeric($value)
140
+        $value = $this->get( $key );
141
+        return is_numeric( $value )
142 142
             ? $value
143 143
             : '';
144 144
     }
Please login to merge, or discard this patch.
plugin/Router.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -7,162 +7,162 @@
 block discarded – undo
7 7
 
8 8
 class Router
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    protected $unguardedActions = [];
10
+	/**
11
+	 * @var array
12
+	 */
13
+	protected $unguardedActions = [];
14 14
 
15
-    public function __construct()
16
-    {
17
-        $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [
18
-            'dismiss-notice',
19
-            'fetch-paged-reviews',
20
-        ]);
21
-    }
15
+	public function __construct()
16
+	{
17
+		$this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [
18
+			'dismiss-notice',
19
+			'fetch-paged-reviews',
20
+		]);
21
+	}
22 22
 
23
-    /**
24
-     * @return void
25
-     */
26
-    public function routeAdminPostRequest()
27
-    {
28
-        $request = $this->getRequest();
29
-        if (!$this->isValidPostRequest($request)) {
30
-            return;
31
-        }
32
-        check_admin_referer($request['_action']);
33
-        $this->routeRequest('admin', $request['_action'], $request);
34
-    }
23
+	/**
24
+	 * @return void
25
+	 */
26
+	public function routeAdminPostRequest()
27
+	{
28
+		$request = $this->getRequest();
29
+		if (!$this->isValidPostRequest($request)) {
30
+			return;
31
+		}
32
+		check_admin_referer($request['_action']);
33
+		$this->routeRequest('admin', $request['_action'], $request);
34
+	}
35 35
 
36
-    /**
37
-     * @return void
38
-     */
39
-    public function routeAjaxRequest()
40
-    {
41
-        $request = $this->getRequest();
42
-        $this->checkAjaxRequest($request);
43
-        $this->checkAjaxNonce($request);
44
-        $this->routeRequest('ajax', $request['_action'], $request);
45
-        wp_die();
46
-    }
36
+	/**
37
+	 * @return void
38
+	 */
39
+	public function routeAjaxRequest()
40
+	{
41
+		$request = $this->getRequest();
42
+		$this->checkAjaxRequest($request);
43
+		$this->checkAjaxNonce($request);
44
+		$this->routeRequest('ajax', $request['_action'], $request);
45
+		wp_die();
46
+	}
47 47
 
48
-    /**
49
-     * @return void
50
-     */
51
-    public function routePublicPostRequest()
52
-    {
53
-        if (is_admin()) {
54
-            return;
55
-        }
56
-        $request = $this->getRequest();
57
-        if (!$this->isValidPostRequest($request)) {
58
-            return;
59
-        }
60
-        if (!$this->isValidPublicNonce($request)) {
61
-            return;
62
-        }
63
-        $this->routeRequest('public', $request['_action'], $request);
64
-    }
48
+	/**
49
+	 * @return void
50
+	 */
51
+	public function routePublicPostRequest()
52
+	{
53
+		if (is_admin()) {
54
+			return;
55
+		}
56
+		$request = $this->getRequest();
57
+		if (!$this->isValidPostRequest($request)) {
58
+			return;
59
+		}
60
+		if (!$this->isValidPublicNonce($request)) {
61
+			return;
62
+		}
63
+		$this->routeRequest('public', $request['_action'], $request);
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    protected function checkAjaxNonce(array $request)
70
-    {
71
-        if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) {
72
-            return;
73
-        }
74
-        if (!isset($request['_nonce'])) {
75
-            $this->sendAjaxError('request is missing a nonce', $request);
76
-        }
77
-        if (!wp_verify_nonce($request['_nonce'], $request['_action'])) {
78
-            $this->sendAjaxError('request failed the nonce check', $request, 403);
79
-        }
80
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	protected function checkAjaxNonce(array $request)
70
+	{
71
+		if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) {
72
+			return;
73
+		}
74
+		if (!isset($request['_nonce'])) {
75
+			$this->sendAjaxError('request is missing a nonce', $request);
76
+		}
77
+		if (!wp_verify_nonce($request['_nonce'], $request['_action'])) {
78
+			$this->sendAjaxError('request failed the nonce check', $request, 403);
79
+		}
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     */
85
-    protected function checkAjaxRequest(array $request)
86
-    {
87
-        if (!isset($request['_action'])) {
88
-            $this->sendAjaxError('request must include an action', $request);
89
-        }
90
-        if (empty($request['_ajax_request'])) {
91
-            $this->sendAjaxError('request is invalid', $request);
92
-        }
93
-    }
82
+	/**
83
+	 * @return void
84
+	 */
85
+	protected function checkAjaxRequest(array $request)
86
+	{
87
+		if (!isset($request['_action'])) {
88
+			$this->sendAjaxError('request must include an action', $request);
89
+		}
90
+		if (empty($request['_ajax_request'])) {
91
+			$this->sendAjaxError('request is invalid', $request);
92
+		}
93
+	}
94 94
 
95
-    /**
96
-     * All ajax requests in the plugin are triggered by a single action hook: glsr_action,
97
-     * while each ajax route is determined by $_POST[request][_action].
98
-     * @return array
99
-     */
100
-    protected function getRequest()
101
-    {
102
-        $request = Helper::filterInputArray(Application::ID);
103
-        if (Helper::filterInput('action') == Application::PREFIX.'action') {
104
-            $request['_ajax_request'] = true;
105
-        }
106
-        if ('submit-review' == Helper::filterInput('_action', $request)) {
107
-            $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response');
108
-        }
109
-        return $request;
110
-    }
95
+	/**
96
+	 * All ajax requests in the plugin are triggered by a single action hook: glsr_action,
97
+	 * while each ajax route is determined by $_POST[request][_action].
98
+	 * @return array
99
+	 */
100
+	protected function getRequest()
101
+	{
102
+		$request = Helper::filterInputArray(Application::ID);
103
+		if (Helper::filterInput('action') == Application::PREFIX.'action') {
104
+			$request['_ajax_request'] = true;
105
+		}
106
+		if ('submit-review' == Helper::filterInput('_action', $request)) {
107
+			$request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response');
108
+		}
109
+		return $request;
110
+	}
111 111
 
112
-    /**
113
-     * @return bool
114
-     */
115
-    protected function isValidPostRequest(array $request = [])
116
-    {
117
-        return !empty($request['_action']) && empty($request['_ajax_request']);
118
-    }
112
+	/**
113
+	 * @return bool
114
+	 */
115
+	protected function isValidPostRequest(array $request = [])
116
+	{
117
+		return !empty($request['_action']) && empty($request['_ajax_request']);
118
+	}
119 119
 
120
-    /**
121
-     * @return bool
122
-     */
123
-    protected function isValidPublicNonce(array $request)
124
-    {
125
-        if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) {
126
-            glsr_log()->error('nonce check failed for public request')->debug($request);
127
-            return false;
128
-        }
129
-        return true;
130
-    }
120
+	/**
121
+	 * @return bool
122
+	 */
123
+	protected function isValidPublicNonce(array $request)
124
+	{
125
+		if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) {
126
+			glsr_log()->error('nonce check failed for public request')->debug($request);
127
+			return false;
128
+		}
129
+		return true;
130
+	}
131 131
 
132
-    /**
133
-     * @param string $type
134
-     * @param string $action
135
-     * @return void
136
-     */
137
-    protected function routeRequest($type, $action, array $request = [])
138
-    {
139
-        $actionHook = 'site-reviews/route/'.$type.'/request';
140
-        $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers'));
141
-        $method = Helper::buildMethodName($action, 'router');
142
-        $request = apply_filters('site-reviews/route/request', $request, $action, $type);
143
-        do_action($actionHook, $action, $request);
144
-        if (is_callable([$controller, $method])) {
145
-            call_user_func([$controller, $method], $request);
146
-            return;
147
-        }
148
-        if (0 === did_action($actionHook)) {
149
-            glsr_log('Unknown '.$type.' router request: '.$action);
150
-        }
151
-    }
132
+	/**
133
+	 * @param string $type
134
+	 * @param string $action
135
+	 * @return void
136
+	 */
137
+	protected function routeRequest($type, $action, array $request = [])
138
+	{
139
+		$actionHook = 'site-reviews/route/'.$type.'/request';
140
+		$controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers'));
141
+		$method = Helper::buildMethodName($action, 'router');
142
+		$request = apply_filters('site-reviews/route/request', $request, $action, $type);
143
+		do_action($actionHook, $action, $request);
144
+		if (is_callable([$controller, $method])) {
145
+			call_user_func([$controller, $method], $request);
146
+			return;
147
+		}
148
+		if (0 === did_action($actionHook)) {
149
+			glsr_log('Unknown '.$type.' router request: '.$action);
150
+		}
151
+	}
152 152
 
153
-    /**
154
-     * @param string $error
155
-     * @param int $statusCode
156
-     * @return void
157
-     */
158
-    protected function sendAjaxError($error, array $request, $statusCode = 400)
159
-    {
160
-        glsr_log()->error($error)->debug($request);
161
-        glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>');
162
-        wp_send_json_error([
163
-            'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'),
164
-            'notices' => glsr(Notice::class)->get(),
165
-            'error' => $error,
166
-        ]);
167
-    }
153
+	/**
154
+	 * @param string $error
155
+	 * @param int $statusCode
156
+	 * @return void
157
+	 */
158
+	protected function sendAjaxError($error, array $request, $statusCode = 400)
159
+	{
160
+		glsr_log()->error($error)->debug($request);
161
+		glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>');
162
+		wp_send_json_error([
163
+			'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'),
164
+			'notices' => glsr(Notice::class)->get(),
165
+			'error' => $error,
166
+		]);
167
+	}
168 168
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
 
15 15
     public function __construct()
16 16
     {
17
-        $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [
17
+        $this->unguardedActions = apply_filters( 'site-reviews/router/unguarded-actions', [
18 18
             'dismiss-notice',
19 19
             'fetch-paged-reviews',
20
-        ]);
20
+        ] );
21 21
     }
22 22
 
23 23
     /**
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
     public function routeAdminPostRequest()
27 27
     {
28 28
         $request = $this->getRequest();
29
-        if (!$this->isValidPostRequest($request)) {
29
+        if( !$this->isValidPostRequest( $request ) ) {
30 30
             return;
31 31
         }
32
-        check_admin_referer($request['_action']);
33
-        $this->routeRequest('admin', $request['_action'], $request);
32
+        check_admin_referer( $request['_action'] );
33
+        $this->routeRequest( 'admin', $request['_action'], $request );
34 34
     }
35 35
 
36 36
     /**
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
     public function routeAjaxRequest()
40 40
     {
41 41
         $request = $this->getRequest();
42
-        $this->checkAjaxRequest($request);
43
-        $this->checkAjaxNonce($request);
44
-        $this->routeRequest('ajax', $request['_action'], $request);
42
+        $this->checkAjaxRequest( $request );
43
+        $this->checkAjaxNonce( $request );
44
+        $this->routeRequest( 'ajax', $request['_action'], $request );
45 45
         wp_die();
46 46
     }
47 47
 
@@ -50,45 +50,45 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function routePublicPostRequest()
52 52
     {
53
-        if (is_admin()) {
53
+        if( is_admin() ) {
54 54
             return;
55 55
         }
56 56
         $request = $this->getRequest();
57
-        if (!$this->isValidPostRequest($request)) {
57
+        if( !$this->isValidPostRequest( $request ) ) {
58 58
             return;
59 59
         }
60
-        if (!$this->isValidPublicNonce($request)) {
60
+        if( !$this->isValidPublicNonce( $request ) ) {
61 61
             return;
62 62
         }
63
-        $this->routeRequest('public', $request['_action'], $request);
63
+        $this->routeRequest( 'public', $request['_action'], $request );
64 64
     }
65 65
 
66 66
     /**
67 67
      * @return void
68 68
      */
69
-    protected function checkAjaxNonce(array $request)
69
+    protected function checkAjaxNonce( array $request )
70 70
     {
71
-        if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) {
71
+        if( !is_user_logged_in() || in_array( Arr::get( $request, '_action' ), $this->unguardedActions ) ) {
72 72
             return;
73 73
         }
74
-        if (!isset($request['_nonce'])) {
75
-            $this->sendAjaxError('request is missing a nonce', $request);
74
+        if( !isset($request['_nonce']) ) {
75
+            $this->sendAjaxError( 'request is missing a nonce', $request );
76 76
         }
77
-        if (!wp_verify_nonce($request['_nonce'], $request['_action'])) {
78
-            $this->sendAjaxError('request failed the nonce check', $request, 403);
77
+        if( !wp_verify_nonce( $request['_nonce'], $request['_action'] ) ) {
78
+            $this->sendAjaxError( 'request failed the nonce check', $request, 403 );
79 79
         }
80 80
     }
81 81
 
82 82
     /**
83 83
      * @return void
84 84
      */
85
-    protected function checkAjaxRequest(array $request)
85
+    protected function checkAjaxRequest( array $request )
86 86
     {
87
-        if (!isset($request['_action'])) {
88
-            $this->sendAjaxError('request must include an action', $request);
87
+        if( !isset($request['_action']) ) {
88
+            $this->sendAjaxError( 'request must include an action', $request );
89 89
         }
90
-        if (empty($request['_ajax_request'])) {
91
-            $this->sendAjaxError('request is invalid', $request);
90
+        if( empty($request['_ajax_request']) ) {
91
+            $this->sendAjaxError( 'request is invalid', $request );
92 92
         }
93 93
     }
94 94
 
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
      */
100 100
     protected function getRequest()
101 101
     {
102
-        $request = Helper::filterInputArray(Application::ID);
103
-        if (Helper::filterInput('action') == Application::PREFIX.'action') {
102
+        $request = Helper::filterInputArray( Application::ID );
103
+        if( Helper::filterInput( 'action' ) == Application::PREFIX.'action' ) {
104 104
             $request['_ajax_request'] = true;
105 105
         }
106
-        if ('submit-review' == Helper::filterInput('_action', $request)) {
107
-            $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response');
106
+        if( 'submit-review' == Helper::filterInput( '_action', $request ) ) {
107
+            $request['_recaptcha-token'] = Helper::filterInput( 'g-recaptcha-response' );
108 108
         }
109 109
         return $request;
110 110
     }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return bool
114 114
      */
115
-    protected function isValidPostRequest(array $request = [])
115
+    protected function isValidPostRequest( array $request = [] )
116 116
     {
117 117
         return !empty($request['_action']) && empty($request['_ajax_request']);
118 118
     }
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
     /**
121 121
      * @return bool
122 122
      */
123
-    protected function isValidPublicNonce(array $request)
123
+    protected function isValidPublicNonce( array $request )
124 124
     {
125
-        if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) {
126
-            glsr_log()->error('nonce check failed for public request')->debug($request);
125
+        if( is_user_logged_in() && !wp_verify_nonce( $request['_nonce'], $request['_action'] ) ) {
126
+            glsr_log()->error( 'nonce check failed for public request' )->debug( $request );
127 127
             return false;
128 128
         }
129 129
         return true;
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
      * @param string $action
135 135
      * @return void
136 136
      */
137
-    protected function routeRequest($type, $action, array $request = [])
137
+    protected function routeRequest( $type, $action, array $request = [] )
138 138
     {
139 139
         $actionHook = 'site-reviews/route/'.$type.'/request';
140
-        $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers'));
141
-        $method = Helper::buildMethodName($action, 'router');
142
-        $request = apply_filters('site-reviews/route/request', $request, $action, $type);
143
-        do_action($actionHook, $action, $request);
144
-        if (is_callable([$controller, $method])) {
145
-            call_user_func([$controller, $method], $request);
140
+        $controller = glsr( Helper::buildClassName( $type.'-controller', 'Controllers' ) );
141
+        $method = Helper::buildMethodName( $action, 'router' );
142
+        $request = apply_filters( 'site-reviews/route/request', $request, $action, $type );
143
+        do_action( $actionHook, $action, $request );
144
+        if( is_callable( [$controller, $method] ) ) {
145
+            call_user_func( [$controller, $method], $request );
146 146
             return;
147 147
         }
148
-        if (0 === did_action($actionHook)) {
149
-            glsr_log('Unknown '.$type.' router request: '.$action);
148
+        if( 0 === did_action( $actionHook ) ) {
149
+            glsr_log( 'Unknown '.$type.' router request: '.$action );
150 150
         }
151 151
     }
152 152
 
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
      * @param int $statusCode
156 156
      * @return void
157 157
      */
158
-    protected function sendAjaxError($error, array $request, $statusCode = 400)
158
+    protected function sendAjaxError( $error, array $request, $statusCode = 400 )
159 159
     {
160
-        glsr_log()->error($error)->debug($request);
161
-        glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>');
162
-        wp_send_json_error([
163
-            'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'),
164
-            'notices' => glsr(Notice::class)->get(),
160
+        glsr_log()->error( $error )->debug( $request );
161
+        glsr( Notice::class )->addError( __( 'There was an error (try reloading the page).', 'site-reviews' ).' <code>'.$error.'</code>' );
162
+        wp_send_json_error( [
163
+            'message' => __( 'The form could not be submitted. Please notify the site administrator.', 'site-reviews' ),
164
+            'notices' => glsr( Notice::class )->get(),
165 165
             'error' => $error,
166
-        ]);
166
+        ] );
167 167
     }
168 168
 }
Please login to merge, or discard this patch.
plugin/Controllers/RebusifyController.php 3 patches
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,8 @@  discard block
 block discarded – undo
51 51
         }
52 52
         if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) {
53 53
             $button = $this->buildUpgradeButton();
54
-        } else {
54
+        }
55
+        else {
55 56
             $button = $this->buildCreateButton();
56 57
         }
57 58
         $context['field'].= $button;
@@ -229,7 +230,8 @@  discard block
 block discarded – undo
229 230
         );
230 231
         if ($rebusify->success) {
231 232
             update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype'));
232
-        } else {
233
+        }
234
+        else {
233 235
             delete_option($this->rebusifyKey);
234 236
             $settings = Arr::set($settings, $this->enabledKey, 'no');
235 237
             glsr(Notice::class)->addError(sprintf(
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -12,231 +12,231 @@
 block discarded – undo
12 12
 
13 13
 class RebusifyController extends Controller
14 14
 {
15
-    protected $apiKey = 'settings.general.rebusify_serial';
16
-    protected $emailKey = 'settings.general.rebusify_email';
17
-    protected $enabledKey = 'settings.general.rebusify';
18
-    protected $rebusifyKey = '_glsr_rebusify';
19
-
20
-    /**
21
-     * @return array
22
-     * @filter site-reviews/settings/callback
23
-     */
24
-    public function filterSettingsCallback(array $settings)
25
-    {
26
-        if ('yes' !== Arr::get($settings, $this->enabledKey)) {
27
-            return $settings;
28
-        }
29
-        $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
-        $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
-        $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false);
32
-        if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
-            $settings = $this->sanitizeRebusifySettings($settings);
34
-        }
35
-        return $settings;
36
-    }
37
-
38
-    /**
39
-     * @param string $template
40
-     * @return array
41
-     * @filter site-reviews/interpolate/partials/form/table-row-multiple
42
-     */
43
-    public function filterSettingsTableRow(array $context, $template, array $data)
44
-    {
45
-        if ($this->enabledKey !== Arr::get($data, 'field.path')) {
46
-            return $context;
47
-        }
48
-        $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey);
49
-        if ('P' === $rebusifyProductType) {
50
-            return $context;
51
-        }
52
-        if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) {
53
-            $button = $this->buildUpgradeButton();
54
-        } else {
55
-            $button = $this->buildCreateButton();
56
-        }
57
-        $context['field'].= $button;
58
-        return $context;
59
-    }
60
-
61
-    /**
62
-     * Triggered when a review is created.
63
-     * @return void
64
-     * @action site-reviews/review/created
65
-     */
66
-    public function onCreated(Review $review)
67
-    {
68
-        if (!$this->canPostReview($review)) {
69
-            return;
70
-        }
71
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
72
-        if ($rebusify->success) {
73
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
74
-        }
75
-    }
76
-
77
-    /**
78
-     * Triggered when a review is reverted to its original title/content/date_timestamp.
79
-     * @return void
80
-     * @action site-reviews/review/reverted
81
-     */
82
-    public function onReverted(Review $review)
83
-    {
84
-        if (!$this->canPostReview($review)) {
85
-            return;
86
-        }
87
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
88
-        if ($rebusify->success) {
89
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
90
-        }
91
-    }
92
-
93
-    /**
94
-     * Triggered when an existing review is updated.
95
-     * @return void
96
-     * @action site-reviews/review/saved
97
-     */
98
-    public function onSaved(Review $review)
99
-    {
100
-        if (!$this->canPostReview($review)) {
101
-            return;
102
-        }
103
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
104
-        if ($rebusify->success) {
105
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
106
-        }
107
-    }
108
-
109
-    /**
110
-     * Triggered when a review's response is added or updated.
111
-     * @param int $metaId
112
-     * @param int $postId
113
-     * @param string $metaKey
114
-     * @return void
115
-     * @action updated_postmeta
116
-     */
117
-    public function onUpdatedMeta($metaId, $postId, $metaKey)
118
-    {
119
-        $review = glsr_get_review($postId);
120
-        if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
121
-            return;
122
-        }
123
-        $rebusify = glsr(Rebusify::class)->sendReviewResponse($review);
124
-        if ($rebusify->success) {
125
-            glsr(Database::class)->set($review->ID, 'rebusify_response', true);
126
-        }
127
-    }
128
-
129
-    /**
130
-     * @return string
131
-     */
132
-    protected function buildCreateButton()
133
-    {
134
-        return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [
135
-            'class' => 'button',
136
-            'href' => Rebusify::WEB_URL,
137
-            'target' => '_blank',
138
-        ]);
139
-    }
140
-
141
-    /**
142
-     * @return string
143
-     */
144
-    protected function buildUpgradeButton()
145
-    {
146
-        $build = glsr(Builder::class);
147
-        $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews'));
148
-        $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [
149
-            'class' => 'button',
150
-            'href' => Rebusify::WEB_URL,
151
-            'target' => '_blank',
152
-        ]);
153
-        return $build->div($notice.$button, [
154
-            'class' => 'glsr-notice-inline notice inline notice-info',
155
-        ]);
156
-    }
157
-
158
-    /**
159
-     * @return bool
160
-     */
161
-    protected function canPostResponse(Review $review)
162
-    {
163
-        $requiredValues = [
164
-            glsr(Database::class)->get($review->ID, 'rebusify'),
165
-            $review->response,
166
-            $review->review_id,
167
-        ];
168
-        return $this->canProceed($review, 'rebusify_response')
169
-            && 'publish' === $review->status
170
-            && 3 === count(array_filter($requiredValues));
171
-    }
172
-
173
-    /**
174
-     * @return bool
175
-     */
176
-    protected function canPostReview(Review $review)
177
-    {
178
-        $requiredValues = [
179
-            $review->author,
180
-            $review->content,
181
-            $review->rating,
182
-            $review->review_id,
183
-            $review->title,
184
-        ];
185
-        return $this->canProceed($review)
186
-            && 'publish' === $review->status
187
-            && 5 === count(array_filter($requiredValues));
188
-    }
189
-
190
-    /**
191
-     * @param string $metaKey
192
-     * @return bool
193
-     */
194
-    protected function canProceed(Review $review, $metaKey = 'rebusify')
195
-    {
196
-        return glsr(OptionManager::class)->getBool($this->enabledKey)
197
-            && $this->isReviewPostId($review->ID)
198
-            && !$this->hasMetaKey($review, $metaKey);
199
-    }
200
-
201
-    /**
202
-     * @param string $metaKey
203
-     * @return bool
204
-     */
205
-    protected function hasMetaKey(Review $review, $metaKey = 'rebusify')
206
-    {
207
-        return '' !== glsr(Database::class)->get($review->ID, $metaKey);
208
-    }
209
-
210
-    /**
211
-     * @param string $key
212
-     * @return bool
213
-     */
214
-    protected function isEmptyOrModified($key, array $settings)
215
-    {
216
-        $oldValue = glsr_get_option($key);
217
-        $newValue = Arr::get($settings, $key);
218
-        return empty($newValue) || $newValue !== $oldValue;
219
-    }
220
-
221
-    /**
222
-     * @return array
223
-     */
224
-    protected function sanitizeRebusifySettings(array $settings)
225
-    {
226
-        $rebusify = glsr(Rebusify::class)->activateKey(
227
-            Arr::get($settings, $this->apiKey),
228
-            Arr::get($settings, $this->emailKey)
229
-        );
230
-        if ($rebusify->success) {
231
-            update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype'));
232
-        } else {
233
-            delete_option($this->rebusifyKey);
234
-            $settings = Arr::set($settings, $this->enabledKey, 'no');
235
-            glsr(Notice::class)->addError(sprintf(
236
-                __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'),
237
-                '('.$rebusify->message.')'
238
-            ));
239
-        }
240
-        return $settings;
241
-    }
15
+	protected $apiKey = 'settings.general.rebusify_serial';
16
+	protected $emailKey = 'settings.general.rebusify_email';
17
+	protected $enabledKey = 'settings.general.rebusify';
18
+	protected $rebusifyKey = '_glsr_rebusify';
19
+
20
+	/**
21
+	 * @return array
22
+	 * @filter site-reviews/settings/callback
23
+	 */
24
+	public function filterSettingsCallback(array $settings)
25
+	{
26
+		if ('yes' !== Arr::get($settings, $this->enabledKey)) {
27
+			return $settings;
28
+		}
29
+		$isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
+		$isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
+		$isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false);
32
+		if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
+			$settings = $this->sanitizeRebusifySettings($settings);
34
+		}
35
+		return $settings;
36
+	}
37
+
38
+	/**
39
+	 * @param string $template
40
+	 * @return array
41
+	 * @filter site-reviews/interpolate/partials/form/table-row-multiple
42
+	 */
43
+	public function filterSettingsTableRow(array $context, $template, array $data)
44
+	{
45
+		if ($this->enabledKey !== Arr::get($data, 'field.path')) {
46
+			return $context;
47
+		}
48
+		$rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey);
49
+		if ('P' === $rebusifyProductType) {
50
+			return $context;
51
+		}
52
+		if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) {
53
+			$button = $this->buildUpgradeButton();
54
+		} else {
55
+			$button = $this->buildCreateButton();
56
+		}
57
+		$context['field'].= $button;
58
+		return $context;
59
+	}
60
+
61
+	/**
62
+	 * Triggered when a review is created.
63
+	 * @return void
64
+	 * @action site-reviews/review/created
65
+	 */
66
+	public function onCreated(Review $review)
67
+	{
68
+		if (!$this->canPostReview($review)) {
69
+			return;
70
+		}
71
+		$rebusify = glsr(Rebusify::class)->sendReview($review);
72
+		if ($rebusify->success) {
73
+			glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
74
+		}
75
+	}
76
+
77
+	/**
78
+	 * Triggered when a review is reverted to its original title/content/date_timestamp.
79
+	 * @return void
80
+	 * @action site-reviews/review/reverted
81
+	 */
82
+	public function onReverted(Review $review)
83
+	{
84
+		if (!$this->canPostReview($review)) {
85
+			return;
86
+		}
87
+		$rebusify = glsr(Rebusify::class)->sendReview($review);
88
+		if ($rebusify->success) {
89
+			glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
90
+		}
91
+	}
92
+
93
+	/**
94
+	 * Triggered when an existing review is updated.
95
+	 * @return void
96
+	 * @action site-reviews/review/saved
97
+	 */
98
+	public function onSaved(Review $review)
99
+	{
100
+		if (!$this->canPostReview($review)) {
101
+			return;
102
+		}
103
+		$rebusify = glsr(Rebusify::class)->sendReview($review);
104
+		if ($rebusify->success) {
105
+			glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
106
+		}
107
+	}
108
+
109
+	/**
110
+	 * Triggered when a review's response is added or updated.
111
+	 * @param int $metaId
112
+	 * @param int $postId
113
+	 * @param string $metaKey
114
+	 * @return void
115
+	 * @action updated_postmeta
116
+	 */
117
+	public function onUpdatedMeta($metaId, $postId, $metaKey)
118
+	{
119
+		$review = glsr_get_review($postId);
120
+		if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
121
+			return;
122
+		}
123
+		$rebusify = glsr(Rebusify::class)->sendReviewResponse($review);
124
+		if ($rebusify->success) {
125
+			glsr(Database::class)->set($review->ID, 'rebusify_response', true);
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * @return string
131
+	 */
132
+	protected function buildCreateButton()
133
+	{
134
+		return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [
135
+			'class' => 'button',
136
+			'href' => Rebusify::WEB_URL,
137
+			'target' => '_blank',
138
+		]);
139
+	}
140
+
141
+	/**
142
+	 * @return string
143
+	 */
144
+	protected function buildUpgradeButton()
145
+	{
146
+		$build = glsr(Builder::class);
147
+		$notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews'));
148
+		$button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [
149
+			'class' => 'button',
150
+			'href' => Rebusify::WEB_URL,
151
+			'target' => '_blank',
152
+		]);
153
+		return $build->div($notice.$button, [
154
+			'class' => 'glsr-notice-inline notice inline notice-info',
155
+		]);
156
+	}
157
+
158
+	/**
159
+	 * @return bool
160
+	 */
161
+	protected function canPostResponse(Review $review)
162
+	{
163
+		$requiredValues = [
164
+			glsr(Database::class)->get($review->ID, 'rebusify'),
165
+			$review->response,
166
+			$review->review_id,
167
+		];
168
+		return $this->canProceed($review, 'rebusify_response')
169
+			&& 'publish' === $review->status
170
+			&& 3 === count(array_filter($requiredValues));
171
+	}
172
+
173
+	/**
174
+	 * @return bool
175
+	 */
176
+	protected function canPostReview(Review $review)
177
+	{
178
+		$requiredValues = [
179
+			$review->author,
180
+			$review->content,
181
+			$review->rating,
182
+			$review->review_id,
183
+			$review->title,
184
+		];
185
+		return $this->canProceed($review)
186
+			&& 'publish' === $review->status
187
+			&& 5 === count(array_filter($requiredValues));
188
+	}
189
+
190
+	/**
191
+	 * @param string $metaKey
192
+	 * @return bool
193
+	 */
194
+	protected function canProceed(Review $review, $metaKey = 'rebusify')
195
+	{
196
+		return glsr(OptionManager::class)->getBool($this->enabledKey)
197
+			&& $this->isReviewPostId($review->ID)
198
+			&& !$this->hasMetaKey($review, $metaKey);
199
+	}
200
+
201
+	/**
202
+	 * @param string $metaKey
203
+	 * @return bool
204
+	 */
205
+	protected function hasMetaKey(Review $review, $metaKey = 'rebusify')
206
+	{
207
+		return '' !== glsr(Database::class)->get($review->ID, $metaKey);
208
+	}
209
+
210
+	/**
211
+	 * @param string $key
212
+	 * @return bool
213
+	 */
214
+	protected function isEmptyOrModified($key, array $settings)
215
+	{
216
+		$oldValue = glsr_get_option($key);
217
+		$newValue = Arr::get($settings, $key);
218
+		return empty($newValue) || $newValue !== $oldValue;
219
+	}
220
+
221
+	/**
222
+	 * @return array
223
+	 */
224
+	protected function sanitizeRebusifySettings(array $settings)
225
+	{
226
+		$rebusify = glsr(Rebusify::class)->activateKey(
227
+			Arr::get($settings, $this->apiKey),
228
+			Arr::get($settings, $this->emailKey)
229
+		);
230
+		if ($rebusify->success) {
231
+			update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype'));
232
+		} else {
233
+			delete_option($this->rebusifyKey);
234
+			$settings = Arr::set($settings, $this->enabledKey, 'no');
235
+			glsr(Notice::class)->addError(sprintf(
236
+				__('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'),
237
+				'('.$rebusify->message.')'
238
+			));
239
+		}
240
+		return $settings;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
      * @return array
22 22
      * @filter site-reviews/settings/callback
23 23
      */
24
-    public function filterSettingsCallback(array $settings)
24
+    public function filterSettingsCallback( array $settings )
25 25
     {
26
-        if ('yes' !== Arr::get($settings, $this->enabledKey)) {
26
+        if( 'yes' !== Arr::get( $settings, $this->enabledKey ) ) {
27 27
             return $settings;
28 28
         }
29
-        $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
-        $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
-        $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false);
32
-        if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
-            $settings = $this->sanitizeRebusifySettings($settings);
29
+        $isApiKeyModified = $this->isEmptyOrModified( $this->apiKey, $settings );
30
+        $isEmailModified = $this->isEmptyOrModified( $this->emailKey, $settings );
31
+        $isAccountVerified = glsr( OptionManager::class )->getWP( $this->rebusifyKey, false );
32
+        if( !$isAccountVerified || $isApiKeyModified || $isEmailModified ) {
33
+            $settings = $this->sanitizeRebusifySettings( $settings );
34 34
         }
35 35
         return $settings;
36 36
     }
@@ -40,21 +40,21 @@  discard block
 block discarded – undo
40 40
      * @return array
41 41
      * @filter site-reviews/interpolate/partials/form/table-row-multiple
42 42
      */
43
-    public function filterSettingsTableRow(array $context, $template, array $data)
43
+    public function filterSettingsTableRow( array $context, $template, array $data )
44 44
     {
45
-        if ($this->enabledKey !== Arr::get($data, 'field.path')) {
45
+        if( $this->enabledKey !== Arr::get( $data, 'field.path' ) ) {
46 46
             return $context;
47 47
         }
48
-        $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey);
49
-        if ('P' === $rebusifyProductType) {
48
+        $rebusifyProductType = glsr( OptionManager::class )->getWP( $this->rebusifyKey );
49
+        if( 'P' === $rebusifyProductType ) {
50 50
             return $context;
51 51
         }
52
-        if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) {
52
+        if( 'F' === $rebusifyProductType && 'yes' === glsr_get_option( 'general.rebusify' ) ) {
53 53
             $button = $this->buildUpgradeButton();
54 54
         } else {
55 55
             $button = $this->buildCreateButton();
56 56
         }
57
-        $context['field'].= $button;
57
+        $context['field'] .= $button;
58 58
         return $context;
59 59
     }
60 60
 
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
      * @return void
64 64
      * @action site-reviews/review/created
65 65
      */
66
-    public function onCreated(Review $review)
66
+    public function onCreated( Review $review )
67 67
     {
68
-        if (!$this->canPostReview($review)) {
68
+        if( !$this->canPostReview( $review ) ) {
69 69
             return;
70 70
         }
71
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
72
-        if ($rebusify->success) {
73
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
71
+        $rebusify = glsr( Rebusify::class )->sendReview( $review );
72
+        if( $rebusify->success ) {
73
+            glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id );
74 74
         }
75 75
     }
76 76
 
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
      * @return void
80 80
      * @action site-reviews/review/reverted
81 81
      */
82
-    public function onReverted(Review $review)
82
+    public function onReverted( Review $review )
83 83
     {
84
-        if (!$this->canPostReview($review)) {
84
+        if( !$this->canPostReview( $review ) ) {
85 85
             return;
86 86
         }
87
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
88
-        if ($rebusify->success) {
89
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
87
+        $rebusify = glsr( Rebusify::class )->sendReview( $review );
88
+        if( $rebusify->success ) {
89
+            glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id );
90 90
         }
91 91
     }
92 92
 
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
      * @return void
96 96
      * @action site-reviews/review/saved
97 97
      */
98
-    public function onSaved(Review $review)
98
+    public function onSaved( Review $review )
99 99
     {
100
-        if (!$this->canPostReview($review)) {
100
+        if( !$this->canPostReview( $review ) ) {
101 101
             return;
102 102
         }
103
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
104
-        if ($rebusify->success) {
105
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
103
+        $rebusify = glsr( Rebusify::class )->sendReview( $review );
104
+        if( $rebusify->success ) {
105
+            glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id );
106 106
         }
107 107
     }
108 108
 
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
      * @return void
115 115
      * @action updated_postmeta
116 116
      */
117
-    public function onUpdatedMeta($metaId, $postId, $metaKey)
117
+    public function onUpdatedMeta( $metaId, $postId, $metaKey )
118 118
     {
119
-        $review = glsr_get_review($postId);
120
-        if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
119
+        $review = glsr_get_review( $postId );
120
+        if( !$this->canPostResponse( $review ) || '_response' !== $metaKey ) {
121 121
             return;
122 122
         }
123
-        $rebusify = glsr(Rebusify::class)->sendReviewResponse($review);
124
-        if ($rebusify->success) {
125
-            glsr(Database::class)->set($review->ID, 'rebusify_response', true);
123
+        $rebusify = glsr( Rebusify::class )->sendReviewResponse( $review );
124
+        if( $rebusify->success ) {
125
+            glsr( Database::class )->set( $review->ID, 'rebusify_response', true );
126 126
         }
127 127
     }
128 128
 
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
      */
132 132
     protected function buildCreateButton()
133 133
     {
134
-        return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [
134
+        return glsr( Builder::class )->a( __( 'Create Your Rebusify Account', 'site-reviews' ), [
135 135
             'class' => 'button',
136 136
             'href' => Rebusify::WEB_URL,
137 137
             'target' => '_blank',
138
-        ]);
138
+        ] );
139 139
     }
140 140
 
141 141
     /**
@@ -143,37 +143,37 @@  discard block
 block discarded – undo
143 143
      */
144 144
     protected function buildUpgradeButton()
145 145
     {
146
-        $build = glsr(Builder::class);
147
-        $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews'));
148
-        $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [
146
+        $build = glsr( Builder::class );
147
+        $notice = $build->p( __( 'Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews' ) );
148
+        $button = $build->a( __( 'Upgrade Your Rebusify Plan', 'site-reviews' ), [
149 149
             'class' => 'button',
150 150
             'href' => Rebusify::WEB_URL,
151 151
             'target' => '_blank',
152
-        ]);
153
-        return $build->div($notice.$button, [
152
+        ] );
153
+        return $build->div( $notice.$button, [
154 154
             'class' => 'glsr-notice-inline notice inline notice-info',
155
-        ]);
155
+        ] );
156 156
     }
157 157
 
158 158
     /**
159 159
      * @return bool
160 160
      */
161
-    protected function canPostResponse(Review $review)
161
+    protected function canPostResponse( Review $review )
162 162
     {
163 163
         $requiredValues = [
164
-            glsr(Database::class)->get($review->ID, 'rebusify'),
164
+            glsr( Database::class )->get( $review->ID, 'rebusify' ),
165 165
             $review->response,
166 166
             $review->review_id,
167 167
         ];
168
-        return $this->canProceed($review, 'rebusify_response')
168
+        return $this->canProceed( $review, 'rebusify_response' )
169 169
             && 'publish' === $review->status
170
-            && 3 === count(array_filter($requiredValues));
170
+            && 3 === count( array_filter( $requiredValues ) );
171 171
     }
172 172
 
173 173
     /**
174 174
      * @return bool
175 175
      */
176
-    protected function canPostReview(Review $review)
176
+    protected function canPostReview( Review $review )
177 177
     {
178 178
         $requiredValues = [
179 179
             $review->author,
@@ -182,60 +182,60 @@  discard block
 block discarded – undo
182 182
             $review->review_id,
183 183
             $review->title,
184 184
         ];
185
-        return $this->canProceed($review)
185
+        return $this->canProceed( $review )
186 186
             && 'publish' === $review->status
187
-            && 5 === count(array_filter($requiredValues));
187
+            && 5 === count( array_filter( $requiredValues ) );
188 188
     }
189 189
 
190 190
     /**
191 191
      * @param string $metaKey
192 192
      * @return bool
193 193
      */
194
-    protected function canProceed(Review $review, $metaKey = 'rebusify')
194
+    protected function canProceed( Review $review, $metaKey = 'rebusify' )
195 195
     {
196
-        return glsr(OptionManager::class)->getBool($this->enabledKey)
197
-            && $this->isReviewPostId($review->ID)
198
-            && !$this->hasMetaKey($review, $metaKey);
196
+        return glsr( OptionManager::class )->getBool( $this->enabledKey )
197
+            && $this->isReviewPostId( $review->ID )
198
+            && !$this->hasMetaKey( $review, $metaKey );
199 199
     }
200 200
 
201 201
     /**
202 202
      * @param string $metaKey
203 203
      * @return bool
204 204
      */
205
-    protected function hasMetaKey(Review $review, $metaKey = 'rebusify')
205
+    protected function hasMetaKey( Review $review, $metaKey = 'rebusify' )
206 206
     {
207
-        return '' !== glsr(Database::class)->get($review->ID, $metaKey);
207
+        return '' !== glsr( Database::class )->get( $review->ID, $metaKey );
208 208
     }
209 209
 
210 210
     /**
211 211
      * @param string $key
212 212
      * @return bool
213 213
      */
214
-    protected function isEmptyOrModified($key, array $settings)
214
+    protected function isEmptyOrModified( $key, array $settings )
215 215
     {
216
-        $oldValue = glsr_get_option($key);
217
-        $newValue = Arr::get($settings, $key);
216
+        $oldValue = glsr_get_option( $key );
217
+        $newValue = Arr::get( $settings, $key );
218 218
         return empty($newValue) || $newValue !== $oldValue;
219 219
     }
220 220
 
221 221
     /**
222 222
      * @return array
223 223
      */
224
-    protected function sanitizeRebusifySettings(array $settings)
224
+    protected function sanitizeRebusifySettings( array $settings )
225 225
     {
226
-        $rebusify = glsr(Rebusify::class)->activateKey(
227
-            Arr::get($settings, $this->apiKey),
228
-            Arr::get($settings, $this->emailKey)
226
+        $rebusify = glsr( Rebusify::class )->activateKey(
227
+            Arr::get( $settings, $this->apiKey ),
228
+            Arr::get( $settings, $this->emailKey )
229 229
         );
230
-        if ($rebusify->success) {
231
-            update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype'));
230
+        if( $rebusify->success ) {
231
+            update_option( $this->rebusifyKey, Arr::get( $rebusify->response, 'producttype' ) );
232 232
         } else {
233
-            delete_option($this->rebusifyKey);
234
-            $settings = Arr::set($settings, $this->enabledKey, 'no');
235
-            glsr(Notice::class)->addError(sprintf(
236
-                __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'),
233
+            delete_option( $this->rebusifyKey );
234
+            $settings = Arr::set( $settings, $this->enabledKey, 'no' );
235
+            glsr( Notice::class )->addError( sprintf(
236
+                __( 'Your Rebusify account details could not be verified, please try again. %s', 'site-reviews' ),
237 237
                 '('.$rebusify->message.')'
238
-            ));
238
+            ) );
239 239
         }
240 240
         return $settings;
241 241
     }
Please login to merge, or discard this patch.
plugin/Controllers/TaxonomyController.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -8,97 +8,97 @@
 block discarded – undo
8 8
 
9 9
 class TaxonomyController
10 10
 {
11
-    /**
12
-     * @return void
13
-     * @action Application::TAXONOMY._add_form_fields
14
-     * @action Application::TAXONOMY._edit_form
15
-     */
16
-    public function disableParents()
17
-    {
18
-        global $wp_taxonomies;
19
-        $wp_taxonomies[Application::TAXONOMY]->hierarchical = false;
20
-    }
11
+	/**
12
+	 * @return void
13
+	 * @action Application::TAXONOMY._add_form_fields
14
+	 * @action Application::TAXONOMY._edit_form
15
+	 */
16
+	public function disableParents()
17
+	{
18
+		global $wp_taxonomies;
19
+		$wp_taxonomies[Application::TAXONOMY]->hierarchical = false;
20
+	}
21 21
 
22
-    /**
23
-     * @return void
24
-     * @action Application::TAXONOMY._term_edit_form_top
25
-     * @action Application::TAXONOMY._term_new_form_tag
26
-     */
27
-    public function enableParents()
28
-    {
29
-        global $wp_taxonomies;
30
-        $wp_taxonomies[Application::TAXONOMY]->hierarchical = true;
31
-    }
22
+	/**
23
+	 * @return void
24
+	 * @action Application::TAXONOMY._term_edit_form_top
25
+	 * @action Application::TAXONOMY._term_new_form_tag
26
+	 */
27
+	public function enableParents()
28
+	{
29
+		global $wp_taxonomies;
30
+		$wp_taxonomies[Application::TAXONOMY]->hierarchical = true;
31
+	}
32 32
 
33
-    /**
34
-     * @return void
35
-     * @action restrict_manage_posts
36
-     */
37
-    public function renderTaxonomyFilter()
38
-    {
39
-        if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) {
40
-            return;
41
-        }
42
-        echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [
43
-            'class' => 'screen-reader-text',
44
-            'for' => Application::TAXONOMY,
45
-        ]);
46
-        wp_dropdown_categories([
47
-            'depth' => 3,
48
-            'hide_empty' => true,
49
-            'hide_if_empty' => true,
50
-            'hierarchical' => true,
51
-            'name' => Application::TAXONOMY,
52
-            'orderby' => 'name',
53
-            'selected' => $this->getSelected(),
54
-            'show_count' => false,
55
-            'show_option_all' => $this->getShowOptionAll(),
56
-            'taxonomy' => Application::TAXONOMY,
57
-            'value_field' => 'slug',
58
-        ]);
59
-    }
33
+	/**
34
+	 * @return void
35
+	 * @action restrict_manage_posts
36
+	 */
37
+	public function renderTaxonomyFilter()
38
+	{
39
+		if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) {
40
+			return;
41
+		}
42
+		echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [
43
+			'class' => 'screen-reader-text',
44
+			'for' => Application::TAXONOMY,
45
+		]);
46
+		wp_dropdown_categories([
47
+			'depth' => 3,
48
+			'hide_empty' => true,
49
+			'hide_if_empty' => true,
50
+			'hierarchical' => true,
51
+			'name' => Application::TAXONOMY,
52
+			'orderby' => 'name',
53
+			'selected' => $this->getSelected(),
54
+			'show_count' => false,
55
+			'show_option_all' => $this->getShowOptionAll(),
56
+			'taxonomy' => Application::TAXONOMY,
57
+			'value_field' => 'slug',
58
+		]);
59
+	}
60 60
 
61
-    /**
62
-     * @param int $postId
63
-     * @param array $terms
64
-     * @param array $newTTIds
65
-     * @param string $taxonomy
66
-     * @param bool $append
67
-     * @param array $oldTTIds
68
-     * @return void
69
-     * @action set_object_terms
70
-     */
71
-    public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
72
-    {
73
-        if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) {
74
-            return;
75
-        }
76
-        $diff = array_diff($newTTIds, $oldTTIds);
77
-        if (empty($newTerm = array_shift($diff))) {
78
-            $newTerm = array_shift($newTTIds);
79
-        }
80
-        if ($newTerm) {
81
-            wp_set_object_terms($postId, intval($newTerm), $taxonomy);
82
-        }
83
-    }
61
+	/**
62
+	 * @param int $postId
63
+	 * @param array $terms
64
+	 * @param array $newTTIds
65
+	 * @param string $taxonomy
66
+	 * @param bool $append
67
+	 * @param array $oldTTIds
68
+	 * @return void
69
+	 * @action set_object_terms
70
+	 */
71
+	public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
72
+	{
73
+		if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) {
74
+			return;
75
+		}
76
+		$diff = array_diff($newTTIds, $oldTTIds);
77
+		if (empty($newTerm = array_shift($diff))) {
78
+			$newTerm = array_shift($newTTIds);
79
+		}
80
+		if ($newTerm) {
81
+			wp_set_object_terms($postId, intval($newTerm), $taxonomy);
82
+		}
83
+	}
84 84
 
85
-    /**
86
-     * @return string
87
-     */
88
-    protected function getSelected()
89
-    {
90
-        global $wp_query;
91
-        return Arr::get($wp_query->query, Application::TAXONOMY);
92
-    }
85
+	/**
86
+	 * @return string
87
+	 */
88
+	protected function getSelected()
89
+	{
90
+		global $wp_query;
91
+		return Arr::get($wp_query->query, Application::TAXONOMY);
92
+	}
93 93
 
94
-    /**
95
-     * @return string
96
-     */
97
-    protected function getShowOptionAll()
98
-    {
99
-        $taxonomy = get_taxonomy(Application::TAXONOMY);
100
-        return $taxonomy
101
-            ? ucfirst(strtolower($taxonomy->labels->all_items))
102
-            : '';
103
-    }
94
+	/**
95
+	 * @return string
96
+	 */
97
+	protected function getShowOptionAll()
98
+	{
99
+		$taxonomy = get_taxonomy(Application::TAXONOMY);
100
+		return $taxonomy
101
+			? ucfirst(strtolower($taxonomy->labels->all_items))
102
+			: '';
103
+	}
104 104
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function renderTaxonomyFilter()
38 38
     {
39
-        if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) {
39
+        if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ) ) {
40 40
             return;
41 41
         }
42
-        echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [
42
+        echo glsr( Builder::class )->label( __( 'Filter by category', 'site-reviews' ), [
43 43
             'class' => 'screen-reader-text',
44 44
             'for' => Application::TAXONOMY,
45
-        ]);
46
-        wp_dropdown_categories([
45
+        ] );
46
+        wp_dropdown_categories( [
47 47
             'depth' => 3,
48 48
             'hide_empty' => true,
49 49
             'hide_if_empty' => true,
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             'show_option_all' => $this->getShowOptionAll(),
56 56
             'taxonomy' => Application::TAXONOMY,
57 57
             'value_field' => 'slug',
58
-        ]);
58
+        ] );
59 59
     }
60 60
 
61 61
     /**
@@ -68,17 +68,17 @@  discard block
 block discarded – undo
68 68
      * @return void
69 69
      * @action set_object_terms
70 70
      */
71
-    public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
71
+    public function restrictTermSelection( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds )
72 72
     {
73
-        if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) {
73
+        if( Application::TAXONOMY != $taxonomy || count( $newTTIds ) <= 1 ) {
74 74
             return;
75 75
         }
76
-        $diff = array_diff($newTTIds, $oldTTIds);
77
-        if (empty($newTerm = array_shift($diff))) {
78
-            $newTerm = array_shift($newTTIds);
76
+        $diff = array_diff( $newTTIds, $oldTTIds );
77
+        if( empty($newTerm = array_shift( $diff )) ) {
78
+            $newTerm = array_shift( $newTTIds );
79 79
         }
80
-        if ($newTerm) {
81
-            wp_set_object_terms($postId, intval($newTerm), $taxonomy);
80
+        if( $newTerm ) {
81
+            wp_set_object_terms( $postId, intval( $newTerm ), $taxonomy );
82 82
         }
83 83
     }
84 84
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
     protected function getSelected()
89 89
     {
90 90
         global $wp_query;
91
-        return Arr::get($wp_query->query, Application::TAXONOMY);
91
+        return Arr::get( $wp_query->query, Application::TAXONOMY );
92 92
     }
93 93
 
94 94
     /**
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
      */
97 97
     protected function getShowOptionAll()
98 98
     {
99
-        $taxonomy = get_taxonomy(Application::TAXONOMY);
99
+        $taxonomy = get_taxonomy( Application::TAXONOMY );
100 100
         return $taxonomy
101
-            ? ucfirst(strtolower($taxonomy->labels->all_items))
101
+            ? ucfirst( strtolower( $taxonomy->labels->all_items ) )
102 102
             : '';
103 103
     }
104 104
 }
Please login to merge, or discard this patch.
plugin/Controllers/AdminController.php 2 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -16,222 +16,222 @@
 block discarded – undo
16 16
 
17 17
 class AdminController extends Controller
18 18
 {
19
-    /**
20
-     * @return void
21
-     * @action admin_enqueue_scripts
22
-     */
23
-    public function enqueueAssets()
24
-    {
25
-        $command = new EnqueueAdminAssets([
26
-            'pointers' => [[
27
-                'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'),
28
-                'id' => 'glsr-pointer-pinned',
29
-                'position' => [
30
-                    'edge' => 'right',
31
-                    'align' => 'middle',
32
-                ],
33
-                'screen' => Application::POST_TYPE,
34
-                'target' => '#misc-pub-pinned',
35
-                'title' => __('Pin Your Reviews', 'site-reviews'),
36
-            ]],
37
-        ]);
38
-        $this->execute($command);
39
-    }
40
-
41
-    /**
42
-     * @return array
43
-     * @filter plugin_action_links_site-reviews/site-reviews.php
44
-     */
45
-    public function filterActionLinks(array $links)
46
-    {
47
-        $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [
48
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'),
49
-        ]);
50
-        $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
51
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'),
52
-        ]);
53
-        return $links;
54
-    }
55
-
56
-    /**
57
-     * @param array $capabilities
58
-     * @param string $capability
59
-     * @return array
60
-     * @filter map_meta_cap
61
-     */
62
-    public function filterCreateCapability($capabilities, $capability)
63
-    {
64
-        if ($capability == 'create_'.Application::POST_TYPE) {
65
-            $capabilities[] = 'do_not_allow';
66
-        }
67
-        return $capabilities;
68
-    }
69
-
70
-    /**
71
-     * @param array $items
72
-     * @return array
73
-     * @filter dashboard_glance_items
74
-     */
75
-    public function filterDashboardGlanceItems($items)
76
-    {
77
-        $postCount = wp_count_posts(Application::POST_TYPE);
78
-        if (empty($postCount->publish)) {
79
-            return $items;
80
-        }
81
-        $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews');
82
-        $text = sprintf($text, number_format_i18n($postCount->publish));
83
-        $items = Arr::consolidateArray($items);
84
-        $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts)
85
-            ? glsr(Builder::class)->a($text, [
86
-                'class' => 'glsr-review-count',
87
-                'href' => 'edit.php?post_type='.Application::POST_TYPE,
88
-            ])
89
-            : glsr(Builder::class)->span($text, [
90
-                'class' => 'glsr-review-count',
91
-            ]);
92
-        return $items;
93
-    }
94
-
95
-    /**
96
-     * @param array $plugins
97
-     * @return array
98
-     * @filter mce_external_plugins
99
-     */
100
-    public function filterTinymcePlugins($plugins)
101
-    {
102
-        if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
103
-            $plugins = Arr::consolidateArray($plugins);
104
-            $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js');
105
-        }
106
-        return $plugins;
107
-    }
108
-
109
-    /**
110
-     * @return void
111
-     * @action admin_init
112
-     */
113
-    public function registerTinymcePopups()
114
-    {
115
-        $command = new RegisterTinymcePopups([
116
-            'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'),
117
-            'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'),
118
-            'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'),
119
-        ]);
120
-        $this->execute($command);
121
-    }
122
-
123
-    /**
124
-     * @param string $editorId
125
-     * @return void|null
126
-     * @action media_buttons
127
-     */
128
-    public function renderTinymceButton($editorId)
129
-    {
130
-        $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId);
131
-        if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) {
132
-            return;
133
-        }
134
-        $shortcodes = [];
135
-        foreach (glsr()->mceShortcodes as $shortcode => $values) {
136
-            $shortcodes[$shortcode] = $values;
137
-        }
138
-        if (empty($shortcodes)) {
139
-            return;
140
-        }
141
-        glsr()->render('partials/editor/tinymce', [
142
-            'shortcodes' => $shortcodes,
143
-        ]);
144
-    }
145
-
146
-    /**
147
-     * @return void
148
-     */
149
-    public function routerClearConsole()
150
-    {
151
-        glsr(Console::class)->clear();
152
-        glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews'));
153
-    }
154
-
155
-    /**
156
-     * @return void
157
-     */
158
-    public function routerFetchConsole()
159
-    {
160
-        glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews'));
161
-    }
162
-
163
-    /**
164
-     * @param bool $showNotice
165
-     * @return void
166
-     */
167
-    public function routerCountReviews($showNotice = true)
168
-    {
169
-        glsr(CountsManager::class)->countAll();
170
-        glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
171
-        if ($showNotice) {
172
-            glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews'));
173
-        }
174
-    }
175
-
176
-    /**
177
-     * @return void
178
-     */
179
-    public function routerDownloadConsole()
180
-    {
181
-        $this->download(Application::ID.'-console.txt', glsr(Console::class)->get());
182
-    }
183
-
184
-    /**
185
-     * @return void
186
-     */
187
-    public function routerDownloadSystemInfo()
188
-    {
189
-        $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get());
190
-    }
191
-
192
-    /**
193
-     * @return void
194
-     */
195
-    public function routerExportSettings()
196
-    {
197
-        $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json());
198
-    }
199
-
200
-    /**
201
-     * @return void
202
-     */
203
-    public function routerImportSettings()
204
-    {
205
-        $file = $_FILES['import-file'];
206
-        if (UPLOAD_ERR_OK !== $file['error']) {
207
-            return glsr(Notice::class)->addError($this->getUploadError($file['error']));
208
-        }
209
-        if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) {
210
-            return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews'));
211
-        }
212
-        $settings = json_decode(file_get_contents($file['tmp_name']), true);
213
-        if (empty($settings)) {
214
-            return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews'));
215
-        }
216
-        glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings));
217
-        glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews'));
218
-    }
219
-
220
-    /**
221
-     * @param int $errorCode
222
-     * @return string
223
-     */
224
-    protected function getUploadError($errorCode)
225
-    {
226
-        $errors = [
227
-            UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'),
228
-            UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'),
229
-            UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'),
230
-            UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'),
231
-            UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'),
232
-            UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'),
233
-            UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'),
234
-        ];
235
-        return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews'));
236
-    }
19
+	/**
20
+	 * @return void
21
+	 * @action admin_enqueue_scripts
22
+	 */
23
+	public function enqueueAssets()
24
+	{
25
+		$command = new EnqueueAdminAssets([
26
+			'pointers' => [[
27
+				'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'),
28
+				'id' => 'glsr-pointer-pinned',
29
+				'position' => [
30
+					'edge' => 'right',
31
+					'align' => 'middle',
32
+				],
33
+				'screen' => Application::POST_TYPE,
34
+				'target' => '#misc-pub-pinned',
35
+				'title' => __('Pin Your Reviews', 'site-reviews'),
36
+			]],
37
+		]);
38
+		$this->execute($command);
39
+	}
40
+
41
+	/**
42
+	 * @return array
43
+	 * @filter plugin_action_links_site-reviews/site-reviews.php
44
+	 */
45
+	public function filterActionLinks(array $links)
46
+	{
47
+		$links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [
48
+			'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'),
49
+		]);
50
+		$links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
51
+			'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'),
52
+		]);
53
+		return $links;
54
+	}
55
+
56
+	/**
57
+	 * @param array $capabilities
58
+	 * @param string $capability
59
+	 * @return array
60
+	 * @filter map_meta_cap
61
+	 */
62
+	public function filterCreateCapability($capabilities, $capability)
63
+	{
64
+		if ($capability == 'create_'.Application::POST_TYPE) {
65
+			$capabilities[] = 'do_not_allow';
66
+		}
67
+		return $capabilities;
68
+	}
69
+
70
+	/**
71
+	 * @param array $items
72
+	 * @return array
73
+	 * @filter dashboard_glance_items
74
+	 */
75
+	public function filterDashboardGlanceItems($items)
76
+	{
77
+		$postCount = wp_count_posts(Application::POST_TYPE);
78
+		if (empty($postCount->publish)) {
79
+			return $items;
80
+		}
81
+		$text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews');
82
+		$text = sprintf($text, number_format_i18n($postCount->publish));
83
+		$items = Arr::consolidateArray($items);
84
+		$items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts)
85
+			? glsr(Builder::class)->a($text, [
86
+				'class' => 'glsr-review-count',
87
+				'href' => 'edit.php?post_type='.Application::POST_TYPE,
88
+			])
89
+			: glsr(Builder::class)->span($text, [
90
+				'class' => 'glsr-review-count',
91
+			]);
92
+		return $items;
93
+	}
94
+
95
+	/**
96
+	 * @param array $plugins
97
+	 * @return array
98
+	 * @filter mce_external_plugins
99
+	 */
100
+	public function filterTinymcePlugins($plugins)
101
+	{
102
+		if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
103
+			$plugins = Arr::consolidateArray($plugins);
104
+			$plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js');
105
+		}
106
+		return $plugins;
107
+	}
108
+
109
+	/**
110
+	 * @return void
111
+	 * @action admin_init
112
+	 */
113
+	public function registerTinymcePopups()
114
+	{
115
+		$command = new RegisterTinymcePopups([
116
+			'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'),
117
+			'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'),
118
+			'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'),
119
+		]);
120
+		$this->execute($command);
121
+	}
122
+
123
+	/**
124
+	 * @param string $editorId
125
+	 * @return void|null
126
+	 * @action media_buttons
127
+	 */
128
+	public function renderTinymceButton($editorId)
129
+	{
130
+		$allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId);
131
+		if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) {
132
+			return;
133
+		}
134
+		$shortcodes = [];
135
+		foreach (glsr()->mceShortcodes as $shortcode => $values) {
136
+			$shortcodes[$shortcode] = $values;
137
+		}
138
+		if (empty($shortcodes)) {
139
+			return;
140
+		}
141
+		glsr()->render('partials/editor/tinymce', [
142
+			'shortcodes' => $shortcodes,
143
+		]);
144
+	}
145
+
146
+	/**
147
+	 * @return void
148
+	 */
149
+	public function routerClearConsole()
150
+	{
151
+		glsr(Console::class)->clear();
152
+		glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews'));
153
+	}
154
+
155
+	/**
156
+	 * @return void
157
+	 */
158
+	public function routerFetchConsole()
159
+	{
160
+		glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews'));
161
+	}
162
+
163
+	/**
164
+	 * @param bool $showNotice
165
+	 * @return void
166
+	 */
167
+	public function routerCountReviews($showNotice = true)
168
+	{
169
+		glsr(CountsManager::class)->countAll();
170
+		glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
171
+		if ($showNotice) {
172
+			glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews'));
173
+		}
174
+	}
175
+
176
+	/**
177
+	 * @return void
178
+	 */
179
+	public function routerDownloadConsole()
180
+	{
181
+		$this->download(Application::ID.'-console.txt', glsr(Console::class)->get());
182
+	}
183
+
184
+	/**
185
+	 * @return void
186
+	 */
187
+	public function routerDownloadSystemInfo()
188
+	{
189
+		$this->download(Application::ID.'-system-info.txt', glsr(System::class)->get());
190
+	}
191
+
192
+	/**
193
+	 * @return void
194
+	 */
195
+	public function routerExportSettings()
196
+	{
197
+		$this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json());
198
+	}
199
+
200
+	/**
201
+	 * @return void
202
+	 */
203
+	public function routerImportSettings()
204
+	{
205
+		$file = $_FILES['import-file'];
206
+		if (UPLOAD_ERR_OK !== $file['error']) {
207
+			return glsr(Notice::class)->addError($this->getUploadError($file['error']));
208
+		}
209
+		if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) {
210
+			return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews'));
211
+		}
212
+		$settings = json_decode(file_get_contents($file['tmp_name']), true);
213
+		if (empty($settings)) {
214
+			return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews'));
215
+		}
216
+		glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings));
217
+		glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews'));
218
+	}
219
+
220
+	/**
221
+	 * @param int $errorCode
222
+	 * @return string
223
+	 */
224
+	protected function getUploadError($errorCode)
225
+	{
226
+		$errors = [
227
+			UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'),
228
+			UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'),
229
+			UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'),
230
+			UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'),
231
+			UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'),
232
+			UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'),
233
+			UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'),
234
+		];
235
+		return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews'));
236
+	}
237 237
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function enqueueAssets()
24 24
     {
25
-        $command = new EnqueueAdminAssets([
25
+        $command = new EnqueueAdminAssets( [
26 26
             'pointers' => [[
27
-                'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'),
27
+                'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ),
28 28
                 'id' => 'glsr-pointer-pinned',
29 29
                 'position' => [
30 30
                     'edge' => 'right',
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
                 ],
33 33
                 'screen' => Application::POST_TYPE,
34 34
                 'target' => '#misc-pub-pinned',
35
-                'title' => __('Pin Your Reviews', 'site-reviews'),
35
+                'title' => __( 'Pin Your Reviews', 'site-reviews' ),
36 36
             ]],
37
-        ]);
38
-        $this->execute($command);
37
+        ] );
38
+        $this->execute( $command );
39 39
     }
40 40
 
41 41
     /**
42 42
      * @return array
43 43
      * @filter plugin_action_links_site-reviews/site-reviews.php
44 44
      */
45
-    public function filterActionLinks(array $links)
45
+    public function filterActionLinks( array $links )
46 46
     {
47
-        $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [
48
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'),
49
-        ]);
50
-        $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
51
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'),
52
-        ]);
47
+        $links['documentation'] = glsr( Builder::class )->a( __( 'Help', 'site-reviews' ), [
48
+            'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=documentation' ),
49
+        ] );
50
+        $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [
51
+            'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ),
52
+        ] );
53 53
         return $links;
54 54
     }
55 55
 
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      * @return array
60 60
      * @filter map_meta_cap
61 61
      */
62
-    public function filterCreateCapability($capabilities, $capability)
62
+    public function filterCreateCapability( $capabilities, $capability )
63 63
     {
64
-        if ($capability == 'create_'.Application::POST_TYPE) {
64
+        if( $capability == 'create_'.Application::POST_TYPE ) {
65 65
             $capabilities[] = 'do_not_allow';
66 66
         }
67 67
         return $capabilities;
@@ -72,23 +72,23 @@  discard block
 block discarded – undo
72 72
      * @return array
73 73
      * @filter dashboard_glance_items
74 74
      */
75
-    public function filterDashboardGlanceItems($items)
75
+    public function filterDashboardGlanceItems( $items )
76 76
     {
77
-        $postCount = wp_count_posts(Application::POST_TYPE);
78
-        if (empty($postCount->publish)) {
77
+        $postCount = wp_count_posts( Application::POST_TYPE );
78
+        if( empty($postCount->publish) ) {
79 79
             return $items;
80 80
         }
81
-        $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews');
82
-        $text = sprintf($text, number_format_i18n($postCount->publish));
83
-        $items = Arr::consolidateArray($items);
84
-        $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts)
85
-            ? glsr(Builder::class)->a($text, [
81
+        $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' );
82
+        $text = sprintf( $text, number_format_i18n( $postCount->publish ) );
83
+        $items = Arr::consolidateArray( $items );
84
+        $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts )
85
+            ? glsr( Builder::class )->a( $text, [
86 86
                 'class' => 'glsr-review-count',
87 87
                 'href' => 'edit.php?post_type='.Application::POST_TYPE,
88
-            ])
89
-            : glsr(Builder::class)->span($text, [
88
+            ] )
89
+            : glsr( Builder::class )->span( $text, [
90 90
                 'class' => 'glsr-review-count',
91
-            ]);
91
+            ] );
92 92
         return $items;
93 93
     }
94 94
 
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
      * @return array
98 98
      * @filter mce_external_plugins
99 99
      */
100
-    public function filterTinymcePlugins($plugins)
100
+    public function filterTinymcePlugins( $plugins )
101 101
     {
102
-        if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
103
-            $plugins = Arr::consolidateArray($plugins);
104
-            $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js');
102
+        if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
103
+            $plugins = Arr::consolidateArray( $plugins );
104
+            $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' );
105 105
         }
106 106
         return $plugins;
107 107
     }
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function registerTinymcePopups()
114 114
     {
115
-        $command = new RegisterTinymcePopups([
116
-            'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'),
117
-            'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'),
118
-            'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'),
119
-        ]);
120
-        $this->execute($command);
115
+        $command = new RegisterTinymcePopups( [
116
+            'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ),
117
+            'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ),
118
+            'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ),
119
+        ] );
120
+        $this->execute( $command );
121 121
     }
122 122
 
123 123
     /**
@@ -125,22 +125,22 @@  discard block
 block discarded – undo
125 125
      * @return void|null
126 126
      * @action media_buttons
127 127
      */
128
-    public function renderTinymceButton($editorId)
128
+    public function renderTinymceButton( $editorId )
129 129
     {
130
-        $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId);
131
-        if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) {
130
+        $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId );
131
+        if( 'post' != glsr_current_screen()->base || !in_array( $editorId, $allowedEditors ) ) {
132 132
             return;
133 133
         }
134 134
         $shortcodes = [];
135
-        foreach (glsr()->mceShortcodes as $shortcode => $values) {
135
+        foreach( glsr()->mceShortcodes as $shortcode => $values ) {
136 136
             $shortcodes[$shortcode] = $values;
137 137
         }
138
-        if (empty($shortcodes)) {
138
+        if( empty($shortcodes) ) {
139 139
             return;
140 140
         }
141
-        glsr()->render('partials/editor/tinymce', [
141
+        glsr()->render( 'partials/editor/tinymce', [
142 142
             'shortcodes' => $shortcodes,
143
-        ]);
143
+        ] );
144 144
     }
145 145
 
146 146
     /**
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function routerClearConsole()
150 150
     {
151
-        glsr(Console::class)->clear();
152
-        glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews'));
151
+        glsr( Console::class )->clear();
152
+        glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) );
153 153
     }
154 154
 
155 155
     /**
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function routerFetchConsole()
159 159
     {
160
-        glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews'));
160
+        glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) );
161 161
     }
162 162
 
163 163
     /**
164 164
      * @param bool $showNotice
165 165
      * @return void
166 166
      */
167
-    public function routerCountReviews($showNotice = true)
167
+    public function routerCountReviews( $showNotice = true )
168 168
     {
169
-        glsr(CountsManager::class)->countAll();
170
-        glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
171
-        if ($showNotice) {
172
-            glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews'));
169
+        glsr( CountsManager::class )->countAll();
170
+        glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) );
171
+        if( $showNotice ) {
172
+            glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) );
173 173
         }
174 174
     }
175 175
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function routerDownloadConsole()
180 180
     {
181
-        $this->download(Application::ID.'-console.txt', glsr(Console::class)->get());
181
+        $this->download( Application::ID.'-console.txt', glsr( Console::class )->get() );
182 182
     }
183 183
 
184 184
     /**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      */
187 187
     public function routerDownloadSystemInfo()
188 188
     {
189
-        $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get());
189
+        $this->download( Application::ID.'-system-info.txt', glsr( System::class )->get() );
190 190
     }
191 191
 
192 192
     /**
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     public function routerExportSettings()
196 196
     {
197
-        $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json());
197
+        $this->download( Application::ID.'-settings.json', glsr( OptionManager::class )->json() );
198 198
     }
199 199
 
200 200
     /**
@@ -203,35 +203,35 @@  discard block
 block discarded – undo
203 203
     public function routerImportSettings()
204 204
     {
205 205
         $file = $_FILES['import-file'];
206
-        if (UPLOAD_ERR_OK !== $file['error']) {
207
-            return glsr(Notice::class)->addError($this->getUploadError($file['error']));
206
+        if( UPLOAD_ERR_OK !== $file['error'] ) {
207
+            return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) );
208 208
         }
209
-        if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) {
210
-            return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews'));
209
+        if( 'application/json' !== $file['type'] || !Str::endsWith( '.json', $file['name'] ) ) {
210
+            return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) );
211 211
         }
212
-        $settings = json_decode(file_get_contents($file['tmp_name']), true);
213
-        if (empty($settings)) {
214
-            return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews'));
212
+        $settings = json_decode( file_get_contents( $file['tmp_name'] ), true );
213
+        if( empty($settings) ) {
214
+            return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) );
215 215
         }
216
-        glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings));
217
-        glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews'));
216
+        glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) );
217
+        glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) );
218 218
     }
219 219
 
220 220
     /**
221 221
      * @param int $errorCode
222 222
      * @return string
223 223
      */
224
-    protected function getUploadError($errorCode)
224
+    protected function getUploadError( $errorCode )
225 225
     {
226 226
         $errors = [
227
-            UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'),
228
-            UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'),
229
-            UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'),
230
-            UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'),
231
-            UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'),
232
-            UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'),
233
-            UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'),
227
+            UPLOAD_ERR_INI_SIZE => __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews' ),
228
+            UPLOAD_ERR_FORM_SIZE => __( 'The uploaded file is too big.', 'site-reviews' ),
229
+            UPLOAD_ERR_PARTIAL => __( 'The uploaded file was only partially uploaded.', 'site-reviews' ),
230
+            UPLOAD_ERR_NO_FILE => __( 'No file was uploaded.', 'site-reviews' ),
231
+            UPLOAD_ERR_NO_TMP_DIR => __( 'Missing a temporary folder.', 'site-reviews' ),
232
+            UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ),
233
+            UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ),
234 234
         ];
235
-        return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews'));
235
+        return Arr::get( $errors, $errorCode, __( 'Unknown upload error.', 'site-reviews' ) );
236 236
     }
237 237
 }
Please login to merge, or discard this patch.
plugin/Modules/ReviewLimits.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -8,103 +8,103 @@
 block discarded – undo
8 8
 
9 9
 class ReviewLimits
10 10
 {
11
-    protected $request;
11
+	protected $request;
12 12
 
13
-    /**
14
-     * @return array
15
-     * @filter site-reviews/get/reviews/query
16
-     */
17
-    public function filterReviewsQuery(array $parameters, array $args)
18
-    {
19
-        if ($authorId = get_current_user_id()) {
20
-            $parameters['author'] = $authorId;
21
-        }
22
-        $parameters['post_status'] = ['pending', 'publish'];
23
-        return apply_filters('site-reviews/reviews-limits/query', $parameters, $args);
24
-    }
13
+	/**
14
+	 * @return array
15
+	 * @filter site-reviews/get/reviews/query
16
+	 */
17
+	public function filterReviewsQuery(array $parameters, array $args)
18
+	{
19
+		if ($authorId = get_current_user_id()) {
20
+			$parameters['author'] = $authorId;
21
+		}
22
+		$parameters['post_status'] = ['pending', 'publish'];
23
+		return apply_filters('site-reviews/reviews-limits/query', $parameters, $args);
24
+	}
25 25
 
26
-    /**
27
-     * @return bool
28
-     */
29
-    public function hasReachedLimit(array $request = [])
30
-    {
31
-        $this->request = $request;
32
-        $method = Helper::buildMethodName(
33
-            glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy'
34
-        );
35
-        return method_exists($this, $method)
36
-            ? !call_user_func([$this, $method])
37
-            : false;
38
-    }
26
+	/**
27
+	 * @return bool
28
+	 */
29
+	public function hasReachedLimit(array $request = [])
30
+	{
31
+		$this->request = $request;
32
+		$method = Helper::buildMethodName(
33
+			glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy'
34
+		);
35
+		return method_exists($this, $method)
36
+			? !call_user_func([$this, $method])
37
+			: false;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $value
42
-     * @param string $whitelist
43
-     * @return bool
44
-     */
45
-    public function isWhitelisted($value, $whitelist)
46
-    {
47
-        if (empty($whitelist)) {
48
-            return false;
49
-        }
50
-        return in_array($value, array_filter(explode("\n", $whitelist), 'trim'));
51
-    }
40
+	/**
41
+	 * @param string $value
42
+	 * @param string $whitelist
43
+	 * @return bool
44
+	 */
45
+	public function isWhitelisted($value, $whitelist)
46
+	{
47
+		if (empty($whitelist)) {
48
+			return false;
49
+		}
50
+		return in_array($value, array_filter(explode("\n", $whitelist), 'trim'));
51
+	}
52 52
 
53
-    /**
54
-     * @param string $whitelistName
55
-     * @return string
56
-     */
57
-    protected function getWhitelist($whitelistName)
58
-    {
59
-        return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName);
60
-    }
53
+	/**
54
+	 * @param string $whitelistName
55
+	 * @return string
56
+	 */
57
+	protected function getWhitelist($whitelistName)
58
+	{
59
+		return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName);
60
+	}
61 61
 
62
-    /**
63
-     * @return bool
64
-     */
65
-    protected function validate($key, $value, $addMetaQuery = true)
66
-    {
67
-        if ($this->isWhitelisted($value, $this->getWhitelist($key))) {
68
-            return true;
69
-        }
70
-        add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2);
71
-        $args = ['assigned_to' => Arr::get($this->request, 'assign_to')];
72
-        if ($addMetaQuery) {
73
-            $args[$key] = $value;
74
-        }
75
-        $reviews = glsr_get_reviews($args);
76
-        remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5);
77
-        return 0 === count($reviews);
78
-    }
62
+	/**
63
+	 * @return bool
64
+	 */
65
+	protected function validate($key, $value, $addMetaQuery = true)
66
+	{
67
+		if ($this->isWhitelisted($value, $this->getWhitelist($key))) {
68
+			return true;
69
+		}
70
+		add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2);
71
+		$args = ['assigned_to' => Arr::get($this->request, 'assign_to')];
72
+		if ($addMetaQuery) {
73
+			$args[$key] = $value;
74
+		}
75
+		$reviews = glsr_get_reviews($args);
76
+		remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5);
77
+		return 0 === count($reviews);
78
+	}
79 79
 
80
-    /**
81
-     * @return bool
82
-     */
83
-    protected function validateByEmail()
84
-    {
85
-        glsr_log()->debug('Email is: '.Arr::get($this->request, 'email'));
86
-        return $this->validate('email', Arr::get($this->request, 'email'));
87
-    }
80
+	/**
81
+	 * @return bool
82
+	 */
83
+	protected function validateByEmail()
84
+	{
85
+		glsr_log()->debug('Email is: '.Arr::get($this->request, 'email'));
86
+		return $this->validate('email', Arr::get($this->request, 'email'));
87
+	}
88 88
 
89
-    /**
90
-     * @return bool
91
-     */
92
-    protected function validateByIpAddress()
93
-    {
94
-        glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address'));
95
-        return $this->validate('ip_address', Arr::get($this->request, 'ip_address'));
96
-    }
89
+	/**
90
+	 * @return bool
91
+	 */
92
+	protected function validateByIpAddress()
93
+	{
94
+		glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address'));
95
+		return $this->validate('ip_address', Arr::get($this->request, 'ip_address'));
96
+	}
97 97
 
98
-    /**
99
-     * @return bool
100
-     */
101
-    protected function validateByUsername()
102
-    {
103
-        $user = wp_get_current_user();
104
-        if (!$user->exists()) {
105
-            return true;
106
-        }
107
-        glsr_log()->debug('Username is: '.$user->user_login);
108
-        return $this->validate('username', $user->user_login, false);
109
-    }
98
+	/**
99
+	 * @return bool
100
+	 */
101
+	protected function validateByUsername()
102
+	{
103
+		$user = wp_get_current_user();
104
+		if (!$user->exists()) {
105
+			return true;
106
+		}
107
+		glsr_log()->debug('Username is: '.$user->user_login);
108
+		return $this->validate('username', $user->user_login, false);
109
+	}
110 110
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -14,26 +14,26 @@  discard block
 block discarded – undo
14 14
      * @return array
15 15
      * @filter site-reviews/get/reviews/query
16 16
      */
17
-    public function filterReviewsQuery(array $parameters, array $args)
17
+    public function filterReviewsQuery( array $parameters, array $args )
18 18
     {
19
-        if ($authorId = get_current_user_id()) {
19
+        if( $authorId = get_current_user_id() ) {
20 20
             $parameters['author'] = $authorId;
21 21
         }
22 22
         $parameters['post_status'] = ['pending', 'publish'];
23
-        return apply_filters('site-reviews/reviews-limits/query', $parameters, $args);
23
+        return apply_filters( 'site-reviews/reviews-limits/query', $parameters, $args );
24 24
     }
25 25
 
26 26
     /**
27 27
      * @return bool
28 28
      */
29
-    public function hasReachedLimit(array $request = [])
29
+    public function hasReachedLimit( array $request = [] )
30 30
     {
31 31
         $this->request = $request;
32 32
         $method = Helper::buildMethodName(
33
-            glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy'
33
+            glsr( OptionManager::class )->get( 'settings.submissions.limit' ), 'validateBy'
34 34
         );
35
-        return method_exists($this, $method)
36
-            ? !call_user_func([$this, $method])
35
+        return method_exists( $this, $method )
36
+            ? !call_user_func( [$this, $method] )
37 37
             : false;
38 38
     }
39 39
 
@@ -42,39 +42,39 @@  discard block
 block discarded – undo
42 42
      * @param string $whitelist
43 43
      * @return bool
44 44
      */
45
-    public function isWhitelisted($value, $whitelist)
45
+    public function isWhitelisted( $value, $whitelist )
46 46
     {
47
-        if (empty($whitelist)) {
47
+        if( empty($whitelist) ) {
48 48
             return false;
49 49
         }
50
-        return in_array($value, array_filter(explode("\n", $whitelist), 'trim'));
50
+        return in_array( $value, array_filter( explode( "\n", $whitelist ), 'trim' ) );
51 51
     }
52 52
 
53 53
     /**
54 54
      * @param string $whitelistName
55 55
      * @return string
56 56
      */
57
-    protected function getWhitelist($whitelistName)
57
+    protected function getWhitelist( $whitelistName )
58 58
     {
59
-        return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName);
59
+        return glsr( OptionManager::class )->get( 'settings.submissions.limit_whitelist.'.$whitelistName );
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return bool
64 64
      */
65
-    protected function validate($key, $value, $addMetaQuery = true)
65
+    protected function validate( $key, $value, $addMetaQuery = true )
66 66
     {
67
-        if ($this->isWhitelisted($value, $this->getWhitelist($key))) {
67
+        if( $this->isWhitelisted( $value, $this->getWhitelist( $key ) ) ) {
68 68
             return true;
69 69
         }
70
-        add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2);
71
-        $args = ['assigned_to' => Arr::get($this->request, 'assign_to')];
72
-        if ($addMetaQuery) {
70
+        add_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2 );
71
+        $args = ['assigned_to' => Arr::get( $this->request, 'assign_to' )];
72
+        if( $addMetaQuery ) {
73 73
             $args[$key] = $value;
74 74
         }
75
-        $reviews = glsr_get_reviews($args);
76
-        remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5);
77
-        return 0 === count($reviews);
75
+        $reviews = glsr_get_reviews( $args );
76
+        remove_filter( 'site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5 );
77
+        return 0 === count( $reviews );
78 78
     }
79 79
 
80 80
     /**
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
      */
83 83
     protected function validateByEmail()
84 84
     {
85
-        glsr_log()->debug('Email is: '.Arr::get($this->request, 'email'));
86
-        return $this->validate('email', Arr::get($this->request, 'email'));
85
+        glsr_log()->debug( 'Email is: '.Arr::get( $this->request, 'email' ) );
86
+        return $this->validate( 'email', Arr::get( $this->request, 'email' ) );
87 87
     }
88 88
 
89 89
     /**
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      */
92 92
     protected function validateByIpAddress()
93 93
     {
94
-        glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address'));
95
-        return $this->validate('ip_address', Arr::get($this->request, 'ip_address'));
94
+        glsr_log()->debug( 'IP Address is: '.Arr::get( $this->request, 'ip_address' ) );
95
+        return $this->validate( 'ip_address', Arr::get( $this->request, 'ip_address' ) );
96 96
     }
97 97
 
98 98
     /**
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
     protected function validateByUsername()
102 102
     {
103 103
         $user = wp_get_current_user();
104
-        if (!$user->exists()) {
104
+        if( !$user->exists() ) {
105 105
             return true;
106 106
         }
107
-        glsr_log()->debug('Username is: '.$user->user_login);
108
-        return $this->validate('username', $user->user_login, false);
107
+        glsr_log()->debug( 'Username is: '.$user->user_login );
108
+        return $this->validate( 'username', $user->user_login, false );
109 109
     }
110 110
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema/BaseType.php 2 patches
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -13,248 +13,248 @@
 block discarded – undo
13 13
 
14 14
 abstract class BaseType implements ArrayAccess, JsonSerializable, Type
15 15
 {
16
-    /**
17
-     * @var array
18
-     */
19
-    public $allowed = [];
16
+	/**
17
+	 * @var array
18
+	 */
19
+	public $allowed = [];
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    public $parents = [];
21
+	/**
22
+	 * @var array
23
+	 */
24
+	public $parents = [];
25 25
 
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $properties = [];
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $properties = [];
30 30
 
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $type;
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $type;
35 35
 
36
-    /**
37
-     * @param string $method
38
-     * @return static
39
-     */
40
-    public function __call($method, array $arguments)
41
-    {
42
-        return $this->setProperty($method, Arr::get($arguments, 0));
43
-    }
36
+	/**
37
+	 * @param string $method
38
+	 * @return static
39
+	 */
40
+	public function __call($method, array $arguments)
41
+	{
42
+		return $this->setProperty($method, Arr::get($arguments, 0));
43
+	}
44 44
 
45
-    /**
46
-     * @param string $type
47
-     */
48
-    public function __construct($type = null)
49
-    {
50
-        $this->type = !is_string($type)
51
-            ? (new ReflectionClass($this))->getShortName()
52
-            : $type;
53
-        $this->setAllowedProperties();
54
-    }
45
+	/**
46
+	 * @param string $type
47
+	 */
48
+	public function __construct($type = null)
49
+	{
50
+		$this->type = !is_string($type)
51
+			? (new ReflectionClass($this))->getShortName()
52
+			: $type;
53
+		$this->setAllowedProperties();
54
+	}
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    public function __toString()
60
-    {
61
-        return $this->toScript();
62
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	public function __toString()
60
+	{
61
+		return $this->toScript();
62
+	}
63 63
 
64
-    /**
65
-     * @return static
66
-     */
67
-    public function addProperties(array $properties)
68
-    {
69
-        foreach ($properties as $property => $value) {
70
-            $this->setProperty($property, $value);
71
-        }
72
-        return $this;
73
-    }
64
+	/**
65
+	 * @return static
66
+	 */
67
+	public function addProperties(array $properties)
68
+	{
69
+		foreach ($properties as $property => $value) {
70
+			$this->setProperty($property, $value);
71
+		}
72
+		return $this;
73
+	}
74 74
 
75
-    /**
76
-     * @return string
77
-     */
78
-    public function getContext()
79
-    {
80
-        return 'https://schema.org';
81
-    }
75
+	/**
76
+	 * @return string
77
+	 */
78
+	public function getContext()
79
+	{
80
+		return 'https://schema.org';
81
+	}
82 82
 
83
-    /**
84
-     * @return array
85
-     */
86
-    public function getProperties()
87
-    {
88
-        return $this->properties;
89
-    }
83
+	/**
84
+	 * @return array
85
+	 */
86
+	public function getProperties()
87
+	{
88
+		return $this->properties;
89
+	}
90 90
 
91
-    /**
92
-     * @param string $property
93
-     * @param mixed $default
94
-     * @return mixed
95
-     */
96
-    public function getProperty($property, $default = null)
97
-    {
98
-        return Arr::get($this->properties, $property, $default);
99
-    }
91
+	/**
92
+	 * @param string $property
93
+	 * @param mixed $default
94
+	 * @return mixed
95
+	 */
96
+	public function getProperty($property, $default = null)
97
+	{
98
+		return Arr::get($this->properties, $property, $default);
99
+	}
100 100
 
101
-    /**
102
-     * @return string
103
-     */
104
-    public function getType()
105
-    {
106
-        return $this->type;
107
-    }
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function getType()
105
+	{
106
+		return $this->type;
107
+	}
108 108
 
109
-    /**
110
-     * @param bool $condition
111
-     * @param mixed $callback
112
-     * @return static
113
-     */
114
-    public function doIf($condition, $callback)
115
-    {
116
-        if ($condition) {
117
-            $callback($this);
118
-        }
119
-        return $this;
120
-    }
109
+	/**
110
+	 * @param bool $condition
111
+	 * @param mixed $callback
112
+	 * @return static
113
+	 */
114
+	public function doIf($condition, $callback)
115
+	{
116
+		if ($condition) {
117
+			$callback($this);
118
+		}
119
+		return $this;
120
+	}
121 121
 
122
-    /**
123
-     * @return array
124
-     */
125
-    public function jsonSerialize()
126
-    {
127
-        return $this->toArray();
128
-    }
122
+	/**
123
+	 * @return array
124
+	 */
125
+	public function jsonSerialize()
126
+	{
127
+		return $this->toArray();
128
+	}
129 129
 
130
-    /**
131
-     * @param mixed $offset
132
-     * @return bool
133
-     */
134
-    public function offsetExists($offset)
135
-    {
136
-        return array_key_exists($offset, $this->properties);
137
-    }
130
+	/**
131
+	 * @param mixed $offset
132
+	 * @return bool
133
+	 */
134
+	public function offsetExists($offset)
135
+	{
136
+		return array_key_exists($offset, $this->properties);
137
+	}
138 138
 
139
-    /**
140
-     * @param string $offset
141
-     * @return mixed
142
-     */
143
-    public function offsetGet($offset)
144
-    {
145
-        return $this->getProperty($offset);
146
-    }
139
+	/**
140
+	 * @param string $offset
141
+	 * @return mixed
142
+	 */
143
+	public function offsetGet($offset)
144
+	{
145
+		return $this->getProperty($offset);
146
+	}
147 147
 
148
-    /**
149
-     * @param string $offset
150
-     * @param mixed $value
151
-     * @return void
152
-     */
153
-    public function offsetSet($offset, $value)
154
-    {
155
-        $this->setProperty($offset, $value);
156
-    }
148
+	/**
149
+	 * @param string $offset
150
+	 * @param mixed $value
151
+	 * @return void
152
+	 */
153
+	public function offsetSet($offset, $value)
154
+	{
155
+		$this->setProperty($offset, $value);
156
+	}
157 157
 
158
-    /**
159
-     * @param string $offset
160
-     * @return void
161
-     */
162
-    public function offsetUnset($offset)
163
-    {
164
-        unset($this->properties[$offset]);
165
-    }
158
+	/**
159
+	 * @param string $offset
160
+	 * @return void
161
+	 */
162
+	public function offsetUnset($offset)
163
+	{
164
+		unset($this->properties[$offset]);
165
+	}
166 166
 
167
-    /**
168
-     * @param string $property
169
-     * @param mixed $value
170
-     * @return static
171
-     */
172
-    public function setProperty($property, $value)
173
-    {
174
-        if (!in_array($property, $this->allowed)
175
-            && 'UnknownType' != (new ReflectionClass($this))->getShortName()) {
176
-            glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property');
177
-            return $this;
178
-        }
179
-        $this->properties[$property] = $value;
180
-        return $this;
181
-    }
167
+	/**
168
+	 * @param string $property
169
+	 * @param mixed $value
170
+	 * @return static
171
+	 */
172
+	public function setProperty($property, $value)
173
+	{
174
+		if (!in_array($property, $this->allowed)
175
+			&& 'UnknownType' != (new ReflectionClass($this))->getShortName()) {
176
+			glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property');
177
+			return $this;
178
+		}
179
+		$this->properties[$property] = $value;
180
+		return $this;
181
+	}
182 182
 
183
-    /**
184
-     * @return array
185
-     */
186
-    public function toArray()
187
-    {
188
-        return [
189
-            '@context' => $this->getContext(),
190
-            '@type' => $this->getType(),
191
-        ] + $this->serializeProperty($this->getProperties());
192
-    }
183
+	/**
184
+	 * @return array
185
+	 */
186
+	public function toArray()
187
+	{
188
+		return [
189
+			'@context' => $this->getContext(),
190
+			'@type' => $this->getType(),
191
+		] + $this->serializeProperty($this->getProperties());
192
+	}
193 193
 
194
-    /**
195
-     * @return string
196
-     */
197
-    public function toScript()
198
-    {
199
-        return sprintf('<script type="application/ld+json">%s</script>',
200
-            json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
201
-        );
202
-    }
194
+	/**
195
+	 * @return string
196
+	 */
197
+	public function toScript()
198
+	{
199
+		return sprintf('<script type="application/ld+json">%s</script>',
200
+			json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
201
+		);
202
+	}
203 203
 
204
-    /**
205
-     * @param array|null $parents
206
-     * @return array
207
-     */
208
-    protected function getParents($parents = null)
209
-    {
210
-        if (!isset($parents)) {
211
-            $parents = $this->parents;
212
-        }
213
-        $newParents = $parents;
214
-        foreach ($parents as $parent) {
215
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
216
-            if (!class_exists($parentClass)) {
217
-                continue;
218
-            }
219
-            $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents));
220
-        }
221
-        return array_values(array_unique($newParents));
222
-    }
204
+	/**
205
+	 * @param array|null $parents
206
+	 * @return array
207
+	 */
208
+	protected function getParents($parents = null)
209
+	{
210
+		if (!isset($parents)) {
211
+			$parents = $this->parents;
212
+		}
213
+		$newParents = $parents;
214
+		foreach ($parents as $parent) {
215
+			$parentClass = Helper::buildClassName($parent, __NAMESPACE__);
216
+			if (!class_exists($parentClass)) {
217
+				continue;
218
+			}
219
+			$newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents));
220
+		}
221
+		return array_values(array_unique($newParents));
222
+	}
223 223
 
224
-    /**
225
-     * @return void
226
-     */
227
-    protected function setAllowedProperties()
228
-    {
229
-        $parents = $this->getParents();
230
-        foreach ($parents as $parent) {
231
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
232
-            if (!class_exists($parentClass)) {
233
-                continue;
234
-            }
235
-            $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed)));
236
-        }
237
-    }
224
+	/**
225
+	 * @return void
226
+	 */
227
+	protected function setAllowedProperties()
228
+	{
229
+		$parents = $this->getParents();
230
+		foreach ($parents as $parent) {
231
+			$parentClass = Helper::buildClassName($parent, __NAMESPACE__);
232
+			if (!class_exists($parentClass)) {
233
+				continue;
234
+			}
235
+			$this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed)));
236
+		}
237
+	}
238 238
 
239
-    /**
240
-     * @param mixed $property
241
-     * @return array|string
242
-     */
243
-    protected function serializeProperty($property)
244
-    {
245
-        if (is_array($property)) {
246
-            return array_map([$this, 'serializeProperty'], $property);
247
-        }
248
-        if ($property instanceof Type) {
249
-            $property = $property->toArray();
250
-            unset($property['@context']);
251
-        }
252
-        if ($property instanceof DateTimeInterface) {
253
-            $property = $property->format(DateTime::ATOM);
254
-        }
255
-        if (is_object($property)) {
256
-            throw new InvalidProperty();
257
-        }
258
-        return $property;
259
-    }
239
+	/**
240
+	 * @param mixed $property
241
+	 * @return array|string
242
+	 */
243
+	protected function serializeProperty($property)
244
+	{
245
+		if (is_array($property)) {
246
+			return array_map([$this, 'serializeProperty'], $property);
247
+		}
248
+		if ($property instanceof Type) {
249
+			$property = $property->toArray();
250
+			unset($property['@context']);
251
+		}
252
+		if ($property instanceof DateTimeInterface) {
253
+			$property = $property->format(DateTime::ATOM);
254
+		}
255
+		if (is_object($property)) {
256
+			throw new InvalidProperty();
257
+		}
258
+		return $property;
259
+	}
260 260
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -37,18 +37,18 @@  discard block
 block discarded – undo
37 37
      * @param string $method
38 38
      * @return static
39 39
      */
40
-    public function __call($method, array $arguments)
40
+    public function __call( $method, array $arguments )
41 41
     {
42
-        return $this->setProperty($method, Arr::get($arguments, 0));
42
+        return $this->setProperty( $method, Arr::get( $arguments, 0 ) );
43 43
     }
44 44
 
45 45
     /**
46 46
      * @param string $type
47 47
      */
48
-    public function __construct($type = null)
48
+    public function __construct( $type = null )
49 49
     {
50
-        $this->type = !is_string($type)
51
-            ? (new ReflectionClass($this))->getShortName()
50
+        $this->type = !is_string( $type )
51
+            ? (new ReflectionClass( $this ))->getShortName()
52 52
             : $type;
53 53
         $this->setAllowedProperties();
54 54
     }
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
     /**
65 65
      * @return static
66 66
      */
67
-    public function addProperties(array $properties)
67
+    public function addProperties( array $properties )
68 68
     {
69
-        foreach ($properties as $property => $value) {
70
-            $this->setProperty($property, $value);
69
+        foreach( $properties as $property => $value ) {
70
+            $this->setProperty( $property, $value );
71 71
         }
72 72
         return $this;
73 73
     }
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
      * @param mixed $default
94 94
      * @return mixed
95 95
      */
96
-    public function getProperty($property, $default = null)
96
+    public function getProperty( $property, $default = null )
97 97
     {
98
-        return Arr::get($this->properties, $property, $default);
98
+        return Arr::get( $this->properties, $property, $default );
99 99
     }
100 100
 
101 101
     /**
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
      * @param mixed $callback
112 112
      * @return static
113 113
      */
114
-    public function doIf($condition, $callback)
114
+    public function doIf( $condition, $callback )
115 115
     {
116
-        if ($condition) {
117
-            $callback($this);
116
+        if( $condition ) {
117
+            $callback( $this );
118 118
         }
119 119
         return $this;
120 120
     }
@@ -131,18 +131,18 @@  discard block
 block discarded – undo
131 131
      * @param mixed $offset
132 132
      * @return bool
133 133
      */
134
-    public function offsetExists($offset)
134
+    public function offsetExists( $offset )
135 135
     {
136
-        return array_key_exists($offset, $this->properties);
136
+        return array_key_exists( $offset, $this->properties );
137 137
     }
138 138
 
139 139
     /**
140 140
      * @param string $offset
141 141
      * @return mixed
142 142
      */
143
-    public function offsetGet($offset)
143
+    public function offsetGet( $offset )
144 144
     {
145
-        return $this->getProperty($offset);
145
+        return $this->getProperty( $offset );
146 146
     }
147 147
 
148 148
     /**
@@ -150,16 +150,16 @@  discard block
 block discarded – undo
150 150
      * @param mixed $value
151 151
      * @return void
152 152
      */
153
-    public function offsetSet($offset, $value)
153
+    public function offsetSet( $offset, $value )
154 154
     {
155
-        $this->setProperty($offset, $value);
155
+        $this->setProperty( $offset, $value );
156 156
     }
157 157
 
158 158
     /**
159 159
      * @param string $offset
160 160
      * @return void
161 161
      */
162
-    public function offsetUnset($offset)
162
+    public function offsetUnset( $offset )
163 163
     {
164 164
         unset($this->properties[$offset]);
165 165
     }
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
      * @param mixed $value
170 170
      * @return static
171 171
      */
172
-    public function setProperty($property, $value)
172
+    public function setProperty( $property, $value )
173 173
     {
174
-        if (!in_array($property, $this->allowed)
175
-            && 'UnknownType' != (new ReflectionClass($this))->getShortName()) {
176
-            glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property');
174
+        if( !in_array( $property, $this->allowed )
175
+            && 'UnknownType' != (new ReflectionClass( $this ))->getShortName() ) {
176
+            glsr_log()->warning( $this->getType().' does not allow the "'.$property.'" property' );
177 177
             return $this;
178 178
         }
179 179
         $this->properties[$property] = $value;
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         return [
189 189
             '@context' => $this->getContext(),
190 190
             '@type' => $this->getType(),
191
-        ] + $this->serializeProperty($this->getProperties());
191
+        ] + $this->serializeProperty( $this->getProperties() );
192 192
     }
193 193
 
194 194
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
      */
197 197
     public function toScript()
198 198
     {
199
-        return sprintf('<script type="application/ld+json">%s</script>',
200
-            json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
199
+        return sprintf( '<script type="application/ld+json">%s</script>',
200
+            json_encode( $this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES )
201 201
         );
202 202
     }
203 203
 
@@ -205,20 +205,20 @@  discard block
 block discarded – undo
205 205
      * @param array|null $parents
206 206
      * @return array
207 207
      */
208
-    protected function getParents($parents = null)
208
+    protected function getParents( $parents = null )
209 209
     {
210
-        if (!isset($parents)) {
210
+        if( !isset($parents) ) {
211 211
             $parents = $this->parents;
212 212
         }
213 213
         $newParents = $parents;
214
-        foreach ($parents as $parent) {
215
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
216
-            if (!class_exists($parentClass)) {
214
+        foreach( $parents as $parent ) {
215
+            $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ );
216
+            if( !class_exists( $parentClass ) ) {
217 217
                 continue;
218 218
             }
219
-            $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents));
219
+            $newParents = array_merge( $newParents, $this->getParents( (new $parentClass())->parents ) );
220 220
         }
221
-        return array_values(array_unique($newParents));
221
+        return array_values( array_unique( $newParents ) );
222 222
     }
223 223
 
224 224
     /**
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
     protected function setAllowedProperties()
228 228
     {
229 229
         $parents = $this->getParents();
230
-        foreach ($parents as $parent) {
231
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
232
-            if (!class_exists($parentClass)) {
230
+        foreach( $parents as $parent ) {
231
+            $parentClass = Helper::buildClassName( $parent, __NAMESPACE__ );
232
+            if( !class_exists( $parentClass ) ) {
233 233
                 continue;
234 234
             }
235
-            $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed)));
235
+            $this->allowed = array_values( array_unique( array_merge( (new $parentClass())->allowed, $this->allowed ) ) );
236 236
         }
237 237
     }
238 238
 
@@ -240,19 +240,19 @@  discard block
 block discarded – undo
240 240
      * @param mixed $property
241 241
      * @return array|string
242 242
      */
243
-    protected function serializeProperty($property)
243
+    protected function serializeProperty( $property )
244 244
     {
245
-        if (is_array($property)) {
246
-            return array_map([$this, 'serializeProperty'], $property);
245
+        if( is_array( $property ) ) {
246
+            return array_map( [$this, 'serializeProperty'], $property );
247 247
         }
248
-        if ($property instanceof Type) {
248
+        if( $property instanceof Type ) {
249 249
             $property = $property->toArray();
250 250
             unset($property['@context']);
251 251
         }
252
-        if ($property instanceof DateTimeInterface) {
253
-            $property = $property->format(DateTime::ATOM);
252
+        if( $property instanceof DateTimeInterface ) {
253
+            $property = $property->format( DateTime::ATOM );
254 254
         }
255
-        if (is_object($property)) {
255
+        if( is_object( $property ) ) {
256 256
             throw new InvalidProperty();
257 257
         }
258 258
         return $property;
Please login to merge, or discard this patch.