Passed
Push — master ( 6cfb9c...acdd87 )
by Paul
03:15
created
src/MetaBox/MetaBox.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function init()
34 34
 	{
35
-		if( empty( $this->app->config->{static::ID} ))return;
35
+		if( empty($this->app->config->{static::ID} ) )return;
36 36
 		$this->normalize( $this->app->config->{static::ID}, [
37 37
 			'post_types' => [],
38
-		]);
38
+		] );
39 39
 		add_filter( 'rwmb_normalize_map_field', [$this, 'normalizeMapField'] );
40
-		add_filter( 'rwmb_show',                [$this, 'show'], 10, 2 );
41
-		add_filter( 'rwmb_meta_boxes',          [$this, 'register'] );
42
-		add_filter( 'rwmb_outer_html',          [$this, 'renderField'], 10, 2 );
40
+		add_filter( 'rwmb_show', [$this, 'show'], 10, 2 );
41
+		add_filter( 'rwmb_meta_boxes', [$this, 'register'] );
42
+		add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 );
43 43
 	}
44 44
 
45 45
 	/**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	{
73 73
 		return PostMeta::get( $key, [
74 74
 			'id' => $this->getPostId(),
75
-		]);
75
+		] );
76 76
 	}
77 77
 
78 78
 	/**
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public function normalizeMapField( $field )
83 83
 	{
84
-		if( empty( $field['address_field'] )) {
84
+		if( empty($field['address_field']) ) {
85 85
 			return $field;
86 86
 		}
87
-		if( !Helper::startsWith( Application::PREFIX, $field['address_field'] )) {
88
-			$field['address_field'] = Application::PREFIX . $field['address_field'];
87
+		if( !Helper::startsWith( Application::PREFIX, $field['address_field'] ) ) {
88
+			$field['address_field'] = Application::PREFIX.$field['address_field'];
89 89
 		}
90 90
 		$apiKey = SiteMeta::services( $field['api_key'] );
91
-		if( !empty( $apiKey ) && is_string( $apiKey )) {
91
+		if( !empty($apiKey) && is_string( $apiKey ) ) {
92 92
 			$field['api_key'] = $apiKey;
93 93
 		}
94 94
 		return $field;
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	public function register()
102 102
 	{
103
-		if( current_user_can( 'switch_themes' )) {
103
+		if( current_user_can( 'switch_themes' ) ) {
104 104
 			$instructions = $this->initInstructions();
105
-			if( is_array( $instructions )) {
105
+			if( is_array( $instructions ) ) {
106 106
 				$this->normalize( $instructions );
107 107
 			}
108 108
 		}
109 109
 		$metaboxes = func_num_args()
110
-			? Helper::toArray( func_get_arg(0) )
110
+			? Helper::toArray( func_get_arg( 0 ) )
111 111
 			: [];
112 112
 		return array_merge( $metaboxes, $this->metaboxes );
113 113
 	}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function renderField( $html, $field )
120 120
 	{
121
-		return !isset( $field['condition'] ) || $this->validate( $field['condition'] )
121
+		return !isset($field['condition']) || $this->validate( $field['condition'] )
122 122
 			? $html
123 123
 			: '';
124 124
 	}
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	public function show( $bool, array $metabox )
131 131
 	{
132 132
 		if( defined( 'DOING_AJAX' )
133
-			|| !isset( $metabox['condition'] )
134
-			|| !$this->hasPostType( $metabox )) {
133
+			|| !isset($metabox['condition'])
134
+			|| !$this->hasPostType( $metabox ) ) {
135 135
 			return $bool;
136 136
 		}
137 137
 		return $this->validate( $metabox['condition'] );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 */
143 143
 	protected function getPostId()
144 144
 	{
145
-		if( !( $postId = filter_input( INPUT_GET, 'post' ))) {
145
+		if( !($postId = filter_input( INPUT_GET, 'post' )) ) {
146 146
 			$postId = filter_input( INPUT_POST, 'post_ID' );
147 147
 		}
148 148
 		return intval( $postId );
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
 	{
156 156
 		return array_unique( iterator_to_array(
157 157
 			new RecursiveIteratorIterator(
158
-				new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ))
158
+				new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) )
159 159
 			),
160 160
 			false
161
-		));
161
+		) );
162 162
 	}
163 163
 
