From 65979a1101b9220eaae9bb01fdc7634546c8916a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Tue, 10 Nov 2020 06:48:18 +0100 Subject: [PATCH] Explicit programming in Post_Object --- src/Post_Type/Post_Object.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Post_Type/Post_Object.php b/src/Post_Type/Post_Object.php index 7a1f65cf..4f2524c2 100644 --- a/src/Post_Type/Post_Object.php +++ b/src/Post_Type/Post_Object.php @@ -27,7 +27,8 @@ class Post_Object { /** @var Meta_Map */ protected $meta; - protected $post_id = 0; + /** @var int */ + protected $post_id; /** * Post_Object constructor. @@ -39,11 +40,12 @@ class Post_Object { */ public function __construct( $post_id = 0, Meta_Map $meta = null ) { $this->post_id = $post_id; - if ( isset( $meta ) ) { - $this->meta = $meta; - } else { + if ( ! $meta instanceof Meta_Map ) { $this->meta = new Meta_Map( static::NAME ); + return; } + + $this->meta = $meta; } public function __get( $key ) { @@ -69,13 +71,12 @@ public function get_meta( $key ) { * @return static */ public static function factory( $post_id ) { - /** @var Meta_Repository $meta_repo */ $meta_repo = apply_filters( Meta_Repository::GET_REPO_FILTER, null ); - if ( empty( $meta_repo ) ) { + if ( ! $meta_repo instanceof Meta_Repository ) { $meta_repo = new Meta_Repository(); } $post_type = static::NAME; - if ( empty( $post_type ) ) { + if ( '' === $post_type ) { $post_type = get_post_type( $post_id ); } $post = new static( $post_id, $meta_repo->get( $post_type ) );