Passed
Pull Request — master (#69)
by Glynn
17:50
created
src/Registrar/Post_Type_Registrar.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -62,15 +62,15 @@  discard block
 block discarded – undo
62 62
 	 * @param \PinkCrab\Registerables\Registration_Middleware\Registerable $registerable
63 63
 	 * @return void
64 64
 	 */
65
-	public function register( Registerable $registerable ): void {
65
+	public function register(Registerable $registerable): void {
66 66
 		/** @var Post_Type $registerable, Validation call below catches no Post_Type Registerables */
67 67
 
68
-		if ( ! $this->validator->validate( $registerable ) ) {
68
+		if ( ! $this->validator->validate($registerable)) {
69 69
 			throw new Exception(
70 70
 				sprintf(
71 71
 					'Failed validating post type model(%s) with errors: %s',
72
-					get_class( $registerable ),
73
-					join( ', ', $this->validator->get_errors() )
72
+					get_class($registerable),
73
+					join(', ', $this->validator->get_errors())
74 74
 				)
75 75
 			);
76 76
 		}
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 		// Attempt to register the post type.
79 79
 		try {
80 80
 			/* @phpstan-ignore-next-line */
81
-			$result = register_post_type( $registerable->key, $this->compile_args( $registerable ) );
82
-			if ( is_a( $result, \WP_Error::class ) ) {
83
-				throw new Exception( join( $result->get_error_messages() ) );
81
+			$result = register_post_type($registerable->key, $this->compile_args($registerable));
82
+			if (is_a($result, \WP_Error::class)) {
83
+				throw new Exception(join($result->get_error_messages()));
84 84
 			}
85
-		} catch ( \Throwable $th ) {
86
-			throw new Exception( "Failed to register {$registerable->key} post type ({$th->getMessage()})" );
85
+		} catch (\Throwable $th) {
86
+			throw new Exception("Failed to register {$registerable->key} post type ({$th->getMessage()})");
87 87
 		}
88 88
 
89 89
 		// Register all meta data for post type.
90
-		$this->register_meta_data( $registerable );
90
+		$this->register_meta_data($registerable);
91 91
 	}
92 92
 
93 93
 	/**
@@ -96,18 +96,18 @@  discard block
 block discarded – undo
96 96
 	 * @param \PinkCrab\Registerables\Post_Type $post_type
97 97
 	 * @return void
98 98
 	 */
99
-	protected function register_meta_data( Post_Type $post_type ): void {
99
+	protected function register_meta_data(Post_Type $post_type): void {
100 100
 
101 101
 		// Get all meta fields for post_type.
102
-		$meta_fields = $post_type->meta_data( array() );
102
+		$meta_fields = $post_type->meta_data(array());
103 103
 		// Attempt to register all Meta for post_type.
104 104
 		try {
105
-			foreach ( $meta_fields as $meta_field ) {
105
+			foreach ($meta_fields as $meta_field) {
106 106
 				$this->meta_data_registrar
107
-					->register_for_post_type( $meta_field, $post_type->key );
107
+					->register_for_post_type($meta_field, $post_type->key);
108 108
 			}
109
-		} catch ( \Throwable $th ) {
110
-			throw new Exception( $th->getMessage() );
109
+		} catch (\Throwable $th) {
110
+			throw new Exception($th->getMessage());
111 111
 		}
112 112
 	}
113 113
 
@@ -119,64 +119,64 @@  discard block
 block discarded – undo
119 119
 	 * @param \PinkCrab\Registerables\Post_Type $post_type
120 120
 	 * @return array<string, string|int|array<string, string>>
121 121
 	 */
122
-	protected function compile_args( Post_Type $post_type ): array {
122
+	protected function compile_args(Post_Type $post_type): array {
123 123
 		// Create the labels.
124 124
 		$labels = array(
125 125
 			'name'                     => $post_type->plural,
126 126
 			'singular_name'            => $post_type->singular,
127
-			'add_new'                  => _x( 'Add New', 'Add new post label of custom post type', 'pinkcrab' ),
127
+			'add_new'                  => _x('Add New', 'Add new post label of custom post type', 'pinkcrab'),
128 128
 			/* translators: %s: Post type singular name */
129
-			'add_new_item'             => wp_sprintf( _x( 'Add New %s', 'Label for adding a new singular item. Default is ‘Add New {post type singular name}’.', 'pinkcrab' ), $post_type->singular ),
129
+			'add_new_item'             => wp_sprintf(_x('Add New %s', 'Label for adding a new singular item. Default is ‘Add New {post type singular name}’.', 'pinkcrab'), $post_type->singular),
130 130
 			/* translators: %s: Post type singular name */
131
-			'edit_item'                => wp_sprintf( _x( 'Edit %s', 'Label for editing a singular item. Default is ‘Edit {post type singular name}’.', 'pinkcrab' ), $post_type->singular ),
131
+			'edit_item'                => wp_sprintf(_x('Edit %s', 'Label for editing a singular item. Default is ‘Edit {post type singular name}’.', 'pinkcrab'), $post_type->singular),
132 132
 			/* translators: %s: Post type singular name */
133
-			'new_item'                 => wp_sprintf( _x( 'New %s', 'Label for the new item page title. Default is ‘New {post type singular name}’.', 'pinkcrab' ), $post_type->singular ),
133
+			'new_item'                 => wp_sprintf(_x('New %s', 'Label for the new item page title. Default is ‘New {post type singular name}’.', 'pinkcrab'), $post_type->singular),
134 134
 			/* translators: %s: Post type singular name */
135
-			'view_item'                => wp_sprintf( _x( 'View %s', 'Label for viewing a singular item. Default is ‘View {post type singular name}’.', 'pinkcrab' ), $post_type->singular ),
135
+			'view_item'                => wp_sprintf(_x('View %s', 'Label for viewing a singular item. Default is ‘View {post type singular name}’.', 'pinkcrab'), $post_type->singular),
136 136
 			/* translators: %s: Post type plural name */
137
-			'view_items'               => wp_sprintf( _x( 'View %s', 'Label for viewing post type archives. Default is ‘View {post type plural name}’.', 'pinkcrab' ), $post_type->plural ),
137
+			'view_items'               => wp_sprintf(_x('View %s', 'Label for viewing post type archives. Default is ‘View {post type plural name}’.', 'pinkcrab'), $post_type->plural),
138 138
 			/* translators: %s: Post type singular name */
139
-			'search_items'             => wp_sprintf( _x( 'Search %s', 'Label for searching plural items. Default is ‘Search {post type plural name}’.', 'pinkcrab' ), $post_type->singular ),
139
+			'search_items'             => wp_sprintf(_x('Search %s', 'Label for searching plural items. Default is ‘Search {post type plural name}’.', 'pinkcrab'), $post_type->singular),
140 140
 			/* translators: %s: Post type plural name */
141
-			'not_found'                => wp_sprintf( _x( 'No %s found', 'Label used when no items are found. Default is ‘No {post type plural name} found’.', 'pinkcrab' ), $post_type->plural ),
141
+			'not_found'                => wp_sprintf(_x('No %s found', 'Label used when no items are found. Default is ‘No {post type plural name} found’.', 'pinkcrab'), $post_type->plural),
142 142
 			/* translators: %s: Post type plural name */
143
-			'not_found_in_trash'       => wp_sprintf( _x( 'No %s found in Trash', 'Label used when no items are in the Trash. Default is ‘No {post type plural name} found in Trash’.', 'pinkcrab' ), $post_type->plural ),
143
+			'not_found_in_trash'       => wp_sprintf(_x('No %s found in Trash', 'Label used when no items are in the Trash. Default is ‘No {post type plural name} found in Trash’.', 'pinkcrab'), $post_type->plural),
144 144
 			/* translators: %s: Post type singular name */
145
-			'parent_item_colon'        => wp_sprintf( _x( 'Parent %s:', 'Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is ‘Parent {post type plural name}:’.', 'pinkcrab' ), $post_type->singular ),
145
+			'parent_item_colon'        => wp_sprintf(_x('Parent %s:', 'Label used to prefix parents of hierarchical items. Not used on non-hierarchical post types. Default is ‘Parent {post type plural name}:’.', 'pinkcrab'), $post_type->singular),
146 146
 			/* translators: %s: Post type singular name */
147
-			'all_items'                => wp_sprintf( _x( 'All %s', 'Label to signify all items in a submenu link. Default is ‘All {post type plural name}’.', 'pinkcrab' ), $post_type->plural ),
147
+			'all_items'                => wp_sprintf(_x('All %s', 'Label to signify all items in a submenu link. Default is ‘All {post type plural name}’.', 'pinkcrab'), $post_type->plural),
148 148
 			/* translators: %s: Post type plural name */
149
-			'archives'                 => wp_sprintf( _x( '%s Archives', ' Label for archives in nav menus. Default is ‘Post Archives’.', 'pinkcrab' ), \ucfirst( $post_type->plural ) ),
149
+			'archives'                 => wp_sprintf(_x('%s Archives', ' Label for archives in nav menus. Default is ‘Post Archives’.', 'pinkcrab'), \ucfirst($post_type->plural)),
150 150
 			/* translators: %s: Post type plural name */
151
-			'attributes'               => wp_sprintf( _x( '%s Attributes', 'Label for the attributes meta box. Default is ‘{post type plural name} Attributes’.', 'pinkcrab' ), \ucfirst( $post_type->plural ) ),
151
+			'attributes'               => wp_sprintf(_x('%s Attributes', 'Label for the attributes meta box. Default is ‘{post type plural name} Attributes’.', 'pinkcrab'), \ucfirst($post_type->plural)),
152 152
 			/* translators: %s: Post type singular name */
153
-			'insert_into_item'         => wp_sprintf( _x( 'Insert into %s', 'Label for the media frame button. Default is ‘Insert into {post type plural name}’.', 'pinkcrab' ), $post_type->singular ),
153
+			'insert_into_item'         => wp_sprintf(_x('Insert into %s', 'Label for the media frame button. Default is ‘Insert into {post type plural name}’.', 'pinkcrab'), $post_type->singular),
154 154
 			/* translators: %s: Post type singular name */
155
-			'uploaded_to_this_item'    => wp_sprintf( _x( 'Uploaded to this %s', 'Label for the media frame filter. Default is ‘Uploaded to this {post type plural name}’.', 'pinkcrab' ), $post_type->singular ),
156
-			'featured_image'           => _x( 'Featured image', 'Label for the featured image meta box title. Default is ‘Featured image’.', 'pinkcrab' ),
157
-			'set_featured_image'       => _x( 'Set featured image', 'Label for setting the featured image. Default is ‘Set featured image’.', 'pinkcrab' ),
158
-			'remove_featured_image'    => _x( 'Remove featured image', 'Label for removing the featured image. Default is ‘Remove featured image’.', 'pinkcrab' ),
159
-			'use_featured_image'       => _x( 'Use as featured image', 'Label in the media frame for using a featured image. Default is ‘Use as featured image’.', 'pinkcrab' ),
155
+			'uploaded_to_this_item'    => wp_sprintf(_x('Uploaded to this %s', 'Label for the media frame filter. Default is ‘Uploaded to this {post type plural name}’.', 'pinkcrab'), $post_type->singular),
156
+			'featured_image'           => _x('Featured image', 'Label for the featured image meta box title. Default is ‘Featured image’.', 'pinkcrab'),
157
+			'set_featured_image'       => _x('Set featured image', 'Label for setting the featured image. Default is ‘Set featured image’.', 'pinkcrab'),
158
+			'remove_featured_image'    => _x('Remove featured image', 'Label for removing the featured image. Default is ‘Remove featured image’.', 'pinkcrab'),
159
+			'use_featured_image'       => _x('Use as featured image', 'Label in the media frame for using a featured image. Default is ‘Use as featured image’.', 'pinkcrab'),
160 160
 			'menu_name'                => $post_type->plural,
161 161
 			/* translators: %s: Post type plural name */
162
-			'filter_items_list'        => wp_sprintf( _x( 'Filter %s list', 'Label for the table views hidden heading. Default is ‘Filter {post type plural name} list’.', 'pinkcrab' ), $post_type->plural ),
163
-			'filter_by_date'           => _x( 'Filter by date', 'Label for the date filter in list tables. Default is ‘Filter by date’.', 'pinkcrab' ),
162
+			'filter_items_list'        => wp_sprintf(_x('Filter %s list', 'Label for the table views hidden heading. Default is ‘Filter {post type plural name} list’.', 'pinkcrab'), $post_type->plural),
163
+			'filter_by_date'           => _x('Filter by date', 'Label for the date filter in list tables. Default is ‘Filter by date’.', 'pinkcrab'),
164 164
 			/* translators: %s: Post type plural name */
165
-			'items_list'               => wp_sprintf( _x( '%s list', 'Label for the table hidden heading. Default is ‘{post type plural name} list’.', 'pinkcrab' ), \ucfirst( $post_type->plural ) ),
165
+			'items_list'               => wp_sprintf(_x('%s list', 'Label for the table hidden heading. Default is ‘{post type plural name} list’.', 'pinkcrab'), \ucfirst($post_type->plural)),
166 166
 			/* translators: %s: Post type singular name */
167
-			'item_published'           => wp_sprintf( _x( '%s published', 'Label used when an item is published. Default is ‘{post type singular name} published’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ),
167
+			'item_published'           => wp_sprintf(_x('%s published', 'Label used when an item is published. Default is ‘{post type singular name} published’.', 'pinkcrab'), \ucfirst($post_type->singular)),
168 168
 			/* translators: %s: Post type singular name */
169
-			'item_published_privately' => wp_sprintf( _x( '%s published privately', 'Label used when an item is published with private visibility. Default is ‘{post type singular name} published privately.’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ),
169
+			'item_published_privately' => wp_sprintf(_x('%s published privately', 'Label used when an item is published with private visibility. Default is ‘{post type singular name} published privately.’.', 'pinkcrab'), \ucfirst($post_type->singular)),
170 170
 			/* translators: %s: Post type singular name */
171
-			'item_reverted_to_draft'   => wp_sprintf( _x( '%s reverted to draft', 'Label used when an item is switched to a draft. Default is ‘{post type singular name} reverted to draft’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ),
171
+			'item_reverted_to_draft'   => wp_sprintf(_x('%s reverted to draft', 'Label used when an item is switched to a draft. Default is ‘{post type singular name} reverted to draft’.', 'pinkcrab'), \ucfirst($post_type->singular)),
172 172
 			/* translators: %s: Post type singular name */
173
-			'item_scheduled'           => wp_sprintf( _x( '%s scheduled', 'Label used when an item is scheduled for publishing. Default is ‘{post type singular name} scheduled.’ ', 'pinkcrab' ), \ucfirst( $post_type->singular ) ),
173
+			'item_scheduled'           => wp_sprintf(_x('%s scheduled', 'Label used when an item is scheduled for publishing. Default is ‘{post type singular name} scheduled.’ ', 'pinkcrab'), \ucfirst($post_type->singular)),
174 174
 			/* translators: %s: Post type singular name */
175
-			'item_updated'             => wp_sprintf( _x( '%s updated', 'Label used when an item is updated. Default is ‘{post type singular name} updated.’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ),
175
+			'item_updated'             => wp_sprintf(_x('%s updated', 'Label used when an item is updated. Default is ‘{post type singular name} updated.’.', 'pinkcrab'), \ucfirst($post_type->singular)),
176 176
 			/* translators: %s: Post type singular name */
177
-			'item_link'                => wp_sprintf( _x( '%s Link', 'Title for a navigation link block variation. Default is ‘{post type singular name} Link’.', 'pinkcrab' ), \ucfirst( $post_type->singular ) ),
177
+			'item_link'                => wp_sprintf(_x('%s Link', 'Title for a navigation link block variation. Default is ‘{post type singular name} Link’.', 'pinkcrab'), \ucfirst($post_type->singular)),
178 178
 			/* translators: %s: Post type singular name */
179
-			'item_link_description'    => wp_sprintf( _x( 'A link to a %s', 'Description for a navigation link block variation. Default is ‘A link to a {post type singular name}’.', 'pinkcrab' ), $post_type->singular ),
179
+			'item_link_description'    => wp_sprintf(_x('A link to a %s', 'Description for a navigation link block variation. Default is ‘A link to a {post type singular name}’.', 'pinkcrab'), $post_type->singular),
180 180
 		);
181 181
 
182 182
 		/**
@@ -187,10 +187,10 @@  discard block
 block discarded – undo
187 187
 		 * @param Post_Type $cpt
188 188
 		 * @return array<string, string>
189 189
 		 */
190
-		$labels = apply_filters( Registerable_Hooks::POST_TYPE_LABELS, $post_type->filter_labels( $labels ), $post_type );
190
+		$labels = apply_filters(Registerable_Hooks::POST_TYPE_LABELS, $post_type->filter_labels($labels), $post_type);
191 191
 
192 192
 		// Set the rewrite rules if not defined.
193
-		if ( is_null( $post_type->rewrite ) ) {
193
+		if (is_null($post_type->rewrite)) {
194 194
 			$post_type->rewrite = array(
195 195
 				'slug'       => $post_type->key,
196 196
 				'with_front' => true,
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
 		// Set the meta cap based on its definition and if uses gutenberg.
203 203
 		// See https://github.com/Pink-Crab/Perique-Registerables/issues/66
204
-		if ( null === $post_type->map_meta_cap ) {
204
+		if (null === $post_type->map_meta_cap) {
205 205
 			$meta_cap = $post_type->gutenberg ? true : false;
206 206
 		} else {
207 207
 			$meta_cap = $post_type->map_meta_cap ?? false;
@@ -211,30 +211,30 @@  discard block
 block discarded – undo
211 211
 		$args = array(
212 212
 			'labels'                => $labels,
213 213
 			'description'           => $post_type->description ?? $post_type->plural,
214
-			'hierarchical'          => is_bool( $post_type->hierarchical ) ? $post_type->hierarchical : false,
214
+			'hierarchical'          => is_bool($post_type->hierarchical) ? $post_type->hierarchical : false,
215 215
 			'supports'              => $post_type->supports,
216
-			'public'                => is_bool( $post_type->public ) ? $post_type->public : true,
217
-			'show_ui'               => is_bool( $post_type->show_ui ) ? $post_type->show_ui : true,
218
-			'show_in_menu'          => is_bool( $post_type->show_in_menu ) ? $post_type->show_in_menu : true,
219
-			'show_in_admin_bar'     => is_bool( $post_type->show_in_admin_bar ) ? $post_type->show_in_admin_bar : true,
216
+			'public'                => is_bool($post_type->public) ? $post_type->public : true,
217
+			'show_ui'               => is_bool($post_type->show_ui) ? $post_type->show_ui : true,
218
+			'show_in_menu'          => is_bool($post_type->show_in_menu) ? $post_type->show_in_menu : true,
219
+			'show_in_admin_bar'     => is_bool($post_type->show_in_admin_bar) ? $post_type->show_in_admin_bar : true,
220 220
 			'menu_position'         => $post_type->menu_position,
221 221
 			'menu_icon'             => $post_type->dashicon,
222
-			'show_in_nav_menus'     => is_bool( $post_type->show_in_nav_menus ) ? $post_type->show_in_nav_menus : true,
223
-			'publicly_queryable'    => is_bool( $post_type->publicly_queryable ) ? $post_type->publicly_queryable : true,
224
-			'exclude_from_search'   => is_bool( $post_type->exclude_from_search ) ? $post_type->exclude_from_search : true,
225
-			'has_archive'           => is_bool( $post_type->has_archive ) ? $post_type->has_archive : true,
226
-			'query_var'             => is_bool( $post_type->query_var ) ? $post_type->query_var : false,
227
-			'can_export'            => is_bool( $post_type->can_export ) ? $post_type->can_export : true,
228
-			'rewrite'               => is_bool( $post_type->rewrite ) ? $post_type->rewrite : false,
222
+			'show_in_nav_menus'     => is_bool($post_type->show_in_nav_menus) ? $post_type->show_in_nav_menus : true,
223
+			'publicly_queryable'    => is_bool($post_type->publicly_queryable) ? $post_type->publicly_queryable : true,
224
+			'exclude_from_search'   => is_bool($post_type->exclude_from_search) ? $post_type->exclude_from_search : true,
225
+			'has_archive'           => is_bool($post_type->has_archive) ? $post_type->has_archive : true,
226
+			'query_var'             => is_bool($post_type->query_var) ? $post_type->query_var : false,
227
+			'can_export'            => is_bool($post_type->can_export) ? $post_type->can_export : true,
228
+			'rewrite'               => is_bool($post_type->rewrite) ? $post_type->rewrite : false,
229 229
 			'capability_type'       => $post_type->capability_type,
230 230
 			'capabilities'          => $post_type->capabilities,
231 231
 			'taxonomies'            => $post_type->taxonomies,
232
-			'show_in_rest'          => is_bool( $post_type->show_in_rest ) ? $post_type->show_in_rest : true,
232
+			'show_in_rest'          => is_bool($post_type->show_in_rest) ? $post_type->show_in_rest : true,
233 233
 			'rest_base'             => $post_type->rest_base ?? $post_type->key,
234
-			'rest_controller_class' => \class_exists( $post_type->rest_controller_class ) ? $post_type->rest_controller_class : \WP_REST_Posts_Controller::class,
235
-			'delete_with_user'      => \is_bool( $post_type->delete_with_user ) ? $post_type->delete_with_user : null,
236
-			'template'              => \is_array( $post_type->template ) ? $post_type->template : array(),
237
-			'template_lock'         => \is_string( $post_type->template_lock ) ? $post_type->template_lock : false,
234
+			'rest_controller_class' => \class_exists($post_type->rest_controller_class) ? $post_type->rest_controller_class : \WP_REST_Posts_Controller::class,
235
+			'delete_with_user'      => \is_bool($post_type->delete_with_user) ? $post_type->delete_with_user : null,
236
+			'template'              => \is_array($post_type->template) ? $post_type->template : array(),
237
+			'template_lock'         => \is_string($post_type->template_lock) ? $post_type->template_lock : false,
238 238
 			'map_meta_cap'          => $meta_cap,
239 239
 		);
240 240
 
@@ -247,6 +247,6 @@  discard block
 block discarded – undo
247 247
 		 * @return array<string, string|bool|int|null|array<string, string>
248 248
 		 */
249 249
 		/* @phpstan-ignore-next-line, this is due to apply_filters type hints being wrong. */
250
-		return apply_filters( Registerable_Hooks::POST_TYPE_ARGS, $post_type->filter_args( $args ), $post_type );
250
+		return apply_filters(Registerable_Hooks::POST_TYPE_ARGS, $post_type->filter_args($args), $post_type);
251 251
 	}
252 252
 }
Please login to merge, or discard this patch.
src/Validator/Meta_Box_Validator.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
 class Meta_Box_Validator extends Abstract_Validator {
34 34
 
35
-	protected const REQUIRED_FIELDS = array( 'key', 'label' );
35
+	protected const REQUIRED_FIELDS = array('key', 'label');
36 36
 
37 37
 	/**
38 38
 	 * Validates the class passed.
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * @param \PinkCrab\Registerables\Registration_Middleware\Registerable $object
41 41
 	 * @return bool
42 42
 	 */
43
-	public function validate( Registerable $object ): bool { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
43
+	public function validate(Registerable $object): bool { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
44 44
 		return false; //no op
45 45
 	}
46 46
 
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 	 * @param mixed $meta_box
51 51
 	 * @return bool
52 52
 	 */
53
-	public function verify_meta_box( $meta_box ): bool {
53
+	public function verify_meta_box($meta_box): bool {
54 54
 		// If this is not a valid post type, just bail here.
55
-		if ( ! is_object( $meta_box ) || ! is_a( $meta_box, Meta_Box::class ) ) {
56
-			$this->add_error( sprintf( '%s is not a valid Meta Box Model', is_object( $meta_box ) ? get_class( $meta_box ) : \gettype( $meta_box ) ) );
55
+		if ( ! is_object($meta_box) || ! is_a($meta_box, Meta_Box::class)) {
56
+			$this->add_error(sprintf('%s is not a valid Meta Box Model', is_object($meta_box) ? get_class($meta_box) : \gettype($meta_box)));
57 57
 			return false;
58 58
 		}
59 59
 
60 60
 		/* @var Meta_Box $object, already confirmed as a post type */
61 61
 
62 62
 		// Ensure all required fields are set.
63
-		$this->has_required_fields( $meta_box );
63
+		$this->has_required_fields($meta_box);
64 64
 
65 65
 		// Ensure can render view.
66
-		$this->has_valid_view( $meta_box );
66
+		$this->has_valid_view($meta_box);
67 67
 
68 68
 		// Check if the passed object has any errors.
69 69
 		return ! $this->has_errors();
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
 	 * @param Meta_Box $meta_box
76 76
 	 * @return void
77 77
 	 */
78
-	protected function has_required_fields( Meta_Box $meta_box ): void {
79
-		foreach ( self::REQUIRED_FIELDS as $field ) {
80
-			if ( ! is_string( $meta_box->{$field} )
81
-			|| \mb_strlen( $meta_box->{$field} ) === 0
78
+	protected function has_required_fields(Meta_Box $meta_box): void {
79
+		foreach (self::REQUIRED_FIELDS as $field) {
80
+			if ( ! is_string($meta_box->{$field} )
81
+			|| \mb_strlen($meta_box->{$field} ) === 0
82 82
 			) {
83
-				$this->add_error( sprintf( '%s is not set on %s Meta Box Model', $field, get_class( $meta_box ) ) );
83
+				$this->add_error(sprintf('%s is not set on %s Meta Box Model', $field, get_class($meta_box)));
84 84
 			}
85 85
 		}
86 86
 	}
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
 	 * @param \PinkCrab\Registerables\Meta_Box $meta_box
93 93
 	 * @return void
94 94
 	 */
95
-	protected function has_valid_view( Meta_Box $meta_box ): void {
96
-		if ( ! \is_callable( $meta_box->view )
97
-		&& ( ! is_string( $meta_box->view_template ) || \mb_strlen( $meta_box->view_template ) === 0 )
95
+	protected function has_valid_view(Meta_Box $meta_box): void {
96
+		if ( ! \is_callable($meta_box->view)
97
+		&& ( ! is_string($meta_box->view_template) || \mb_strlen($meta_box->view_template) === 0)
98 98
 		) {
99
-			$this->add_error( sprintf( '%s doesn\'t have a valid view defined.', get_class( $meta_box ) ) );
99
+			$this->add_error(sprintf('%s doesn\'t have a valid view defined.', get_class($meta_box)));
100 100
 		}
101 101
 	}
102 102
 }
Please login to merge, or discard this patch.