164 164
 	/**
@@ -166,10 +166,10 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	protected function hasPostType( array $metabox )
168 168
 	{
169
-		if( !isset( $metabox['post_types'] )) {
169
+		if( !isset($metabox['post_types']) ) {
170 170
 			return true;
171 171
 		}
172
-		if( !( $type = filter_input( INPUT_GET, 'post_type' ))) {
172
+		if( !($type = filter_input( INPUT_GET, 'post_type' )) ) {
173 173
 			$type = get_post_type( $this->getPostId() );
174 174
 		}
175 175
 		return in_array( $type, $metabox['post_types'] );
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 				'id' => $id,
188 188
 				'slug' => $id,
189 189
 				'validation' => [],
190
-			]);
190
+			] );
191 191
 			$this->metaboxes[] = $this->setDependencies(
192 192
 				$this->normalizeThis( $metabox, $data, $id )
193 193
 			);
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 */
202 202
 	protected function normalizeDepends( $depends, array $data, $parentId )
203 203
 	{
204
-		return is_string( $depends ) && !empty( $depends )
204
+		return is_string( $depends ) && !empty($depends)
205 205
 			? $this->normalizeId( $depends, $data, $parentId )
206 206
 			: '';
207 207
 	}
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 	 */
222 222
 	protected function normalizeFields( array $fields, array $data, $parentId )
223 223
 	{
224
-		return array_map( function( $id, $field ) use( $parentId ) {
225
-			$defaults =  [
224
+		return array_map( function( $id, $field ) use($parentId) {
225
+			$defaults = [
226 226
 				'attributes' => [],
227 227
 				'class' => '',
228 228
 				'condition' => [],
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 */
243 243
 	protected function normalizeId( $id, array $data, $parentId )
244 244
 	{
245
-		return Application::prefix() . $id;
245
+		return Application::prefix().$id;
246 246
 	}
247 247
 
248 248
 	/**
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 	protected function normalizeValidation( array $validation, array $data, $parentId )
261 261
 	{
262 262
 		foreach( ['messages', 'rules'] as $key ) {
263
-			if( empty( $validation[$key] ))continue;
263
+			if( empty($validation[$key]) )continue;
264 264
 			foreach( $validation[$key] as $id => $value ) {
265 265
 				$validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value;
266
-				unset( $validation[$key][$id] );
266
+				unset($validation[$key][$id]);
267 267
 			}
268 268
 		}
269 269
 		return $validation;
@@ -276,17 +276,17 @@  discard block
 block discarded – undo
276 276
 	{
277 277
 		$fields = &$metabox['fields'];
278 278
 		$depends = array_column( $fields, 'depends' );
279
-		array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) {
280
-			if( empty( $value ))return;
279
+		array_walk( $depends, function( $value, $index ) use(&$fields, $metabox) {
280
+			if( empty($value) )return;
281 281
 			$fields[$index]['attributes']['data-depends'] = $value;
282
-			list( $key, $value ) = array_pad( explode( '|', $value ), 2, null );
283
-			$dependency = array_search( $key, array_column( $fields, 'id' ));
282
+			list($key, $value) = array_pad( explode( '|', $value ), 2, null );
283
+			$dependency = array_search( $key, array_column( $fields, 'id' ) );
284 284
 			$metaValue = $this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] );
285 285
 			$isHidden = $value === null
286 286
 				? $metaValue === ''
287 287
 				: $metaValue != $value;
288 288
 			if( $isHidden ) {
289
-				$fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] );
289
+				$fields[$index]['class'] = trim( 'hidden '.$fields[$index]['class'] );
290 290
 			}
291 291
 		});
292 292
 		return $metabox;
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,9 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function init()
34 34
 	{
35
-		if( empty( $this->app->config->{static::ID} ))return;
35
+		if( empty( $this->app->config->{static::ID} )) {
36
+			return;
37
+		}
36 38
 		$this->normalize( $this->app->config->{static::ID}, [
37 39
 			'post_types' => [],
38 40
 		]);
@@ -260,7 +262,9 @@  discard block
 block discarded – undo
260 262
 	protected function normalizeValidation( array $validation, array $data, $parentId )
261 263
 	{
262 264
 		foreach( ['messages', 'rules'] as $key ) {
263
-			if( empty( $validation[$key] ))continue;
265
+			if( empty( $validation[$key] )) {
266
+				continue;
267
+			}
264 268
 			foreach( $validation[$key] as $id => $value ) {
265 269
 				$validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value;
266 270
 				unset( $validation[$key][$id] );
@@ -277,7 +281,9 @@  discard block
 block discarded – undo
277 281
 		$fields = &$metabox['fields'];
278 282
 		$depends = array_column( $fields, 'depends' );
279 283
 		array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) {
280
-			if( empty( $value ))return;
284
+			if( empty( $value )) {
285
+				return;
286
+			}
281 287
 			$fields[$index]['attributes']['data-depends'] = $value;
282 288
 			list( $key, $value ) = array_pad( explode( '|', $value ), 2, null );
283 289
 			$dependency = array_search( $key, array_column( $fields, 'id' ));
Please login to merge, or discard this patch.