| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Bulk_Editor\Domain\Updates; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class describes a title, description and/or focus keyphrase update for a single post. |
| 8 |
*/ |
| 9 |
class Post_Update { |
| 10 |
|
| 11 |
/** |
| 12 |
* The ID of the post to update. |
| 13 |
* |
| 14 |
* @var int |
| 15 |
*/ |
| 16 |
private $post_id; |
| 17 |
|
| 18 |
/** |
| 19 |
* The new title, or null when the title should be left untouched. |
| 20 |
* |
| 21 |
* @var string|null |
| 22 |
*/ |
| 23 |
private $title; |
| 24 |
|
| 25 |
/** |
| 26 |
* The new description, or null when the description should be left untouched. |
| 27 |
* |
| 28 |
* @var string|null |
| 29 |
*/ |
| 30 |
private $description; |
| 31 |
|
| 32 |
/** |
| 33 |
* The new focus keyphrase, or null when the focus keyphrase should be left untouched. |
| 34 |
* |
| 35 |
* @var string|null |
| 36 |
*/ |
| 37 |
private $focus_keyphrase; |
| 38 |
|
| 39 |
/** |
| 40 |
* The constructor. |
| 41 |
* |
| 42 |
* @param int $post_id The ID of the post to update. |
| 43 |
* @param string|null $title The new title, or null to leave the title untouched. |
| 44 |
* @param string|null $description The new description, or null to leave the description untouched. |
| 45 |
* @param string|null $focus_keyphrase The new focus keyphrase, or null to leave the focus keyphrase untouched. |
| 46 |
*/ |
| 47 |
public function __construct( int $post_id, ?string $title, ?string $description, ?string $focus_keyphrase ) { |
| 48 |
$this->post_id = $post_id; |
| 49 |
$this->title = $title; |
| 50 |
$this->description = $description; |
| 51 |
$this->focus_keyphrase = $focus_keyphrase; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Gets the ID of the post to update. |
| 56 |
* |
| 57 |
* @return int The ID of the post to update. |
| 58 |
*/ |
| 59 |
public function get_post_id(): int { |
| 60 |
return $this->post_id; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Gets the new title. |
| 65 |
* |
| 66 |
* @return string|null The new title, or null when the title should be left untouched. |
| 67 |
*/ |
| 68 |
public function get_title(): ?string { |
| 69 |
return $this->title; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Gets the new description. |
| 74 |
* |
| 75 |
* @return string|null The new description, or null when the description should be left untouched. |
| 76 |
*/ |
| 77 |
public function get_description(): ?string { |
| 78 |
return $this->description; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Gets the new focus keyphrase. |
| 83 |
* |
| 84 |
* @return string|null The new focus keyphrase, or null when the focus keyphrase should be left untouched. |
| 85 |
*/ |
| 86 |
public function get_focus_keyphrase(): ?string { |
| 87 |
return $this->focus_keyphrase; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Whether this update carries a title. An empty string is a value: it clears the title. |
| 92 |
* |
| 93 |
* @return bool Whether this update carries a title. |
| 94 |
*/ |
| 95 |
public function has_title(): bool { |
| 96 |
return $this->title !== null; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Whether this update carries a description. An empty string is a value: it clears the description. |
| 101 |
* |
| 102 |
* @return bool Whether this update carries a description. |
| 103 |
*/ |
| 104 |
public function has_description(): bool { |
| 105 |
return $this->description !== null; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Whether this update carries a focus keyphrase. An empty string is a value: it clears the focus keyphrase. |
| 110 |
* |
| 111 |
* @return bool Whether this update carries a focus keyphrase. |
| 112 |
*/ |
| 113 |
public function has_focus_keyphrase(): bool { |
| 114 |
return $this->focus_keyphrase !== null; |
| 115 |
} |
| 116 |
} |
| 117 |
|