Passed
Push — develop ( 9b346b...48f539 )
by Paul
12:10
created
src/MetaBox/MetaBox.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -24,20 +24,20 @@  discard block
 block discarded – undo
24 24
 	/**
25 25
 	 * @var array
26 26
 	 */
27
-	public $metaboxes = [];
27
+	public $metaboxes = [ ];
28 28
 
29 29
 	/**
30 30
 	 * {@inheritdoc}
31 31
 	 */
32 32
 	public function init()
33 33
 	{
34
-		$this->normalize( $this->app->config[static::ID], [
35
-			'post_types' => [],
36
-		]);
34
+		$this->normalize( $this->app->config[ static::ID ], [
35
+			'post_types' => [ ],
36
+		] );
37 37
 
38
-		add_filter( 'rwmb_show',       [$this, 'show'], 10, 2 );
39
-		add_filter( 'rwmb_meta_boxes', [$this, 'register'] );
40
-		add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 );
38
+		add_filter( 'rwmb_show', [ $this, 'show' ], 10, 2 );
39
+		add_filter( 'rwmb_meta_boxes', [ $this, 'register' ] );
40
+		add_filter( 'rwmb_outer_html', [ $this, 'renderField' ], 10, 2 );
41 41
 	}
42 42
 
43 43
 	/**
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function register()
68 68
 	{
69
-		if( current_user_can( 'switch_themes' )) {
69
+		if( current_user_can( 'switch_themes' ) ) {
70 70
 			$this->addInstructions();
71 71
 		}
72 72
 		$metaboxes = func_num_args()
73
-			? ( new Helper )->toArray( func_get_arg(0) )
74
-			: [];
73
+			? ( new Helper )->toArray( func_get_arg( 0 ) )
74
+			: [ ];
75 75
 		return array_merge( $metaboxes, $this->metaboxes );
76 76
 	}
77 77
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public function renderField( $html, $field )
83 83
 	{
84
-		return $this->validate( $field['condition'] )
84
+		return $this->validate( $field[ 'condition' ] )
85 85
 			? $html
86 86
 			: '';
87 87
 	}
@@ -93,11 +93,11 @@  discard block
 block discarded – undo
93 93
 	public function show( $bool, array $metabox )
94 94
 	{
95 95
 		if( defined( 'DOING_AJAX' )
96
-			|| !isset( $metabox['condition'] )
97
-			|| !$this->hasPostType( $metabox )) {
96
+			|| !isset( $metabox[ 'condition' ] )
97
+			|| !$this->hasPostType( $metabox ) ) {
98 98
 			return $bool;
99 99
 		}
100
-		return $this->validate( $metabox['condition'] );
100
+		return $this->validate( $metabox[ 'condition' ] );
101 101
 	}
102 102
 
103 103
 	/**
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	protected function getPostId()
107 107
 	{
108
-		if( !( $postId = filter_input( INPUT_GET, 'post' ))) {
108
+		if( !( $postId = filter_input( INPUT_GET, 'post' ) ) ) {
109 109
 			$postId = filter_input( INPUT_POST, 'post_ID' );
110 110
 		}
111 111
 		return intval( $postId );
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 	{
119 119
 		return array_unique( iterator_to_array(
120 120
 			new RecursiveIteratorIterator(
121
-				new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ))
121
+				new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) )
122 122
 			),
123 123
 			false
124
-		));
124
+		) );
125 125
 	}
126 126
 
127 127
 	/**
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 	{
132 132
 		return PostMeta::get( $key, [
133 133
 			'id' => $this->getPostId(),
134
-		]);
134
+		] );
135 135
 	}
136 136
 
137 137
 	/**
@@ -139,26 +139,26 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	protected function hasPostType( array $metabox )
141 141
 	{
142
-		if( !isset( $metabox['post_types'] )) {
142
+		if( !isset( $metabox[ 'post_types' ] ) ) {
143 143
 			return true;
144 144
 		}
145
-		return in_array( get_post_type( $this->getPostId() ), $metabox['post_types'] );
145
+		return in_array( get_post_type( $this->getPostId() ), $metabox[ 'post_types' ] );
146 146
 	}
147 147
 
148 148
 	/**
149 149
 	 * @return void
150 150
 	 */
