@@ -44,7 +44,7 @@ |
||
| 44 | 44 | * @param Meta_Data[] $meta_data |
| 45 | 45 | * @return Meta_Data[] |
| 46 | 46 | */ |
| 47 | - public function meta_data( array $meta_data ): array { |
|
| 47 | + public function meta_data(array $meta_data): array { |
|
| 48 | 48 | return $meta_data; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param \PinkCrab\Loader\Hook_Loader $loader |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - public function set_hook_loader( Hook_Loader $loader ) { |
|
| 53 | + public function set_hook_loader(Hook_Loader $loader) { |
|
| 54 | 54 | $this->loader = $loader; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @param \PinkCrab\Perique\Interfaces\DI_Container $container |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - public function set_di_container( DI_Container $container ): void { |
|
| 63 | + public function set_di_container(DI_Container $container): void { |
|
| 64 | 64 | $this->container = $container; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -70,23 +70,23 @@ discard block |
||
| 70 | 70 | * @param object|Registerable $class |
| 71 | 71 | * @return object |
| 72 | 72 | */ |
| 73 | - public function process( $class ) { |
|
| 74 | - if ( ! is_a( $class, Registerable::class ) ) { |
|
| 73 | + public function process($class) { |
|
| 74 | + if ( ! is_a($class, Registerable::class)) { |
|
| 75 | 75 | return $class; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Based on the registerable type. |
| 79 | - switch ( true ) { |
|
| 80 | - case is_a( $class, Post_Type::class ): |
|
| 81 | - $this->process_post_type( $class ); |
|
| 79 | + switch (true) { |
|
| 80 | + case is_a($class, Post_Type::class): |
|
| 81 | + $this->process_post_type($class); |
|
| 82 | 82 | break; |
| 83 | 83 | |
| 84 | - case is_a( $class, Taxonomy::class ): |
|
| 85 | - $this->process_taxonomy( $class ); |
|
| 84 | + case is_a($class, Taxonomy::class): |
|
| 85 | + $this->process_taxonomy($class); |
|
| 86 | 86 | break; |
| 87 | 87 | |
| 88 | - case is_a( $class, Shared_Meta_Box_Controller::class ): |
|
| 89 | - $this->process_shared_meta_box( $class ); |
|
| 88 | + case is_a($class, Shared_Meta_Box_Controller::class): |
|
| 89 | + $this->process_shared_meta_box($class); |
|
| 90 | 90 | break; |
| 91 | 91 | |
| 92 | 92 | default: |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | * @return void |
| 105 | 105 | * @since 0.7.0 |
| 106 | 106 | */ |
| 107 | - protected function process_taxonomy( Taxonomy $taxonomy ): void { |
|
| 107 | + protected function process_taxonomy(Taxonomy $taxonomy): void { |
|
| 108 | 108 | $this->loader->action( |
| 109 | 109 | 'init', |
| 110 | - static function() use ( $taxonomy ) { |
|
| 110 | + static function() use ($taxonomy) { |
|
| 111 | 111 | Registrar_Factory::new() |
| 112 | - ->create_from_registerable( $taxonomy ) |
|
| 113 | - ->register( $taxonomy ); |
|
| 112 | + ->create_from_registerable($taxonomy) |
|
| 113 | + ->register($taxonomy); |
|
| 114 | 114 | } |
| 115 | 115 | ); |
| 116 | 116 | } |
@@ -122,21 +122,21 @@ discard block |
||
| 122 | 122 | * @return void |
| 123 | 123 | * @since 0.7.0 |
| 124 | 124 | */ |
| 125 | - protected function process_post_type( Post_Type $post_type_registerable ) { |
|
| 125 | + protected function process_post_type(Post_Type $post_type_registerable) { |
|
| 126 | 126 | // Register registerable. |
| 127 | 127 | $this->loader->action( |
| 128 | 128 | 'init', |
| 129 | - static function() use ( $post_type_registerable ) { |
|
| 129 | + static function() use ($post_type_registerable) { |
|
| 130 | 130 | Registrar_Factory::new() |
| 131 | - ->create_from_registerable( $post_type_registerable ) |
|
| 132 | - ->register( $post_type_registerable ); |
|
| 131 | + ->create_from_registerable($post_type_registerable) |
|
| 132 | + ->register($post_type_registerable); |
|
| 133 | 133 | } |
| 134 | 134 | ); |
| 135 | 135 | |
| 136 | 136 | // Define use of gutenberg |
| 137 | 137 | $this->loader->filter( |
| 138 | 138 | 'use_block_editor_for_post_type', |
| 139 | - static function( bool $state, string $post_type ) use ( $post_type_registerable ): bool { |
|
| 139 | + static function(bool $state, string $post_type) use ($post_type_registerable): bool { |
|
| 140 | 140 | return $post_type === $post_type_registerable->key |
| 141 | 141 | ? (bool) $post_type_registerable->gutenberg |
| 142 | 142 | : $state; |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | 148 | // Register meta boxes. |
| 149 | - $meta_boxes = $post_type_registerable->meta_boxes( array() ); |
|
| 149 | + $meta_boxes = $post_type_registerable->meta_boxes(array()); |
|
| 150 | 150 | |
| 151 | - if ( ! empty( $meta_boxes ) ) { |
|
| 151 | + if ( ! empty($meta_boxes)) { |
|
| 152 | 152 | // Create the registrar |
| 153 | 153 | $meta_box_registrar = $this->get_meta_box_registrar(); |
| 154 | 154 | |
| 155 | 155 | // Register each meta box. |
| 156 | - foreach ( $meta_boxes as $meta_box ) { |
|
| 157 | - $meta_box_registrar->register( $meta_box ); |
|
| 156 | + foreach ($meta_boxes as $meta_box) { |
|
| 157 | + $meta_box_registrar->register($meta_box); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | * @return void |
| 168 | 168 | * @since 0.7.0 |
| 169 | 169 | */ |
| 170 | - public function process_shared_meta_box( Shared_Meta_Box_Controller $controller ): void { |
|
| 171 | - $registrar = new Shared_Meta_Box_Registrar( $this->get_meta_box_registrar() ); |
|
| 172 | - $registrar->register( $controller ); |
|
| 170 | + public function process_shared_meta_box(Shared_Meta_Box_Controller $controller): void { |
|
| 171 | + $registrar = new Shared_Meta_Box_Registrar($this->get_meta_box_registrar()); |
|
| 172 | + $registrar->register($controller); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * @since 0.7.0 |
| 180 | 180 | */ |
| 181 | 181 | public function get_meta_box_registrar(): Meta_Box_Registrar { |
| 182 | - return Registrar_Factory::new()->meta_box_registrar( $this->container, $this->loader ); |
|
| 182 | + return Registrar_Factory::new()->meta_box_registrar($this->container, $this->loader); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | public function setup(): void { |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | protected $meta_box_registrar; |
| 43 | 43 | |
| 44 | - public function __construct( Meta_Box_Registrar $meta_box_registrar ) { |
|
| 44 | + public function __construct(Meta_Box_Registrar $meta_box_registrar) { |
|
| 45 | 45 | $this->meta_box_registrar = $meta_box_registrar; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | * @param \PinkCrab\Registerables\Registration_Middleware\Registerable $registerable |
| 52 | 52 | * @return void |
| 53 | 53 | */ |
| 54 | - public function register( Registerable $registerable ): void { |
|
| 55 | - if ( ! is_a( $registerable, Shared_Meta_Box_Controller::class ) ) { |
|
| 54 | + public function register(Registerable $registerable): void { |
|
| 55 | + if ( ! is_a($registerable, Shared_Meta_Box_Controller::class)) { |
|
| 56 | 56 | return; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // Get the meta box and meta data. |
| 62 | 62 | $meta_box = $registerable->meta_box(); |
| 63 | - $meta_data = $registerable->meta_data( array() ); |
|
| 63 | + $meta_data = $registerable->meta_data(array()); |
|
| 64 | 64 | |
| 65 | 65 | // Register the meta box. |
| 66 | - $this->meta_box_registrar->register( $meta_box ); |
|
| 66 | + $this->meta_box_registrar->register($meta_box); |
|
| 67 | 67 | |
| 68 | 68 | // Register all meta data. |
| 69 | - foreach ( $this->filter_meta_data( $meta_data ) as $meta_field ) { |
|
| 69 | + foreach ($this->filter_meta_data($meta_data) as $meta_field) { |
|
| 70 | 70 | // Register meta data for each post type. |
| 71 | - foreach ( $meta_box->screen as $post_type ) { |
|
| 72 | - $this->register_meta_data_for_post_type( $meta_field, $post_type ); |
|
| 71 | + foreach ($meta_box->screen as $post_type) { |
|
| 72 | + $this->register_meta_data_for_post_type($meta_field, $post_type); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | * @param mixed[] $meta_data |
| 82 | 82 | * @return Meta_Data[] |
| 83 | 83 | */ |
| 84 | - protected function filter_meta_data( array $meta_data ): array { |
|
| 84 | + protected function filter_meta_data(array $meta_data): array { |
|
| 85 | 85 | return array_filter( |
| 86 | 86 | $meta_data, |
| 87 | - function( $e ) { |
|
| 88 | - return is_a( $e, Meta_Data::class ); |
|
| 87 | + function($e) { |
|
| 88 | + return is_a($e, Meta_Data::class); |
|
| 89 | 89 | } |
| 90 | 90 | ); |
| 91 | 91 | } |
@@ -97,14 +97,14 @@ discard block |
||
| 97 | 97 | * @param string $post_type |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - protected function register_meta_data_for_post_type( Meta_Data $meta_data, string $post_type ): void { |
|
| 100 | + protected function register_meta_data_for_post_type(Meta_Data $meta_data, string $post_type): void { |
|
| 101 | 101 | // Clone and set the post type, while enforcing it as a post meta. |
| 102 | 102 | $meta_data = clone $meta_data; |
| 103 | - $meta_data->object_subtype( $post_type ); |
|
| 104 | - $meta_data->meta_type( 'post' ); |
|
| 105 | - $result = register_meta( $meta_data->get_meta_type(), $meta_data->get_meta_key(), $meta_data->parse_args() ); |
|
| 106 | - if ( ! $result ) { |
|
| 107 | - throw new \Exception( "Failed to register {$meta_data->get_meta_key()} (meta) for {$post_type} post type" ); |
|
| 103 | + $meta_data->object_subtype($post_type); |
|
| 104 | + $meta_data->meta_type('post'); |
|
| 105 | + $result = register_meta($meta_data->get_meta_type(), $meta_data->get_meta_key(), $meta_data->parse_args()); |
|
| 106 | + if ( ! $result) { |
|
| 107 | + throw new \Exception("Failed to register {$meta_data->get_meta_key()} (meta) for {$post_type} post type"); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @return Registrar |
| 55 | 55 | * @throws Exception If not valid registerable type passed. |
| 56 | 56 | */ |
| 57 | - public function create_from_registerable( Registerable $registerable ): Registrar { |
|
| 58 | - switch ( true ) { |
|
| 59 | - case is_a( $registerable, Post_Type::class ): |
|
| 60 | - return new Post_Type_Registrar( new Post_Type_Validator() ); |
|
| 57 | + public function create_from_registerable(Registerable $registerable): Registrar { |
|
| 58 | + switch (true) { |
|
| 59 | + case is_a($registerable, Post_Type::class): |
|
| 60 | + return new Post_Type_Registrar(new Post_Type_Validator()); |
|
| 61 | 61 | |
| 62 | - case is_a( $registerable, Taxonomy::class ): |
|
| 63 | - return new Taxonomy_Registrar( new Taxonomy_Validator() ); |
|
| 62 | + case is_a($registerable, Taxonomy::class): |
|
| 63 | + return new Taxonomy_Registrar(new Taxonomy_Validator()); |
|
| 64 | 64 | |
| 65 | 65 | default: |
| 66 | - $type = get_class( $registerable ); |
|
| 67 | - throw new Exception( 'Invalid registerable (' . $type . ')type (no dispatcher exists)' ); |
|
| 66 | + $type = get_class($registerable); |
|
| 67 | + throw new Exception('Invalid registerable (' . $type . ')type (no dispatcher exists)'); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | * @param \PinkCrab\Loader\Hook_Loader $loader |
| 76 | 76 | * @return Meta_Box_Registrar |
| 77 | 77 | */ |
| 78 | - public function meta_box_registrar( DI_Container $container, Hook_Loader $loader ): Meta_Box_Registrar { |
|
| 79 | - return new Meta_Box_Registrar( new Meta_Box_Validator(), $container, $loader ); |
|
| 78 | + public function meta_box_registrar(DI_Container $container, Hook_Loader $loader): Meta_Box_Registrar { |
|
| 79 | + return new Meta_Box_Registrar(new Meta_Box_Validator(), $container, $loader); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | } |