@@ -20,86 +20,86 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class Post_Id_To_Entity_Transform_Function implements Mappings_Transform_Function { |
| 22 | 22 | |
| 23 | - public function __construct() { |
|
| 23 | + public function __construct() { |
|
| 24 | 24 | |
| 25 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
| 25 | + add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
| 26 | 26 | |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Hook to add ourselves to the list of available transform functions. |
|
| 31 | - * |
|
| 32 | - * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
| 33 | - * |
|
| 34 | - * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
| 35 | - */ |
|
| 36 | - public function wl_mappings_transformation_functions( $value ) { |
|
| 29 | + /** |
|
| 30 | + * Hook to add ourselves to the list of available transform functions. |
|
| 31 | + * |
|
| 32 | + * @param Mappings_Transform_Function[] $value An array of {@link Mappings_Transform_Function}s. |
|
| 33 | + * |
|
| 34 | + * @return Mappings_Transform_Function[] An updated array with ourselves too. |
|
| 35 | + */ |
|
| 36 | + public function wl_mappings_transformation_functions( $value ) { |
|
| 37 | 37 | |
| 38 | - $value[] = $this; |
|
| 38 | + $value[] = $this; |
|
| 39 | 39 | |
| 40 | - return $value; |
|
| 41 | - } |
|
| 40 | + return $value; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @inheritDoc |
|
| 45 | - */ |
|
| 46 | - public function get_name() { |
|
| 43 | + /** |
|
| 44 | + * @inheritDoc |
|
| 45 | + */ |
|
| 46 | + public function get_name() { |
|
| 47 | 47 | |
| 48 | - return 'post_id_to_entity'; |
|
| 49 | - } |
|
| 48 | + return 'post_id_to_entity'; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @inheritDoc |
|
| 53 | - */ |
|
| 54 | - public function get_label() { |
|
| 51 | + /** |
|
| 52 | + * @inheritDoc |
|
| 53 | + */ |
|
| 54 | + public function get_label() { |
|
| 55 | 55 | |
| 56 | - return __( 'Post ID to Entity', 'wordlift' ); |
|
| 57 | - } |
|
| 56 | + return __( 'Post ID to Entity', 'wordlift' ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @inheritDoc |
|
| 61 | - */ |
|
| 62 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
| 59 | + /** |
|
| 60 | + * @inheritDoc |
|
| 61 | + */ |
|
| 62 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 63 | + public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
| 64 | 64 | |
| 65 | - $ret_val = array(); |
|
| 66 | - foreach ( (array) $data as $target_post_id ) { |
|
| 65 | + $ret_val = array(); |
|
| 66 | + foreach ( (array) $data as $target_post_id ) { |
|
| 67 | 67 | |
| 68 | - // We may receive a `WP_Post` here, in which case we want the ID. |
|
| 69 | - if ( is_a( $target_post_id, '\WP_Post' ) ) { |
|
| 70 | - $target_post_id = $target_post_id->ID; |
|
| 71 | - } |
|
| 68 | + // We may receive a `WP_Post` here, in which case we want the ID. |
|
| 69 | + if ( is_a( $target_post_id, '\WP_Post' ) ) { |
|
| 70 | + $target_post_id = $target_post_id->ID; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // We need a numeric post ID. |
|
| 74 | - if ( ! is_numeric( $target_post_id ) ) { |
|
| 73 | + // We need a numeric post ID. |
|
| 74 | + if ( ! is_numeric( $target_post_id ) ) { |
|
| 75 | 75 | |
| 76 | - $class_name = get_class( $target_post_id ); |
|
| 76 | + $class_name = get_class( $target_post_id ); |
|
| 77 | 77 | |
| 78 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 79 | - @header( "X-Post-Id-To-Entity-Transform-Function: $class_name is not numeric." ); |
|
| 78 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 79 | + @header( "X-Post-Id-To-Entity-Transform-Function: $class_name is not numeric." ); |
|
| 80 | 80 | |
| 81 | - continue; |
|
| 82 | - } |
|
| 81 | + continue; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - // Get the entity by URI. |
|
| 85 | - $entity_url = Wordpress_Content_Service::get_instance() |
|
| 86 | - ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
| 84 | + // Get the entity by URI. |
|
| 85 | + $entity_url = Wordpress_Content_Service::get_instance() |
|
| 86 | + ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
| 87 | 87 | |
| 88 | - // No entity URL. |
|
| 89 | - if ( empty( $entity_url ) ) { |
|
| 90 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 91 | - @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
| 88 | + // No entity URL. |
|
| 89 | + if ( empty( $entity_url ) ) { |
|
| 90 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 91 | + @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
| 92 | 92 | |
| 93 | - continue; |
|
| 94 | - } |
|
| 93 | + continue; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - // Add the entity among the references using the post ID. |
|
| 97 | - $references[] = (int) $target_post_id; |
|
| 96 | + // Add the entity among the references using the post ID. |
|
| 97 | + $references[] = (int) $target_post_id; |
|
| 98 | 98 | |
| 99 | - $ret_val[] = array( '@id' => $entity_url ); |
|
| 100 | - } |
|
| 99 | + $ret_val[] = array( '@id' => $entity_url ); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return $ret_val; |
|
| 103 | - } |
|
| 102 | + return $ret_val; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | public function __construct() { |
| 24 | 24 | |
| 25 | - add_filter( 'wl_mappings_transformation_functions', array( $this, 'wl_mappings_transformation_functions' ) ); |
|
| 25 | + add_filter('wl_mappings_transformation_functions', array($this, 'wl_mappings_transformation_functions')); |
|
| 26 | 26 | |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @return Mappings_Transform_Function[] An updated array with ourselves too. |
| 35 | 35 | */ |
| 36 | - public function wl_mappings_transformation_functions( $value ) { |
|
| 36 | + public function wl_mappings_transformation_functions($value) { |
|
| 37 | 37 | |
| 38 | 38 | $value[] = $this; |
| 39 | 39 | |
@@ -53,42 +53,42 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function get_label() { |
| 55 | 55 | |
| 56 | - return __( 'Post ID to Entity', 'wordlift' ); |
|
| 56 | + return __('Post ID to Entity', 'wordlift'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * @inheritDoc |
| 61 | 61 | */ |
| 62 | 62 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 63 | - public function transform_data( $data, $jsonld, &$references, $post_id ) { |
|
| 63 | + public function transform_data($data, $jsonld, &$references, $post_id) { |
|
| 64 | 64 | |
| 65 | 65 | $ret_val = array(); |
| 66 | - foreach ( (array) $data as $target_post_id ) { |
|
| 66 | + foreach ((array) $data as $target_post_id) { |
|
| 67 | 67 | |
| 68 | 68 | // We may receive a `WP_Post` here, in which case we want the ID. |
| 69 | - if ( is_a( $target_post_id, '\WP_Post' ) ) { |
|
| 69 | + if (is_a($target_post_id, '\WP_Post')) { |
|
| 70 | 70 | $target_post_id = $target_post_id->ID; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // We need a numeric post ID. |
| 74 | - if ( ! is_numeric( $target_post_id ) ) { |
|
| 74 | + if ( ! is_numeric($target_post_id)) { |
|
| 75 | 75 | |
| 76 | - $class_name = get_class( $target_post_id ); |
|
| 76 | + $class_name = get_class($target_post_id); |
|
| 77 | 77 | |
| 78 | 78 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 79 | - @header( "X-Post-Id-To-Entity-Transform-Function: $class_name is not numeric." ); |
|
| 79 | + @header("X-Post-Id-To-Entity-Transform-Function: $class_name is not numeric."); |
|
| 80 | 80 | |
| 81 | 81 | continue; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Get the entity by URI. |
| 85 | 85 | $entity_url = Wordpress_Content_Service::get_instance() |
| 86 | - ->get_entity_id( Wordpress_Content_Id::create_post( $target_post_id ) ); |
|
| 86 | + ->get_entity_id(Wordpress_Content_Id::create_post($target_post_id)); |
|
| 87 | 87 | |
| 88 | 88 | // No entity URL. |
| 89 | - if ( empty( $entity_url ) ) { |
|
| 89 | + if (empty($entity_url)) { |
|
| 90 | 90 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 91 | - @header( "X-Post-Id-To-Entity-Transform-Function: entity url for $data not found." ); |
|
| 91 | + @header("X-Post-Id-To-Entity-Transform-Function: entity url for $data not found."); |
|
| 92 | 92 | |
| 93 | 93 | continue; |
| 94 | 94 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | // Add the entity among the references using the post ID. |
| 97 | 97 | $references[] = (int) $target_post_id; |
| 98 | 98 | |
| 99 | - $ret_val[] = array( '@id' => $entity_url ); |
|
| 99 | + $ret_val[] = array('@id' => $entity_url); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | return $ret_val; |