151
-	protected function normalize( array $metaboxes, array $defaults = [] )
151
+	protected function normalize( array $metaboxes, array $defaults = [ ] )
152 152
 	{
153 153
 		foreach( $metaboxes as $id => $metabox ) {
154 154
 			$data = wp_parse_args( $defaults, [
155
-				'condition' => [],
156
-				'fields' => [],
155
+				'condition' => [ ],
156
+				'fields' => [ ],
157 157
 				'id' => $id,
158 158
 				'slug' => $id,
159
-				'validation' => [],
160
-			]);
161
-			$this->metaboxes[] = $this->setDependencies(
159
+				'validation' => [ ],
160
+			] );
161
+			$this->metaboxes[ ] = $this->setDependencies(
162 162
 				$this->normalizeThis( $metabox, $data, $id )
163 163
 			);
164 164
 		}
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
 	protected function normalizeFields( array $fields, array $data, $parentId )
193 193
 	{
194 194
 		return array_map( function( $id, $field ) use( $parentId ) {
195
-			$defaults =  [
196
-				'attributes' => [],
195
+			$defaults = [
196
+				'attributes' => [ ],
197 197
 				'class' => '',
198
-				'condition' => [],
198
+				'condition' => [ ],
199 199
 				'depends' => '',
200 200
 				'field_name' => $id,
201 201
 				'id' => $id,
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
 	 */
230 230
 	protected function normalizeValidation( array $validation, array $data, $parentId )
231 231
 	{
232
-		foreach( ['messages', 'rules'] as $key ) {
233
-			if( empty( $validation[$key] ))continue;
234
-			foreach( $validation[$key] as $id => $value ) {
235
-				$validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value;
236
-				unset( $validation[$key][$id] );
232
+		foreach( [ 'messages', 'rules' ] as $key ) {
233
+			if( empty( $validation[ $key ] ) )continue;
234
+			foreach( $validation[ $key ] as $id => $value ) {
235
+				$validation[ $key ][ $this->normalizeFieldName( $id, [ 'slug' => $id ], $parentId ) ] = $value;
236
+				unset( $validation[ $key ][ $id ] );
237 237
 			}
238 238
 		}
239 239
 		return $validation;
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
 	 */
245 245
 	protected function setDependencies( array $metabox )
246 246
 	{
247
-		$fields = &$metabox['fields'];
247
+		$fields = &$metabox[ 'fields' ];
248 248
 		$depends = array_column( $fields, 'depends' );
249 249
 		array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) {
250
-			if( empty( $value ))return;
251
-			$dependency = array_search( $value, array_column( $fields, 'id' ));
252
-			$fields[$index]['attributes']['data-depends'] = $value;
253
-			if( !$this->getValue( $fields[$dependency]['slug'], $metabox['slug'] )) {
254
-				$fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] );
250
+			if( empty( $value ) )return;
251
+			$dependency = array_search( $value, array_column( $fields, 'id' ) );
252
+			$fields[ $index ][ 'attributes' ][ 'data-depends' ] = $value;
253
+			if( !$this->getValue( $fields[ $dependency ][ 'slug' ], $metabox[ 'slug' ] ) ) {
254
+				$fields[ $index ][ 'class' ] = trim( 'hidden ' . $fields[ $index ][ 'class' ] );
255 255
 			}
256 256
 		});
257 257
 		return $metabox;
Please login to merge, or discard this patch.
src/Settings/Settings.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -44,16 +44,16 @@  discard block
 block discarded – undo
44 44
 		// @todo: run GateKeeper to check dependencies and capability (make sure it it run on the correct hook!)
45 45
 		// if( !is_plugin_active( 'meta-box/meta-box.php' ))return;
46 46
 
47
-		$this->normalize( $this->app->config[static::ID] );
47
+		$this->normalize( $this->app->config[ static::ID ] );
48 48
 
49
-		add_action( 'admin_menu',                                [$this, 'addPage'] );
50
-		add_action( 'pollux/'.static::ID.'/init',                [$this, 'addSubmitMetaBox'] );
51
-		add_action( 'current_screen',                            [$this, 'register'] );
52
-		add_action( 'admin_menu',                                [$this, 'registerSetting'] );
53
-		add_action( 'pollux/'.static::ID.'/init',                [$this, 'reset'] );
54
-		add_action( 'admin_print_footer_scripts',                [$this, 'renderFooterScript'] );
55
-		add_filter( 'pollux/'.static::ID.'/instruction',         [$this, 'filterInstruction'], 10, 3 );
56
-		add_filter( 'pollux/'.static::ID.'/before/instructions', [$this, 'filterBeforeInstructions'] );
49
+		add_action( 'admin_menu', [ $this, 'addPage' ] );
50
+		add_action( 'pollux/' . static::ID . '/init', [ $this, 'addSubmitMetaBox' ] );
51
+		add_action( 'current_screen', [ $this, 'register' ] );
52
+		add_action( 'admin_menu', [ $this, 'registerSetting' ] );
53
+		add_action( 'pollux/' . static::ID . '/init', [ $this, 'reset' ] );
54
+		add_action( 'admin_print_footer_scripts', [ $this, 'renderFooterScript' ] );
55
+		add_filter( 'pollux/' . static::ID . '/instruction', [ $this, 'filterInstruction' ], 10, 3 );
56
+		add_filter( 'pollux/' . static::ID . '/before/instructions', [ $this, 'filterBeforeInstructions' ] );
57 57
 	}
58 58
 
59 59
 	/**
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 			__( 'Site Settings', 'pollux' ),
68 68
 			'edit_theme_options',
69 69
 			static::id(),
70
-			[$this, 'renderPage'],
70
+			[ $this, 'renderPage' ],
71 71
 			'dashicons-screenoptions',
72 72
 			1313
73
-		]));
73
+		] ) );
74 74
 	}
75 75
 
76 76
 	/**
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 		call_user_func_array( 'add_meta_box', $this->filter( 'metabox/submit', [
83 83
 			'submitdiv',
84 84
 			__( 'Save Settings', 'pollux' ),
85
-			[$this, 'renderSubmitMetaBox'],
85
+			[ $this, 'renderSubmitMetaBox' ],
86 86
 			$this->hook,
87 87
 			'side',
88 88
 			'high',
89
-		]));
89
+		] ) );
90 90
 	}
91 91
 
92 92
 	/**
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 */
106 106
 	public function filterInstruction( $instruction, array $field, array $metabox )
107 107
 	{
108
-		return sprintf( "SiteMeta::%s('%s');", $metabox['slug'], $field['slug'] );
108
+		return sprintf( "SiteMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] );
109 109
 	}
110 110
 
111 111
 	/**
@@ -115,10 +115,10 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 	public function filterSavedSettings( $settings )
117 117
 	{
118
-		if( is_null( $settings )) {
119
-			$settings = [];
118
+		if( is_null( $settings ) ) {
119
+			$settings = [ ];
120 120
 		}
121
-		return $this->filter( 'save', array_merge( $settings, $this->getSettings() ));
121
+		return $this->filter( 'save', array_merge( $settings, $this->getSettings() ) );
122 122
 	}
123 123
 
124 124
 	/**
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	public function register()
129 129
 	{
130
-		if(( new Helper )->getCurrentScreen()->id != $this->hook )return;
130
+		if( ( new Helper )->getCurrentScreen()->id != $this->hook )return;
131 131
 		foreach( parent::register() as $metabox ) {
132 132
 			new RWMetaBox( $metabox, static::ID, $this->hook );
133 133
 		}
134 134
 		add_screen_option( 'layout_columns', [
135 135
 			'max' => 2,
136 136
 			'default' => 2,
137
-		]);
137
+		] );
138 138
 		$this->action( 'init' );
139 139
 	}
140 140
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function registerSetting()
146 146
 	{
147
-		register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] );
147
+		register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] );
148 148
 	}
149 149
 
150 150
 	/**
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 	 */
154 154
 	public function renderFooterScript()
155 155
 	{
156
-		if(( new Helper )->getCurrentScreen()->id != $this->hook )return;
156
+		if( ( new Helper )->getCurrentScreen()->id != $this->hook )return;
157 157
 		$this->render( 'settings/script', [
158 158
 			'confirm' => __( 'Are you sure want to do this?', 'pollux' ),
159 159
 			'hook' => $this->hook,
160 160
 			'id' => static::id(),
161
-		]);
161
+		] );
162 162
 	}
163 163
 
164 164
 	/**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 			'columns' => get_current_screen()->get_columns(),
172 172
 			'heading' => __( 'Site Settings', 'pollux' ),
173 173
 			'id' => static::id(),
174
-		]);
174
+		] );
175 175
 	}
176 176
 
177 177
 	/**
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 		];
189 189
 		$this->render( 'settings/submit', [
190 190
 			'reset' => __( 'Reset all', 'pollux' ),
191
-			'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ))),
191
+			'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ) ) ),
192 192
 			'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ),
193
-		]);
193
+		] );
194 194
 	}
195 195
 
196 196
 	/**
@@ -202,15 +202,15 @@  discard block
 block discarded – undo
202 202
 		if( filter_input( INPUT_GET, 'page' ) !== static::id()
203 203
 			|| filter_input( INPUT_GET, 'action' ) !== 'reset'
204 204
 		)return;
205
-		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) {
205
+		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) {
206 206
 			update_option( static::id(), $this->getDefaults() );
207 207
 			add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' );
208 208
 		}
209 209
 		else {
210
-			add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ));
210
+			add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ) );
211 211
 		}
212 212
 		set_transient( 'settings_errors', get_settings_errors(), 30 );
213
-		wp_safe_redirect( add_query_arg( 'settings-updated', 'true',  wp_get_referer() ));
213
+		wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() ) );
214 214
 		exit;
215 215
 	}
216 216
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 	protected function filterArrayByKey( array $array, $key )
222 222
 	{
223 223
 		return array_filter( $array, function( $value ) use( $key ) {
224
-			return !empty( $value[$key] );
224
+			return !empty( $value[ $key ] );
225 225
 		});
226 226
 	}
227 227
 
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
 
235 235
 		array_walk( $metaboxes, function( &$metabox ) {
236 236
 			$fields = array_map( function( $field ) {
237
-				$field = wp_parse_args( $field, ['std' => ''] );
238
-				return [$field['slug'] => $field['std']];
239
-			}, $this->filterArrayByKey( $metabox['fields'], 'slug' ));
237
+				$field = wp_parse_args( $field, [ 'std' => '' ] );
238
+				return [ $field[ 'slug' ] => $field[ 'std' ] ];
239
+			}, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) );
240 240
 			$metabox = [
241
-				$metabox['slug'] => call_user_func_array( 'array_merge', $fields ),
241
+				$metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ),
242 242
 			];
243 243
 		});
244 244
 		return call_user_func_array( 'array_merge', $metaboxes );
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	 */
265 265
 	protected function normalizeFieldName( $name, array $data, $parentId )
266 266
 	{
267
-		return sprintf( '%s[%s][%s]', static::id(), $parentId, $data['slug'] );
267
+		return sprintf( '%s[%s][%s]', static::id(), $parentId, $data[ 'slug' ] );
268 268
 	}
269 269
 
270 270
 	/**
Please login to merge, or discard this patch.