Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit programming in Post_Object #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/Post_Type/Post_Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class Post_Object {
/** @var Meta_Map */
protected $meta;

protected $post_id = 0;
/** @var int */
protected $post_id;

/**
* Post_Object constructor.
Expand All @@ -38,11 +39,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 ) {
Expand Down Expand Up @@ -71,13 +73,13 @@ public static function factory( $post_id ) {
/** @var Meta_Repository|null $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 );
}

Expand Down