From 1efbb4dcd0dcc63c03b0b9a5463a903cf84c2fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Thu, 30 Nov 2023 08:46:15 +0100 Subject: [PATCH] hotfix: phpcs error: introduce getter function for wp_post in the transformer --- includes/transformer/class-base.php | 9 +++++++++ includes/transformer/class-post.php | 14 ++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/includes/transformer/class-base.php b/includes/transformer/class-base.php index ec6f5d1..532d9c6 100644 --- a/includes/transformer/class-base.php +++ b/includes/transformer/class-base.php @@ -28,6 +28,15 @@ abstract class Base { */ protected $wp_post; + /** + * Getter function for this wp_post. + * + * @return WP_post This WordPress Post object. + */ + protected function get_wp_post() { + return $this->wp_post; + } + /** * Assign WP_Post Object to a specific transformer instance. * diff --git a/includes/transformer/class-post.php b/includes/transformer/class-post.php index 068bf63..ee41744 100644 --- a/includes/transformer/class-post.php +++ b/includes/transformer/class-post.php @@ -107,7 +107,7 @@ class Post extends Base { return $object_type; } - /** + /** * Transforms the WP_Post object to an ActivityPub Object * * @see \Activitypub\Activity\Base_Object @@ -116,20 +116,18 @@ class Post extends Base { * @return \Activitypub\Activity\Base_Object The ActivityPub Object */ public function transform() { - if ( ! $this->wp_post ) { - return; - } - $object = new Base_Object(); + $object = new Base_Objet(); + $wp_post = $this->get_wp_post(); $object->set_id( $this->get_id() ); $object->set_url( $this->get_url() ); $object->set_type( $this->get_object_type() ); - $published = \strtotime( $this->$wp_post->post_date_gmt ); + $published = \strtotime( $wp_post->post_date_gmt ); $object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) ); - $updated = \strtotime( $this->$wp_post->post_modified_gmt ); + $updated = \strtotime( $wp_post->post_modified_gmt ); if ( $updated > $published ) { $object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) ); @@ -138,7 +136,7 @@ class Post extends Base { $object->set_attributed_to( $this->get_attributed_to() ); $object->set_content( $this->get_content() ); $object->set_content_map( $this->get_content_map ); - $path = sprintf( 'users/%d/followers', intval( $this->$wp_post->post_author ) ); + $path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) ); $object->set_to( array(