id = $id; $this->type = ( self::TYPE_TERM === $type ) ? self::TYPE_TERM : self::TYPE_POST; $this->title = $title; $this->status = $status; $this->slug = $slug; } /** * Returns whether this item is a post (vs. a term). * * @since 1.0.0 * * @return bool True when the item is a post. */ public function is_post(): bool { return self::TYPE_POST === $this->type; } /** * Returns whether this item is a taxonomy term (vs. a post). * * @since 1.0.0 * * @return bool True when the item is a term. */ public function is_term(): bool { return self::TYPE_TERM === $this->type; } /** * Returns a stable composite key uniquely identifying this item. * * Useful when building lookup tables that contain both posts and terms. * Format: `post:123` or `term:45`. * * @since 1.0.0 * * @return string Composite key. */ public function get_key(): string { return $this->type . ':' . $this->id; } /** * Returns a copy of this model with a different title. * * @since 1.0.0 * * @param string $title The new title. * * @return self */ public function with_title( string $title ): self { return new self( $this->id, $this->type, $title, $this->status, $this->slug ); } }