Passed
Push — develop ( eab4f1...a47963 )
by Paul
03:10
created
src/Settings/Settings.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
 
43 43
 		$this->normalize( $this->app->config->{static::ID} );
44 44
 
45
-		add_action( 'pollux/'.static::ID.'/init',                [$this, 'addSubmitMetaBox'] );
46
-		add_action( 'current_screen',                            [$this, 'register'] );
47
-		add_action( 'admin_menu',                                [$this, 'registerPage'] );
48
-		add_action( 'admin_menu',                                [$this, 'registerSetting'] );
49
-		add_action( 'pollux/'.static::ID.'/init',                [$this, 'resetPage'] );
50
-		add_action( 'admin_print_footer_scripts',                [$this, 'renderFooterScript'] );
51
-		add_filter( 'pollux/'.static::ID.'/instruction',         [$this, 'filterInstruction'], 10, 3 );
52
-		add_filter( 'pollux/'.static::ID.'/before/instructions', [$this, 'filterBeforeInstructions'] );
45
+		add_action( 'pollux/' . static::ID . '/init', [ $this, 'addSubmitMetaBox' ] );
46
+		add_action( 'current_screen', [ $this, 'register' ] );
47
+		add_action( 'admin_menu', [ $this, 'registerPage' ] );
48
+		add_action( 'admin_menu', [ $this, 'registerSetting' ] );
49
+		add_action( 'pollux/' . static::ID . '/init', [ $this, 'resetPage' ] );
50
+		add_action( 'admin_print_footer_scripts', [ $this, 'renderFooterScript' ] );
51
+		add_filter( 'pollux/' . static::ID . '/instruction', [ $this, 'filterInstruction' ], 10, 3 );
52
+		add_filter( 'pollux/' . static::ID . '/before/instructions', [ $this, 'filterBeforeInstructions' ] );
53 53
 	}
54 54
 
55 55
 	public function canProceed()
@@ -67,11 +67,11 @@  discard block
 block discarded – undo
67 67
 		call_user_func_array( 'add_meta_box', $this->filter( 'metabox/submit', [
68 68
 			'submitdiv',
69 69
 			__( 'Save Settings', 'pollux' ),
70
-			[$this, 'renderSubmitMetaBox'],
70
+			[ $this, 'renderSubmitMetaBox' ],
71 71
 			$this->hook,
72 72
 			'side',
73 73
 			'high',
74
-		]));
74
+		] ) );
75 75
 	}
76 76
 
77 77
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 */
91 91
 	public function filterInstruction( $instruction, array $field, array $metabox )
92 92
 	{
93
-		return sprintf( "SiteMeta::%s('%s');", $metabox['slug'], $field['slug'] );
93
+		return sprintf( "SiteMeta::%s('%s');", $metabox[ 'slug' ], $field[ 'slug' ] );
94 94
 	}
95 95
 
96 96
 	/**
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	public function filterSavedSettings( $settings )
102 102
 	{
103
-		if( is_null( $settings )) {
104
-			$settings = [];
103
+		if( is_null( $settings ) ) {
104
+			$settings = [ ];
105 105
 		}
106 106
 		return $this->filter( 'save', array_merge(
107 107
 			array_intersect_key( $this->getSettings(), $settings ),
108 108
 			$settings
109
-		));
109
+		) );
110 110
 	}
111 111
 
112 112
 	/**
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 	 */
127 127
 	public function register()
128 128
 	{
129
-		if(( new Helper )->getCurrentScreen()->id != $this->hook )return;
130
-		if( $this->app->gatekeeper->hasDependency( self::DEPENDENCY )) {
129
+		if( ( new Helper )->getCurrentScreen()->id != $this->hook )return;
130
+		if( $this->app->gatekeeper->hasDependency( self::DEPENDENCY ) ) {
131 131
 			foreach( parent::register() as $metabox ) {
132 132
 				new RWMetaBox( $metabox, static::ID, $this );
133 133
 			}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 		add_screen_option( 'layout_columns', [
136 136
 			'max' => 2,
137 137
 			'default' => 2,
138
-		]);
138
+		] );
139 139
 		$this->action( 'init' );
140 140
 	}
141 141
 
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 			__( 'Site Settings', 'pollux' ),
151 151
 			static::CAPABILITY,
152 152
 			static::id(),
153
-			[$this, 'renderPage'],
153
+			[ $this, 'renderPage' ],
154 154
 			'dashicons-screenoptions',
155 155
 			1313
156
-		]));
156
+		] ) );
157 157
 	}
158 158
 
159 159
 	/**
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 */
163 163
 	public function registerSetting()
164 164
 	{
165
-		register_setting( static::id(), static::id(), [$this, 'filterSavedSettings'] );
165
+		register_setting( static::id(), static::id(), [ $this, 'filterSavedSettings' ] );
166 166
 	}
