1414 *
1515 * @property string $page_template
1616 *
17- * @property-read int[] $ancestors
18- * @property-read int[] $post_category
19- * @property-read string[] $tags_input
17+ * @property-read list<non-negative-int> $ancestors
18+ * @property-read list<non-negative-int> $post_category
19+ * @property-read list<non-empty-string> $tags_input
20+ *
21+ * @phpstan-type Data_Array array{
22+ * ID: non-negative-int,
23+ * post_author: numeric-string|'',
24+ * post_date: string,
25+ * post_date_gmt: string,
26+ * post_content: string,
27+ * post_title: string,
28+ * post_excerpt: string,
29+ * post_status: non-empty-string,
30+ * comment_status: non-empty-string,
31+ * ping_status: non-empty-string,
32+ * post_password: string,
33+ * post_name: string,
34+ * to_ping: string,
35+ * pinged: string,
36+ * post_modified: string,
37+ * post_modified_gmt: string,
38+ * post_content_filtered: string,
39+ * post_parent: non-negative-int,
40+ * guid: string,
41+ * menu_order: int,
42+ * post_type: non-empty-string,
43+ * post_mime_type: string,
44+ * comment_count: numeric-string,
45+ * filter: 'raw'|'edit'|'db'|'display'|'attribute'|'js'|'sample'|null,
46+ * ancestors: list<non-negative-int>,
47+ * page_template: string,
48+ * post_category: list<non-negative-int>,
49+ * tags_input: list<non-empty-string>,
50+ * ...
51+ * }
2052 */
2153#[AllowDynamicProperties]
2254final class WP_Post {
@@ -26,17 +58,19 @@ final class WP_Post {
2658 *
2759 * @since 3.5.0
2860 * @var int
61+ * @phpstan-var non-negative-int
2962 */
3063 public $ ID ;
3164
3265 /**
3366 * ID of post author.
3467 *
35- * A numeric string, for compatibility reasons.
68+ * A numeric string, for compatibility reasons. May be an empty string for a
69+ * default post that has not yet been assigned an author.
3670 *
3771 * @since 3.5.0
3872 * @var string
39- * @phpstan-var numeric-string
73+ * @phpstan-var numeric-string|''
4074 */
4175 public $ post_author = '0 ' ;
4276
@@ -85,6 +119,7 @@ final class WP_Post {
85119 *
86120 * @since 3.5.0
87121 * @var string
122+ * @phpstan-var non-empty-string
88123 */
89124 public $ post_status = 'publish ' ;
90125
@@ -93,6 +128,7 @@ final class WP_Post {
93128 *
94129 * @since 3.5.0
95130 * @var string
131+ * @phpstan-var non-empty-string
96132 */
97133 public $ comment_status = 'open ' ;
98134
@@ -101,6 +137,7 @@ final class WP_Post {
101137 *
102138 * @since 3.5.0
103139 * @var string
140+ * @phpstan-var non-empty-string
104141 */
105142 public $ ping_status = 'open ' ;
106143
@@ -165,6 +202,7 @@ final class WP_Post {
165202 *
166203 * @since 3.5.0
167204 * @var int
205+ * @phpstan-var non-negative-int
168206 */
169207 public $ post_parent = 0 ;
170208
@@ -189,6 +227,7 @@ final class WP_Post {
189227 *
190228 * @since 3.5.0
191229 * @var string
230+ * @phpstan-var non-empty-string
192231 */
193232 public $ post_type = 'post ' ;
194233
@@ -216,9 +255,11 @@ final class WP_Post {
216255 *
217256 * Does not correspond to a DB field.
218257 *
258+ * The 'sample' value is set exclusively by {@see get_sample_permalink()} and is read during permalink previewing.
259+ *
219260 * @since 3.5.0
220- * @var string
221- * @phpstan-var 'raw'|'edit'|'db'|'display'|'attribute'|'js'
261+ * @var string|null
262+ * @phpstan-var 'raw'|'edit'|'db'|'display'|'attribute'|'js'|'sample'|null
222263 */
223264 public $ filter ;
224265
@@ -389,10 +430,9 @@ public function filter( $filter ) {
389430 *
390431 * @return array<string, mixed> Object as array.
391432 *
392- * @phpstan-return non-empty-array<string, mixed>
433+ * @phpstan-return Data_Array
393434 */
394435 public function to_array () {
395- /** @var non-empty-array<string, mixed> $post */
396436 $ post = get_object_vars ( $ this );
397437
398438 foreach ( array ( 'ancestors ' , 'page_template ' , 'post_category ' , 'tags_input ' ) as $ key ) {
@@ -401,6 +441,7 @@ public function to_array() {
401441 }
402442 }
403443
444+ /** @var Data_Array $post */
404445 return $ post ;
405446 }
406447}
0 commit comments