From 5fe6c41546b0925659153033dcedf7b88105634b Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Fri, 12 Mar 2021 02:35:42 -0300 Subject: [PATCH] Fixes indentations and more refactors --- .../entities/class-tainacan-taxonomy.php | 19 +++++++-------- .../class-tainacan-repository.php | 24 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/classes/entities/class-tainacan-taxonomy.php b/src/classes/entities/class-tainacan-taxonomy.php index 3139f7d40..9adf2f3e7 100644 --- a/src/classes/entities/class-tainacan-taxonomy.php +++ b/src/classes/entities/class-tainacan-taxonomy.php @@ -44,8 +44,8 @@ class Taxonomy extends Entity { */ static $db_identifier_prefix = 'tnc_tax_'; - public function __toString(){ - return apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this); + public function __toString() { + return (string) apply_filters("tainacan-taxonomy-to-string", $this->get_name(), $this); } /** @@ -54,18 +54,19 @@ class Taxonomy extends Entity { * @return bool */ function tainacan_register_taxonomy() { - $labels = array( - 'name' => $this->get_name(), - 'singular_name' => $this->get_name(), - 'search_items' => __( sprintf('Search terms in %s', $this->get_name()), 'tainacan' ), - 'all_items' => __( sprintf('All terms in %s', $this->get_name()), 'tainacan' ), + $taxonomy_name = $this->get_name(); + $labels = array( + 'name' => $taxonomy_name, + 'singular_name' => $taxonomy_name, + 'search_items' => __( sprintf('Search terms in %s', $taxonomy_name), 'tainacan' ), + 'all_items' => __( sprintf('All terms in %s', $taxonomy_name), 'tainacan' ), 'parent_item' => __( 'Parent term', 'tainacan' ), 'parent_item_colon' => __( 'Parent term:', 'tainacan' ), 'edit_item' => __( 'Edit term', 'tainacan' ), 'update_item' => __( 'Update term', 'tainacan' ), 'add_new_item' => __( 'Add New term', 'tainacan' ), 'new_item_name' => __( 'New Genre term', 'tainacan' ), - 'menu_name' => $this->get_name(), + 'menu_name' => $taxonomy_name, ); $enabled_post_types = $this->get_enabled_post_types(); @@ -88,8 +89,6 @@ class Taxonomy extends Entity { unregister_taxonomy($this->get_db_identifier()); } - - register_taxonomy( $this->get_db_identifier(), $enabled_post_types, diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index d859ea4ec..dc2df52db 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -144,10 +144,10 @@ abstract class Repository { } $obj->WP_Post->post_type = $obj::get_post_type(); - if ( $obj instanceof Entities\Taxonomy ) { - $sanitized = $this->sanitize_value($obj->get('name')); - $obj->WP_Post->post_title = $sanitized; - } + if ( $obj instanceof Entities\Taxonomy ) { + $sanitized = $this->sanitize_value($obj->get('name')); + $obj->WP_Post->post_title = $sanitized; + } if ( $obj instanceof Entities\Log && ! ( isset( $obj->WP_Post->post_status ) && in_array( $obj->WP_Post->post_status, [ 'publish', @@ -157,8 +157,8 @@ abstract class Repository { } if ( $obj instanceof Entities\Item ) { - $sanitized_title = $this->sanitize_value($obj->get('title')); - $sanitized_desc = $this->sanitize_value($obj->get('description')); + $sanitized_title = $this->sanitize_value($obj->get('title')); + $sanitized_desc = $this->sanitize_value($obj->get('description')); // get collection to determine post type $collection = $obj->get_collection(); @@ -169,21 +169,21 @@ abstract class Repository { $post_t = $collection->get_db_identifier(); $obj->WP_Post->post_type = $post_t; - $obj->WP_Post->post_title = $sanitized_title; - $obj->WP_Post->post_content = $sanitized_desc; + $obj->WP_Post->post_title = $sanitized_title; + $obj->WP_Post->post_content = $sanitized_desc; $obj_post_type = 'tainacan-item'; do_action( "tainacan-pre-insert-$obj_post_type", $obj ); } if ($obj instanceof Entities\Collection || $obj instanceof Entities\Metadatum) { - $sanitized = $this->sanitize_value($obj->get('name')); - $obj->WP_Post->post_title = $sanitized; - } + $sanitized = $this->sanitize_value($obj->get('name')); + $obj->WP_Post->post_title = $sanitized; + } $id = wp_insert_post( $obj->WP_Post ); if ($id instanceof \WP_Error || 0 === $id) { return false; - } + } // reset object $obj->WP_Post = get_post( $id );