167 167
 
168 168
 	/**
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
 	 */
172 172
 	public function renderFooterScript()
173 173
 	{
174
-		if(( new Helper )->getCurrentScreen()->id != $this->hook )return;
174
+		if( ( new Helper )->getCurrentScreen()->id != $this->hook )return;
175 175
 		$this->app->render( 'settings/script', [
176 176
 			'confirm' => __( 'Are you sure want to do this?', 'pollux' ),
177 177
 			'hook' => $this->hook,
178 178
 			'id' => static::id(),
179
-		]);
179
+		] );
180 180
 	}
181 181
 
182 182
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			'columns' => get_current_screen()->get_columns(),
190 190
 			'heading' => __( 'Site Settings', 'pollux' ),
191 191
 			'id' => static::id(),
192
-		]);
192
+		] );
193 193
 	}
194 194
 
195 195
 	/**
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 		];
207 207
 		$this->app->render( 'settings/submit', [
208 208
 			'reset' => __( 'Reset all', 'pollux' ),
209
-			'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ))),
209
+			'reset_url' => esc_url( add_query_arg( $query, admin_url( $pagenow ) ) ),
210 210
 			'submit' => get_submit_button( __( 'Save', 'pollux' ), 'primary', 'submit', false ),
211
-		]);
211
+		] );
212 212
 	}
213 213
 
214 214
 	/**
@@ -220,15 +220,15 @@  discard block
 block discarded – undo
220 220
 		if( filter_input( INPUT_GET, 'page' ) !== static::id()
221 221
 			|| filter_input( INPUT_GET, 'action' ) !== 'reset'
222 222
 		)return;
223
-		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook )) {
223
+		if( wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), $this->hook ) ) {
224 224
 			update_option( static::id(), $this->getDefaults() );
225 225
 			add_settings_error( static::id(), 'reset', __( 'Reset successful.', 'pollux' ), 'updated' );
226 226
 		}
227 227
 		else {
228
-			add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ));
228
+			add_settings_error( static::id(), 'failed', __( 'Failed to reset. Please try again.', 'pollux' ) );
229 229
 		}
230 230
 		set_transient( 'settings_errors', get_settings_errors(), 30 );
231
-		wp_safe_redirect( add_query_arg( 'settings-updated', 'true',  wp_get_referer() ));
231
+		wp_safe_redirect( add_query_arg( 'settings-updated', 'true', wp_get_referer() ) );
232 232
 		exit;
233 233
 	}
234 234
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 	protected function filterArrayByKey( array $array, $key )
240 240
 	{
241 241
 		return array_filter( $array, function( $value ) use( $key ) {
242
-			return !empty( $value[$key] );
242
+			return !empty( $value[ $key ] );
243 243
 		});
244 244
 	}
245 245
 
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
 
253 253
 		array_walk( $metaboxes, function( &$metabox ) {
254 254
 			$fields = array_map( function( $field ) {
255
-				$field = wp_parse_args( $field, ['std' => ''] );
256
-				return [$field['slug'] => $field['std']];
257
-			}, $this->filterArrayByKey( $metabox['fields'], 'slug' ));
255
+				$field = wp_parse_args( $field, [ 'std' => '' ] );
256
+				return [ $field[ 'slug' ] => $field[ 'std' ] ];
257
+			}, $this->filterArrayByKey( $metabox[ 'fields' ], 'slug' ) );
258 258
 			$metabox = [
259
-				$metabox['slug'] => call_user_func_array( 'array_merge', $fields ),
259
+				$metabox[ 'slug' ] => call_user_func_array( 'array_merge', $fields ),
260 260
 			];
261 261
 		});
262 262
 		return call_user_func_array( 'array_merge', $metaboxes );
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	protected function normalizeFieldName( $name, array $data, $parentId )
276 276
 	{
277
-		return sprintf( '%s[%s][%s]', static::id(), $parentId, $data['slug'] );
277
+		return sprintf( '%s[%s][%s]', static::id(), $parentId, $data[ 'slug' ] );
278 278
 	}
279 279
 
280 280
 	/**
Please login to merge, or discard this patch.
src/Settings/RWMetaBox.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@  discard block
 block discarded – undo
19 19
 		$this->pollux_caller = $caller;
20 20
 		$this->pollux_id = $id;
21 21
 
22
-		remove_action( 'add_meta_boxes', [$this, 'add_meta_boxes'] );
23
-		remove_action( 'save_post_post', [$this, 'save_post'] );
22
+		remove_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
23
+		remove_action( 'save_post_post', [ $this, 'save_post' ] );
24 24
 
25
-		add_action( 'pollux/archives/init', [$this, 'add_meta_boxes'] );
26
-		add_action( 'pollux/settings/init', [$this, 'add_meta_boxes'] );
27
-		add_filter( 'rwmb_field_meta',      [$this, '_get_field_meta'], 10, 3 );
28
-		add_filter( 'rwmb_normalize_field', [$this, '_normalize_field'] );
25
+		add_action( 'pollux/archives/init', [ $this, 'add_meta_boxes' ] );
26
+		add_action( 'pollux/settings/init', [ $this, 'add_meta_boxes' ] );
27
+		add_filter( 'rwmb_field_meta', [ $this, '_get_field_meta' ], 10, 3 );
28
+		add_filter( 'rwmb_normalize_field', [ $this, '_normalize_field' ] );
29 29
 	}
30 30
 
31 31
 	/**
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function _get_field_meta( $meta, array $field, $saved )
38 38
 	{
39
-		if( !$this->is_edit_screen() || !empty(( new Helper )->toArray( $meta )) || empty( $field['slug'] )) {
39
+		if( !$this->is_edit_screen() || !empty( ( new Helper )->toArray( $meta ) ) || empty( $field[ 'slug' ] ) ) {
40 40
 			return $meta;
41 41
 		}
42
-		$meta = call_user_func( [RWMB_Field::get_class_name( $field ), 'esc_meta'], ( $saved
43
-			? $this->pollux_caller->getMetaValue( $field['slug'], $meta, $this->meta_box['slug'] )
44
-			: $field['std']
45
-		));
42
+		$meta = call_user_func( [ RWMB_Field::get_class_name( $field ), 'esc_meta' ], ( $saved
43
+			? $this->pollux_caller->getMetaValue( $field[ 'slug' ], $meta, $this->meta_box[ 'slug' ] )
44
+			: $field[ 'std' ]
45
+		) );
46 46
 		return $this->_normalize_field_meta( $meta, $field );
47 47
 	}
48 48
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	public function _normalize_field( array $field )
53 53
 	{
54
-		if( !empty( $field['multiple'] ) && $field['id'] == substr( $field['field_name'], 0, -2 )) {
55
-			$parts = array_filter( explode( '-', $field['id'] ));
54
+		if( !empty( $field[ 'multiple' ] ) && $field[ 'id' ] == substr( $field[ 'field_name' ], 0, -2 ) ) {
55
+			$parts = array_filter( explode( '-', $field[ 'id' ] ) );
56 56
 			$first = array_shift( $parts );
57
-			$field['field_name'] = array_reduce( $parts, function( $carry, $part ) {
57
+			$field[ 'field_name' ] = array_reduce( $parts, function( $carry, $part ) {
58 58
 				return sprintf( '%s[%s]', $carry, $part );
59 59
 			}, $first ) . '[]';
60 60
 		}
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	public function _normalize_field_meta( $meta, array $field )
69 69
 	{
70
-		if( !empty( $meta ) && is_array( $meta )) {
70
+		if( !empty( $meta ) && is_array( $meta ) ) {
71 71
 			return $meta;
72 72
 		}
73
-		if( $field['clone'] ) {
74
-			return [''];
73
+		if( $field[ 'clone' ] ) {
74
+			return [ '' ];
75 75
 		}
76
-		if( $field['multiple'] ) {
77
-			return [];
76
+		if( $field[ 'multiple' ] ) {
77
+			return [ ];
78 78
 		}
79 79
 		return $meta;
80 80
 	}
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	public function add_meta_boxes()
88 88
 	{
89 89
 		add_meta_box(
90
-			$this->meta_box['id'],
91
-			$this->meta_box['title'],
92
-			[$this, 'show'],
90
+			$this->meta_box[ 'id' ],
91
+			$this->meta_box[ 'title' ],
92
+			[ $this, 'show' ],
93 93
 			null,
94
-			$this->meta_box['context'],
95
-			$this->meta_box['priority']
94
+			$this->meta_box[ 'context' ],
95
+			$this->meta_box[ 'priority' ]
96 96
 		);
97 97
 	}
98 98
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	public function is_saved()
111 111
 	{
112 112
 		foreach( array_column( $this->fields, 'slug' ) as $field ) {
113
-			if( !is_null( $this->pollux_caller->getMetaValue( $field, null, $this->meta_box['slug'] ))) {
113
+			if( !is_null( $this->pollux_caller->getMetaValue( $field, null, $this->meta_box[ 'slug' ] ) ) ) {
114 114
 				return true;
115 115
 			}
116 116
 		}
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 	 */
124 124
 	public static function normalize( $metabox )
125 125
 	{
126
-		unset( $metabox['post_types'] );
127
-		return wp_parse_args( $metabox, ['slug' => ''] );
126
+		unset( $metabox[ 'post_types' ] );
127
+		return wp_parse_args( $metabox, [ 'slug' => '' ] );
128 128
 	}
129 129
 }
Please login to merge, or discard this patch.