Completed
Pull Request — develop (#1698)
by
unknown
01:26
created
src/wordlift/lod-import/index.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,6 +4,6 @@
 block discarded – undo
4 4
 
5 5
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
6 6
 if ( apply_filters( 'wl_feature__enable__lod-import', false ) ) {
7
-	$lod_import = new Lod_Import();
8
-	$lod_import->register_hooks();
7
+    $lod_import = new Lod_Import();
8
+    $lod_import->register_hooks();
9 9
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 use Wordlift\Lod_Import\Lod_Import;
4 4
 
5 5
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
6
-if ( apply_filters( 'wl_feature__enable__lod-import', false ) ) {
6
+if (apply_filters('wl_feature__enable__lod-import', false)) {
7 7
 	$lod_import = new Lod_Import();
8 8
 	$lod_import->register_hooks();
9 9
 }
Please login to merge, or discard this patch.
src/wordlift/lod-import/class-lod-import.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 
11 11
 class Lod_Import {
12 12
 
13
-	public function __construct() {
13
+    public function __construct() {
14 14
 
15
-	}
15
+    }
16 16
 
17
-	public function register_hooks() {
18
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
19
-	}
17
+    public function register_hooks() {
18
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
19
+    }
20 20
 
21
-	public function admin_menu() {
21
+    public function admin_menu() {
22 22
 
23
-		$callback = isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ? 'handle' : 'render';
23
+        $callback = isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ? 'handle' : 'render';
24 24
 
25
-		add_submenu_page(
26
-			'wl_admin_menu',
27
-			__( 'LOD Import', 'wordlift' ),
28
-			__( 'LOD Import', 'wordlift' ),
29
-			'manage_options',
30
-			'wl_lod_import',
31
-			array( $this, $callback )
32
-		);
33
-	}
25
+        add_submenu_page(
26
+            'wl_admin_menu',
27
+            __( 'LOD Import', 'wordlift' ),
28
+            __( 'LOD Import', 'wordlift' ),
29
+            'manage_options',
30
+            'wl_lod_import',
31
+            array( $this, $callback )
32
+        );
33
+    }
34 34
 
35
-	public function render() {
36
-		?>
35
+    public function render() {
36
+        ?>
37 37
 		<div class="wrap">
38 38
 			<h1><?php esc_html_e( 'LOD Import', 'wordlift' ); ?></h1>
39 39
 			<p><?php esc_html_e( 'Helpful stuff here', 'wordlift' ); ?></p>
@@ -48,38 +48,38 @@  discard block
 block discarded – undo
48 48
 		</div>
49 49
 		<?php
50 50
 
51
-	}
51
+    }
52 52
 
53
-	public function handle() {
54
-		$item_ids = filter_input( INPUT_POST, 'item-ids' );
55
-		if ( ! $item_ids ) {
56
-			?>
53
+    public function handle() {
54
+        $item_ids = filter_input( INPUT_POST, 'item-ids' );
55
+        if ( ! $item_ids ) {
56
+            ?>
57 57
 			<p class="notice notice-error">Please type stgh</p>
58 58
 			<?php
59
-			return;
60
-		}
59
+            return;
60
+        }
61 61
 
62
-		foreach ( preg_split( '(\r\n|\r|\n)', $item_ids ) as $item_id ) {
63
-			$this->import_single( $item_id );
64
-		}
65
-	}
62
+        foreach ( preg_split( '(\r\n|\r|\n)', $item_ids ) as $item_id ) {
63
+            $this->import_single( $item_id );
64
+        }
65
+    }
66 66
 
67
-	private function import_single( $item_id ) {
67
+    private function import_single( $item_id ) {
68 68
 
69
-		$content_service = Wordpress_Content_Service::get_instance();
69
+        $content_service = Wordpress_Content_Service::get_instance();
70 70
 
71
-		// Do not create/update an existing entity.
72
-		if ( $content_service->get_by_entity_id_or_same_as( $item_id ) ) {
73
-			return;
74
-		}
71
+        // Do not create/update an existing entity.
72
+        if ( $content_service->get_by_entity_id_or_same_as( $item_id ) ) {
73
+            return;
74
+        }
75 75
 
76
-		$remote_entity = Url_To_Remote_Entity_Converter::convert( $item_id );
77
-		$importer      = Remote_Entity_Importer_Factory::from_entity( $remote_entity );
78
-		$content_id    = $importer->import();
79
-		if ( $content_id instanceof Content_Id && $content_id->get_type() === Object_Type_Enum::POST ) {
80
-			edit_post_link( null, null, null, $content_id->get_id() );
81
-		}
76
+        $remote_entity = Url_To_Remote_Entity_Converter::convert( $item_id );
77
+        $importer      = Remote_Entity_Importer_Factory::from_entity( $remote_entity );
78
+        $content_id    = $importer->import();
79
+        if ( $content_id instanceof Content_Id && $content_id->get_type() === Object_Type_Enum::POST ) {
80
+            edit_post_link( null, null, null, $content_id->get_id() );
81
+        }
82 82
 
83
-	}
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -15,35 +15,35 @@  discard block
 block discarded – undo
15 15
 	}
16 16
 
17 17
 	public function register_hooks() {
18
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
18
+		add_action('admin_menu', array($this, 'admin_menu'));
19 19
 	}
20 20
 
21 21
 	public function admin_menu() {
22 22
 
23
-		$callback = isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ? 'handle' : 'render';
23
+		$callback = isset($_SERVER['REQUEST_METHOD']) && 'POST' === sanitize_text_field(wp_unslash($_SERVER['REQUEST_METHOD'])) ? 'handle' : 'render';
24 24
 
25 25
 		add_submenu_page(
26 26
 			'wl_admin_menu',
27
-			__( 'LOD Import', 'wordlift' ),
28
-			__( 'LOD Import', 'wordlift' ),
27
+			__('LOD Import', 'wordlift'),
28
+			__('LOD Import', 'wordlift'),
29 29
 			'manage_options',
30 30
 			'wl_lod_import',
31
-			array( $this, $callback )
31
+			array($this, $callback)
32 32
 		);
33 33
 	}
34 34
 
35 35
 	public function render() {
36 36
 		?>
37 37
 		<div class="wrap">
38
-			<h1><?php esc_html_e( 'LOD Import', 'wordlift' ); ?></h1>
39
-			<p><?php esc_html_e( 'Helpful stuff here', 'wordlift' ); ?></p>
38
+			<h1><?php esc_html_e('LOD Import', 'wordlift'); ?></h1>
39
+			<p><?php esc_html_e('Helpful stuff here', 'wordlift'); ?></p>
40 40
 			<form method="post" novalidate="novalidate">
41 41
 				<div class="form-field">
42
-					<label for="item-ids"><?php esc_html_e( 'Linked Data IDs', 'wordlift' ); ?></label>
42
+					<label for="item-ids"><?php esc_html_e('Linked Data IDs', 'wordlift'); ?></label>
43 43
 					<textarea name="item-ids" id="item-ids" rows="5" cols="40"></textarea>
44
-					<p><?php esc_html_e( 'The description is not prominent by default; however, some themes may show it.', 'wordlift' ); ?></p>
44
+					<p><?php esc_html_e('The description is not prominent by default; however, some themes may show it.', 'wordlift'); ?></p>
45 45
 				</div>
46
-				<?php submit_button( 'Import' ); ?>
46
+				<?php submit_button('Import'); ?>
47 47
 			</form>
48 48
 		</div>
49 49
 		<?php
@@ -51,33 +51,33 @@  discard block
 block discarded – undo
51 51
 	}
52 52
 
53 53
 	public function handle() {
54
-		$item_ids = filter_input( INPUT_POST, 'item-ids' );
55
-		if ( ! $item_ids ) {
54
+		$item_ids = filter_input(INPUT_POST, 'item-ids');
55
+		if ( ! $item_ids) {
56 56
 			?>
57 57
 			<p class="notice notice-error">Please type stgh</p>
58 58
 			<?php
59 59
 			return;
60 60
 		}
61 61
 
62
-		foreach ( preg_split( '(\r\n|\r|\n)', $item_ids ) as $item_id ) {
63
-			$this->import_single( $item_id );
62
+		foreach (preg_split('(\r\n|\r|\n)', $item_ids) as $item_id) {
63
+			$this->import_single($item_id);
64 64
 		}
65 65
 	}
66 66
 
67
-	private function import_single( $item_id ) {
67
+	private function import_single($item_id) {
68 68
 
69 69
 		$content_service = Wordpress_Content_Service::get_instance();
70 70
 
71 71
 		// Do not create/update an existing entity.
72
-		if ( $content_service->get_by_entity_id_or_same_as( $item_id ) ) {
72
+		if ($content_service->get_by_entity_id_or_same_as($item_id)) {
73 73
 			return;
74 74
 		}
75 75
 
76
-		$remote_entity = Url_To_Remote_Entity_Converter::convert( $item_id );
77
-		$importer      = Remote_Entity_Importer_Factory::from_entity( $remote_entity );
76
+		$remote_entity = Url_To_Remote_Entity_Converter::convert($item_id);
77
+		$importer      = Remote_Entity_Importer_Factory::from_entity($remote_entity);
78 78
 		$content_id    = $importer->import();
79
-		if ( $content_id instanceof Content_Id && $content_id->get_type() === Object_Type_Enum::POST ) {
80
-			edit_post_link( null, null, null, $content_id->get_id() );
79
+		if ($content_id instanceof Content_Id && $content_id->get_type() === Object_Type_Enum::POST) {
80
+			edit_post_link(null, null, null, $content_id->get_id());
81 81
 		}
82 82
 
83 83
 	}
Please login to merge, or discard this patch.
src/wordlift/duplicate-markup-remover/class-duplicate-markup-remover.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -4,111 +4,111 @@
 block discarded – undo
4 4
 
5 5
 class Duplicate_Markup_Remover {
6 6
 
7
-	private $types_to_properties_map = array(
8
-		'HowTo'   => array(
9
-			'estimatedCost',
10
-			'totalTime',
11
-			'supply',
12
-			'tool',
13
-			'step',
14
-		),
15
-		'FAQPage' => array( 'mainEntity' ),
16
-		'Recipe'  => array(
17
-			'cookTime',
18
-			'cookingMethod',
19
-			'nutrition',
20
-			'recipeCategory',
21
-			'recipeCuisine',
22
-			'recipeIngredient',
23
-			'recipeInstructions',
24
-			'recipeYield',
25
-			'suitableForDiet',
26
-		),
27
-	);
28
-
29
-	public function __construct() {
30
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 );
31
-	}
32
-
33
-	/**
34
-	 * @param $jsonld array The final jsonld.
35
-	 *
36
-	 * @return array Filtered jsonld.
37
-	 */
38
-	public function wl_after_get_jsonld( $jsonld ) {
39
-
40
-		foreach ( $this->types_to_properties_map as $type_to_remove => $properties_to_remove ) {
41
-			$jsonld = $this->remove_type( $jsonld, $type_to_remove, $properties_to_remove );
42
-		}
43
-
44
-		return $jsonld;
45
-	}
46
-
47
-	/**
48
-	 * @param array $jsonld
49
-	 *
50
-	 * @return bool
51
-	 */
52
-	protected function should_alter_jsonld( $jsonld ) {
53
-		return ! is_array( $jsonld )
54
-			   || ! count( $jsonld ) > 1
55
-			   || ! array_key_exists( 0, $jsonld );
56
-	}
57
-
58
-	/**
59
-	 * @param array $jsonld
60
-	 *
61
-	 * @return array
62
-	 */
63
-	private function remove_type( $jsonld, $type_to_remove, $properties_to_remove ) {
64
-
65
-		if ( $this->should_alter_jsonld( $jsonld ) ) {
66
-			// Return early if there are no referenced entities.
67
-			return $jsonld;
68
-		}
69
-
70
-		$post_jsonld = array_shift( $jsonld );
71
-
72
-		// we need to loop through all the items and remove the faq markup.
73
-		foreach ( $jsonld as $key => &$value ) {
74
-			if ( ! array_key_exists( '@type', $value ) ) {
75
-				continue;
76
-			}
77
-			$type = $value['@type'];
78
-
79
-			/**
80
-			 * Two possibilities:
81
-			 * 1. The referenced entity has only supplied SchemaType markup, in that case remove the complete entity.
82
-			 * 2. The referenced entity has multiple types, in that case completely remove the supplied SchemaType markup, but
83
-			 * retain the other entity data.
84
-			 */
85
-			// If the referenced entity is purely supplied SchemaType markup, then remove it.
86
-
87
-			if ( is_string( $type ) && $type === $type_to_remove ) {
88
-				// Remove the entity completely.
89
-				unset( $jsonld[ $key ] );
90
-			}
91
-
92
-			if ( is_array( $type ) && in_array( $type_to_remove, $type, true ) ) {
93
-				// Remove the supplied SchemaType markup.
94
-				$position = array_search( $type_to_remove, $type, true );
95
-				// Also update the type.
96
-				if ( false !== $position ) {
97
-					unset( $type[ $position ] );
98
-					$value['@type'] = array_values( $type );
99
-				}
100
-
101
-				foreach ( $properties_to_remove as $property ) {
102
-					// Remove keys of supplied SchemaType.
103
-					unset( $value[ $property ] );
104
-				}
105
-			}
106
-		}
107
-
108
-		// Add the post jsonld to front of jsonld array.
109
-		array_unshift( $jsonld, $post_jsonld );
110
-
111
-		return $jsonld;
112
-	}
7
+    private $types_to_properties_map = array(
8
+        'HowTo'   => array(
9
+            'estimatedCost',
10
+            'totalTime',
11
+            'supply',
12
+            'tool',
13
+            'step',
14
+        ),
15
+        'FAQPage' => array( 'mainEntity' ),
16
+        'Recipe'  => array(
17
+            'cookTime',
18
+            'cookingMethod',
19
+            'nutrition',
20
+            'recipeCategory',
21
+            'recipeCuisine',
22
+            'recipeIngredient',
23
+            'recipeInstructions',
24
+            'recipeYield',
25
+            'suitableForDiet',
26
+        ),
27
+    );
28
+
29
+    public function __construct() {
30
+        add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 );
31
+    }
32
+
33
+    /**
34
+     * @param $jsonld array The final jsonld.
35
+     *
36
+     * @return array Filtered jsonld.
37
+     */
38
+    public function wl_after_get_jsonld( $jsonld ) {
39
+
40
+        foreach ( $this->types_to_properties_map as $type_to_remove => $properties_to_remove ) {
41
+            $jsonld = $this->remove_type( $jsonld, $type_to_remove, $properties_to_remove );
42
+        }
43
+
44
+        return $jsonld;
45
+    }
46
+
47
+    /**
48
+     * @param array $jsonld
49
+     *
50
+     * @return bool
51
+     */
52
+    protected function should_alter_jsonld( $jsonld ) {
53
+        return ! is_array( $jsonld )
54
+               || ! count( $jsonld ) > 1
55
+               || ! array_key_exists( 0, $jsonld );
56
+    }
57
+
58
+    /**
59
+     * @param array $jsonld
60
+     *
61
+     * @return array
62
+     */
63
+    private function remove_type( $jsonld, $type_to_remove, $properties_to_remove ) {
64
+
65
+        if ( $this->should_alter_jsonld( $jsonld ) ) {
66
+            // Return early if there are no referenced entities.
67
+            return $jsonld;
68
+        }
69
+
70
+        $post_jsonld = array_shift( $jsonld );
71
+
72
+        // we need to loop through all the items and remove the faq markup.
73
+        foreach ( $jsonld as $key => &$value ) {
74
+            if ( ! array_key_exists( '@type', $value ) ) {
75
+                continue;
76
+            }
77
+            $type = $value['@type'];
78
+
79
+            /**
80
+             * Two possibilities:
81
+             * 1. The referenced entity has only supplied SchemaType markup, in that case remove the complete entity.
82
+             * 2. The referenced entity has multiple types, in that case completely remove the supplied SchemaType markup, but
83
+             * retain the other entity data.
84
+             */
85
+            // If the referenced entity is purely supplied SchemaType markup, then remove it.
86
+
87
+            if ( is_string( $type ) && $type === $type_to_remove ) {
88
+                // Remove the entity completely.
89
+                unset( $jsonld[ $key ] );
90
+            }
91
+
92
+            if ( is_array( $type ) && in_array( $type_to_remove, $type, true ) ) {
93
+                // Remove the supplied SchemaType markup.
94
+                $position = array_search( $type_to_remove, $type, true );
95
+                // Also update the type.
96
+                if ( false !== $position ) {
97
+                    unset( $type[ $position ] );
98
+                    $value['@type'] = array_values( $type );
99
+                }
100
+
101
+                foreach ( $properties_to_remove as $property ) {
102
+                    // Remove keys of supplied SchemaType.
103
+                    unset( $value[ $property ] );
104
+                }
105
+            }
106
+        }
107
+
108
+        // Add the post jsonld to front of jsonld array.
109
+        array_unshift( $jsonld, $post_jsonld );
110
+
111
+        return $jsonld;
112
+    }
113 113
 
114 114
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 			'tool',
13 13
 			'step',
14 14
 		),
15
-		'FAQPage' => array( 'mainEntity' ),
15
+		'FAQPage' => array('mainEntity'),
16 16
 		'Recipe'  => array(
17 17
 			'cookTime',
18 18
 			'cookingMethod',
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	);
28 28
 
29 29
 	public function __construct() {
30
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 );
30
+		add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10);
31 31
 	}
32 32
 
33 33
 	/**
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @return array Filtered jsonld.
37 37
 	 */
38
-	public function wl_after_get_jsonld( $jsonld ) {
38
+	public function wl_after_get_jsonld($jsonld) {
39 39
 
40
-		foreach ( $this->types_to_properties_map as $type_to_remove => $properties_to_remove ) {
41
-			$jsonld = $this->remove_type( $jsonld, $type_to_remove, $properties_to_remove );
40
+		foreach ($this->types_to_properties_map as $type_to_remove => $properties_to_remove) {
41
+			$jsonld = $this->remove_type($jsonld, $type_to_remove, $properties_to_remove);
42 42
 		}
43 43
 
44 44
 		return $jsonld;
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @return bool
51 51
 	 */
52
-	protected function should_alter_jsonld( $jsonld ) {
53
-		return ! is_array( $jsonld )
54
-			   || ! count( $jsonld ) > 1
55
-			   || ! array_key_exists( 0, $jsonld );
52
+	protected function should_alter_jsonld($jsonld) {
53
+		return ! is_array($jsonld)
54
+			   || ! count($jsonld) > 1
55
+			   || ! array_key_exists(0, $jsonld);
56 56
 	}
57 57
 
58 58
 	/**
@@ -60,18 +60,18 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @return array
62 62
 	 */
63
-	private function remove_type( $jsonld, $type_to_remove, $properties_to_remove ) {
63
+	private function remove_type($jsonld, $type_to_remove, $properties_to_remove) {
64 64
 
65
-		if ( $this->should_alter_jsonld( $jsonld ) ) {
65
+		if ($this->should_alter_jsonld($jsonld)) {
66 66
 			// Return early if there are no referenced entities.
67 67
 			return $jsonld;
68 68
 		}
69 69
 
70
-		$post_jsonld = array_shift( $jsonld );
70
+		$post_jsonld = array_shift($jsonld);
71 71
 
72 72
 		// we need to loop through all the items and remove the faq markup.
73
-		foreach ( $jsonld as $key => &$value ) {
74
-			if ( ! array_key_exists( '@type', $value ) ) {
73
+		foreach ($jsonld as $key => &$value) {
74
+			if ( ! array_key_exists('@type', $value)) {
75 75
 				continue;
76 76
 			}
77 77
 			$type = $value['@type'];
@@ -84,29 +84,29 @@  discard block
 block discarded – undo
84 84
 			 */
85 85
 			// If the referenced entity is purely supplied SchemaType markup, then remove it.
86 86
 
87
-			if ( is_string( $type ) && $type === $type_to_remove ) {
87
+			if (is_string($type) && $type === $type_to_remove) {
88 88
 				// Remove the entity completely.
89
-				unset( $jsonld[ $key ] );
89
+				unset($jsonld[$key]);
90 90
 			}
91 91
 
92
-			if ( is_array( $type ) && in_array( $type_to_remove, $type, true ) ) {
92
+			if (is_array($type) && in_array($type_to_remove, $type, true)) {
93 93
 				// Remove the supplied SchemaType markup.
94
-				$position = array_search( $type_to_remove, $type, true );
94
+				$position = array_search($type_to_remove, $type, true);
95 95
 				// Also update the type.
96
-				if ( false !== $position ) {
97
-					unset( $type[ $position ] );
98
-					$value['@type'] = array_values( $type );
96
+				if (false !== $position) {
97
+					unset($type[$position]);
98
+					$value['@type'] = array_values($type);
99 99
 				}
100 100
 
101
-				foreach ( $properties_to_remove as $property ) {
101
+				foreach ($properties_to_remove as $property) {
102 102
 					// Remove keys of supplied SchemaType.
103
-					unset( $value[ $property ] );
103
+					unset($value[$property]);
104 104
 				}
105 105
 			}
106 106
 		}
107 107
 
108 108
 		// Add the post jsonld to front of jsonld array.
109
-		array_unshift( $jsonld, $post_jsonld );
109
+		array_unshift($jsonld, $post_jsonld);
110 110
 
111 111
 		return $jsonld;
112 112
 	}
Please login to merge, or discard this patch.
wordlift/duplicate-markup-remover/class-videoobject-duplicate-remover.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -10,47 +10,47 @@
 block discarded – undo
10 10
  */
11 11
 class Videoobject_Duplicate_Remover {
12 12
 
13
-	public function __construct() {
14
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 );
15
-	}
16
-
17
-	/**
18
-	 * @param $jsonld array The final jsonld.
19
-	 * @return array Filtered jsonld.
20
-	 */
21
-	public function wl_after_get_jsonld( $jsonld ) {
22
-
23
-		if ( ! is_array( $jsonld )
24
-			 || ! count( $jsonld ) > 1
25
-			 || ! array_key_exists( 0, $jsonld ) ) {
26
-			// Return early if there are no referenced entities.
27
-			return $jsonld;
28
-		}
29
-
30
-		$post_jsonld = array_shift( $jsonld );
31
-
32
-		// we need to loop through all the items and remove the faq markup.
33
-		foreach ( $jsonld as $key => &$value ) {
34
-			if ( ! array_key_exists( '@type', $value ) ) {
35
-				continue;
36
-			}
37
-			$type = $value['@type'];
38
-
39
-			if ( ( is_string( $type ) && 'Article' !== $type )
40
-				 || ( is_array( $type ) && ! in_array( 'Article', $type, true ) ) ) {
41
-				continue;
42
-			}
43
-			// Video doesnt exist, dont try to remove it.
44
-			if ( ! array_key_exists( 'video', $value ) ) {
45
-				continue;
46
-			}
47
-			unset( $jsonld[ $key ]['video'] );
48
-		}
49
-
50
-		// Add the post jsonld to front of jsonld array.
51
-		array_unshift( $jsonld, $post_jsonld );
52
-
53
-		return $jsonld;
54
-	}
13
+    public function __construct() {
14
+        add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 );
15
+    }
16
+
17
+    /**
18
+     * @param $jsonld array The final jsonld.
19
+     * @return array Filtered jsonld.
20
+     */
21
+    public function wl_after_get_jsonld( $jsonld ) {
22
+
23
+        if ( ! is_array( $jsonld )
24
+             || ! count( $jsonld ) > 1
25
+             || ! array_key_exists( 0, $jsonld ) ) {
26
+            // Return early if there are no referenced entities.
27
+            return $jsonld;
28
+        }
29
+
30
+        $post_jsonld = array_shift( $jsonld );
31
+
32
+        // we need to loop through all the items and remove the faq markup.
33
+        foreach ( $jsonld as $key => &$value ) {
34
+            if ( ! array_key_exists( '@type', $value ) ) {
35
+                continue;
36
+            }
37
+            $type = $value['@type'];
38
+
39
+            if ( ( is_string( $type ) && 'Article' !== $type )
40
+                 || ( is_array( $type ) && ! in_array( 'Article', $type, true ) ) ) {
41
+                continue;
42
+            }
43
+            // Video doesnt exist, dont try to remove it.
44
+            if ( ! array_key_exists( 'video', $value ) ) {
45
+                continue;
46
+            }
47
+            unset( $jsonld[ $key ]['video'] );
48
+        }
49
+
50
+        // Add the post jsonld to front of jsonld array.
51
+        array_unshift( $jsonld, $post_jsonld );
52
+
53
+        return $jsonld;
54
+    }
55 55
 
56 56
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,44 +11,44 @@
 block discarded – undo
11 11
 class Videoobject_Duplicate_Remover {
12 12
 
13 13
 	public function __construct() {
14
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10 );
14
+		add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10);
15 15
 	}
16 16
 
17 17
 	/**
18 18
 	 * @param $jsonld array The final jsonld.
19 19
 	 * @return array Filtered jsonld.
20 20
 	 */
21
-	public function wl_after_get_jsonld( $jsonld ) {
21
+	public function wl_after_get_jsonld($jsonld) {
22 22
 
23
-		if ( ! is_array( $jsonld )
24
-			 || ! count( $jsonld ) > 1
25
-			 || ! array_key_exists( 0, $jsonld ) ) {
23
+		if ( ! is_array($jsonld)
24
+			 || ! count($jsonld) > 1
25
+			 || ! array_key_exists(0, $jsonld)) {
26 26
 			// Return early if there are no referenced entities.
27 27
 			return $jsonld;
28 28
 		}
29 29
 
30
-		$post_jsonld = array_shift( $jsonld );
30
+		$post_jsonld = array_shift($jsonld);
31 31
 
32 32
 		// we need to loop through all the items and remove the faq markup.
33
-		foreach ( $jsonld as $key => &$value ) {
34
-			if ( ! array_key_exists( '@type', $value ) ) {
33
+		foreach ($jsonld as $key => &$value) {
34
+			if ( ! array_key_exists('@type', $value)) {
35 35
 				continue;
36 36
 			}
37 37
 			$type = $value['@type'];
38 38
 
39
-			if ( ( is_string( $type ) && 'Article' !== $type )
40
-				 || ( is_array( $type ) && ! in_array( 'Article', $type, true ) ) ) {
39
+			if ((is_string($type) && 'Article' !== $type)
40
+				 || (is_array($type) && ! in_array('Article', $type, true))) {
41 41
 				continue;
42 42
 			}
43 43
 			// Video doesnt exist, dont try to remove it.
44
-			if ( ! array_key_exists( 'video', $value ) ) {
44
+			if ( ! array_key_exists('video', $value)) {
45 45
 				continue;
46 46
 			}
47
-			unset( $jsonld[ $key ]['video'] );
47
+			unset($jsonld[$key]['video']);
48 48
 		}
49 49
 
50 50
 		// Add the post jsonld to front of jsonld array.
51
-		array_unshift( $jsonld, $post_jsonld );
51
+		array_unshift($jsonld, $post_jsonld);
52 52
 
53 53
 		return $jsonld;
54 54
 	}
Please login to merge, or discard this patch.
src/wordlift/content/wordpress/class-wordpress-content.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -11,89 +11,89 @@
 block discarded – undo
11 11
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
12 12
 class Wordpress_Content implements Content {
13 13
 
14
-	/**
15
-	 * The actual content.
16
-	 *
17
-	 * @var WP_Post|WP_Term|WP_User $bag
18
-	 */
19
-	private $bag;
20
-
21
-	/**
22
-	 * Creates a WordPress content instance.
23
-	 *
24
-	 * @param WP_Post|WP_Term|WP_User $bag
25
-	 */
26
-	public function __construct( $bag ) {
27
-		$this->bag = $bag;
28
-	}
29
-
30
-	/**
31
-	 * The actual content.
32
-	 *
33
-	 * @return WP_Post|WP_Term|WP_User
34
-	 */
35
-	public function get_bag() {
36
-		return $this->bag;
37
-	}
38
-
39
-	public function get_id() {
40
-		if ( ! is_object( $this->bag ) ) {
41
-			return null;
42
-		}
43
-
44
-		switch ( get_class( $this->bag ) ) {
45
-			case 'WP_Post':
46
-			case 'WP_User':
47
-				return $this->bag->ID;
48
-			case 'WP_Term':
49
-				return $this->bag->term_id;
50
-		}
51
-
52
-		return null;
53
-	}
54
-
55
-	public function get_object_type_enum() {
56
-		if ( ! is_object( $this->bag ) ) {
57
-			return null;
58
-		}
59
-
60
-		return Object_Type_Enum::from_wordpress_instance( $this->bag );
61
-	}
62
-
63
-	public function get_permalink() {
64
-		if ( ! is_object( $this->bag ) ) {
65
-			return null;
66
-		}
67
-
68
-		switch ( get_class( $this->bag ) ) {
69
-			case 'WP_Post':
70
-				return get_permalink( $this->get_bag()->ID );
71
-			case 'WP_User':
72
-				return get_author_posts_url( $this->get_bag()->ID );
73
-			case 'WP_Term':
74
-				return get_term_link( $this->bag->term_id );
75
-		}
76
-
77
-		return null;
78
-	}
79
-
80
-	public function get_edit_link() {
81
-		if ( ! is_object( $this->bag ) ) {
82
-			return null;
83
-		}
84
-
85
-		switch ( get_class( $this->bag ) ) {
86
-			case 'WP_Post':
87
-				// We need to return & character as &, by default context is set to display.
88
-				// so &  will be returned as &amp; breaking header location redirects.
89
-				// By setting context to none we prevent this issue.
90
-				return get_edit_post_link( $this->get_bag()->ID, 'none' );
91
-			case 'WP_User':
92
-				return get_edit_user_link( $this->get_bag()->ID );
93
-			case 'WP_Term':
94
-				return get_edit_term_link( $this->bag->term_id );
95
-		}
96
-
97
-		return null;
98
-	}
14
+    /**
15
+     * The actual content.
16
+     *
17
+     * @var WP_Post|WP_Term|WP_User $bag
18
+     */
19
+    private $bag;
20
+
21
+    /**
22
+     * Creates a WordPress content instance.
23
+     *
24
+     * @param WP_Post|WP_Term|WP_User $bag
25
+     */
26
+    public function __construct( $bag ) {
27
+        $this->bag = $bag;
28
+    }
29
+
30
+    /**
31
+     * The actual content.
32
+     *
33
+     * @return WP_Post|WP_Term|WP_User
34
+     */
35
+    public function get_bag() {
36
+        return $this->bag;
37
+    }
38
+
39
+    public function get_id() {
40
+        if ( ! is_object( $this->bag ) ) {
41
+            return null;
42
+        }
43
+
44
+        switch ( get_class( $this->bag ) ) {
45
+            case 'WP_Post':
46
+            case 'WP_User':
47
+                return $this->bag->ID;
48
+            case 'WP_Term':
49
+                return $this->bag->term_id;
50
+        }
51
+
52
+        return null;
53
+    }
54
+
55
+    public function get_object_type_enum() {
56
+        if ( ! is_object( $this->bag ) ) {
57
+            return null;
58
+        }
59
+
60
+        return Object_Type_Enum::from_wordpress_instance( $this->bag );
61
+    }
62
+
63
+    public function get_permalink() {
64
+        if ( ! is_object( $this->bag ) ) {
65
+            return null;
66
+        }
67
+
68
+        switch ( get_class( $this->bag ) ) {
69
+            case 'WP_Post':
70
+                return get_permalink( $this->get_bag()->ID );
71
+            case 'WP_User':
72
+                return get_author_posts_url( $this->get_bag()->ID );
73
+            case 'WP_Term':
74
+                return get_term_link( $this->bag->term_id );
75
+        }
76
+
77
+        return null;
78
+    }
79
+
80
+    public function get_edit_link() {
81
+        if ( ! is_object( $this->bag ) ) {
82
+            return null;
83
+        }
84
+
85
+        switch ( get_class( $this->bag ) ) {
86
+            case 'WP_Post':
87
+                // We need to return & character as &, by default context is set to display.
88
+                // so &  will be returned as &amp; breaking header location redirects.
89
+                // By setting context to none we prevent this issue.
90
+                return get_edit_post_link( $this->get_bag()->ID, 'none' );
91
+            case 'WP_User':
92
+                return get_edit_user_link( $this->get_bag()->ID );
93
+            case 'WP_Term':
94
+                return get_edit_term_link( $this->bag->term_id );
95
+        }
96
+
97
+        return null;
98
+    }
99 99
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param WP_Post|WP_Term|WP_User $bag
25 25
 	 */
26
-	public function __construct( $bag ) {
26
+	public function __construct($bag) {
27 27
 		$this->bag = $bag;
28 28
 	}
29 29
 
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	}
38 38
 
39 39
 	public function get_id() {
40
-		if ( ! is_object( $this->bag ) ) {
40
+		if ( ! is_object($this->bag)) {
41 41
 			return null;
42 42
 		}
43 43
 
44
-		switch ( get_class( $this->bag ) ) {
44
+		switch (get_class($this->bag)) {
45 45
 			case 'WP_Post':
46 46
 			case 'WP_User':
47 47
 				return $this->bag->ID;
@@ -53,45 +53,45 @@  discard block
 block discarded – undo
53 53
 	}
54 54
 
55 55
 	public function get_object_type_enum() {
56
-		if ( ! is_object( $this->bag ) ) {
56
+		if ( ! is_object($this->bag)) {
57 57
 			return null;
58 58
 		}
59 59
 
60
-		return Object_Type_Enum::from_wordpress_instance( $this->bag );
60
+		return Object_Type_Enum::from_wordpress_instance($this->bag);
61 61
 	}
62 62
 
63 63
 	public function get_permalink() {
64
-		if ( ! is_object( $this->bag ) ) {
64
+		if ( ! is_object($this->bag)) {
65 65
 			return null;
66 66
 		}
67 67
 
68
-		switch ( get_class( $this->bag ) ) {
68
+		switch (get_class($this->bag)) {
69 69
 			case 'WP_Post':
70
-				return get_permalink( $this->get_bag()->ID );
70
+				return get_permalink($this->get_bag()->ID);
71 71
 			case 'WP_User':
72
-				return get_author_posts_url( $this->get_bag()->ID );
72
+				return get_author_posts_url($this->get_bag()->ID);
73 73
 			case 'WP_Term':
74
-				return get_term_link( $this->bag->term_id );
74
+				return get_term_link($this->bag->term_id);
75 75
 		}
76 76
 
77 77
 		return null;
78 78
 	}
79 79
 
80 80
 	public function get_edit_link() {
81
-		if ( ! is_object( $this->bag ) ) {
81
+		if ( ! is_object($this->bag)) {
82 82
 			return null;
83 83
 		}
84 84
 
85
-		switch ( get_class( $this->bag ) ) {
85
+		switch (get_class($this->bag)) {
86 86
 			case 'WP_Post':
87 87
 				// We need to return & character as &, by default context is set to display.
88 88
 				// so &  will be returned as &amp; breaking header location redirects.
89 89
 				// By setting context to none we prevent this issue.
90
-				return get_edit_post_link( $this->get_bag()->ID, 'none' );
90
+				return get_edit_post_link($this->get_bag()->ID, 'none');
91 91
 			case 'WP_User':
92
-				return get_edit_user_link( $this->get_bag()->ID );
92
+				return get_edit_user_link($this->get_bag()->ID);
93 93
 			case 'WP_Term':
94
-				return get_edit_term_link( $this->bag->term_id );
94
+				return get_edit_term_link($this->bag->term_id);
95 95
 		}
96 96
 
97 97
 		return null;
Please login to merge, or discard this patch.
content/wordpress/class-abstract-wordpress-content-legacy-service.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,29 +8,29 @@
 block discarded – undo
8 8
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
9 9
 abstract class Abstract_Wordpress_Content_Legacy_Service extends Abstract_Wordpress_Content_Service {
10 10
 
11
-	private $expected_object_type;
12
-	private $get_meta_fn;
13
-
14
-	protected function __construct( $expected_object_type, $get_meta_fn ) {
15
-		parent::__construct();
16
-
17
-		$this->expected_object_type = $expected_object_type;
18
-		$this->get_meta_fn          = $get_meta_fn;
19
-	}
20
-
21
-	public function get_entity_id( $content_id ) {
22
-		Assertions::equals(
23
-			$content_id->get_type(),
24
-			$this->expected_object_type,
25
-			sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) )
26
-		);
27
-
28
-		$result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true );
29
-		return $result ? $result : null;
30
-	}
31
-
32
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
33
-	public function delete( $content_id ) {
34
-		// do nothing, WP deletes the post meta for us.
35
-	}
11
+    private $expected_object_type;
12
+    private $get_meta_fn;
13
+
14
+    protected function __construct( $expected_object_type, $get_meta_fn ) {
15
+        parent::__construct();
16
+
17
+        $this->expected_object_type = $expected_object_type;
18
+        $this->get_meta_fn          = $get_meta_fn;
19
+    }
20
+
21
+    public function get_entity_id( $content_id ) {
22
+        Assertions::equals(
23
+            $content_id->get_type(),
24
+            $this->expected_object_type,
25
+            sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) )
26
+        );
27
+
28
+        $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true );
29
+        return $result ? $result : null;
30
+    }
31
+
32
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
33
+    public function delete( $content_id ) {
34
+        // do nothing, WP deletes the post meta for us.
35
+    }
36 36
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,26 +11,26 @@
 block discarded – undo
11 11
 	private $expected_object_type;
12 12
 	private $get_meta_fn;
13 13
 
14
-	protected function __construct( $expected_object_type, $get_meta_fn ) {
14
+	protected function __construct($expected_object_type, $get_meta_fn) {
15 15
 		parent::__construct();
16 16
 
17 17
 		$this->expected_object_type = $expected_object_type;
18 18
 		$this->get_meta_fn          = $get_meta_fn;
19 19
 	}
20 20
 
21
-	public function get_entity_id( $content_id ) {
21
+	public function get_entity_id($content_id) {
22 22
 		Assertions::equals(
23 23
 			$content_id->get_type(),
24 24
 			$this->expected_object_type,
25
-			sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) )
25
+			sprintf('`content_id` must be of type `%s`.', Object_Type_Enum::to_string($this->expected_object_type))
26 26
 		);
27 27
 
28
-		$result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true );
28
+		$result = call_user_func($this->get_meta_fn, $content_id->get_id(), 'entity_url', true);
29 29
 		return $result ? $result : null;
30 30
 	}
31 31
 
32 32
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
33
-	public function delete( $content_id ) {
33
+	public function delete($content_id) {
34 34
 		// do nothing, WP deletes the post meta for us.
35 35
 	}
36 36
 }
Please login to merge, or discard this patch.
content/wordpress/class-wordpress-dataset-content-service-hooks.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -8,73 +8,73 @@
 block discarded – undo
8 8
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
9 9
 class Wordpress_Dataset_Content_Service_Hooks {
10 10
 
11
-	public static function register() {
12
-		add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) );
13
-		add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) );
14
-		add_action( 'created_term', array( get_called_class(), 'created_term' ) );
15
-		add_action( 'delete_term', array( get_called_class(), 'delete_term' ) );
16
-		add_action( 'user_register', array( get_called_class(), 'user_register' ) );
17
-		add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) );
18
-	}
11
+    public static function register() {
12
+        add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) );
13
+        add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) );
14
+        add_action( 'created_term', array( get_called_class(), 'created_term' ) );
15
+        add_action( 'delete_term', array( get_called_class(), 'delete_term' ) );
16
+        add_action( 'user_register', array( get_called_class(), 'user_register' ) );
17
+        add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) );
18
+    }
19 19
 
20
-	/**
21
-	 * @throws Exception in case of error.
22
-	 */
23
-	public static function insert_post( $post_id ) {
24
-		if ( ! wp_is_post_revision( $post_id ) ) {
25
-			self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) );
26
-		}
27
-	}
20
+    /**
21
+     * @throws Exception in case of error.
22
+     */
23
+    public static function insert_post( $post_id ) {
24
+        if ( ! wp_is_post_revision( $post_id ) ) {
25
+            self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) );
26
+        }
27
+    }
28 28
 
29
-	public static function after_delete_post( $post_id ) {
30
-		self::delete( Wordpress_Content_Id::create_post( $post_id ) );
31
-	}
29
+    public static function after_delete_post( $post_id ) {
30
+        self::delete( Wordpress_Content_Id::create_post( $post_id ) );
31
+    }
32 32
 
33
-	/**
34
-	 * @throws Exception in case of error.
35
-	 */
36
-	public static function created_term( $term_id ) {
37
-		self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) );
38
-	}
33
+    /**
34
+     * @throws Exception in case of error.
35
+     */
36
+    public static function created_term( $term_id ) {
37
+        self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) );
38
+    }
39 39
 
40
-	public static function delete_term( $term_id ) {
41
-		self::delete( Wordpress_Content_Id::create_term( $term_id ) );
42
-	}
40
+    public static function delete_term( $term_id ) {
41
+        self::delete( Wordpress_Content_Id::create_term( $term_id ) );
42
+    }
43 43
 
44
-	/**
45
-	 * @throws Exception in case of error.
46
-	 */
47
-	public static function user_register( $user_id ) {
48
-		self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) );
49
-	}
44
+    /**
45
+     * @throws Exception in case of error.
46
+     */
47
+    public static function user_register( $user_id ) {
48
+        self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) );
49
+    }
50 50
 
51
-	public static function deleted_user( $user_id ) {
52
-		self::delete( Wordpress_Content_Id::create_user( $user_id ) );
53
-	}
51
+    public static function deleted_user( $user_id ) {
52
+        self::delete( Wordpress_Content_Id::create_user( $user_id ) );
53
+    }
54 54
 
55
-	/**
56
-	 * @param Wordpress_Content_Id $content_id
57
-	 *
58
-	 * @return void
59
-	 * @throws Exception in case of error.
60
-	 */
61
-	private static function set_entity_id( $content_id ) {
62
-		$content_service = Wordpress_Content_Service::get_instance();
63
-		try {
64
-			$existing_id = $content_service->get_entity_id( $content_id );
65
-			if ( empty( $existing_id ) ) {
66
-				$rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() );
67
-				$content_service->set_entity_id( $content_id, $rel_uri );
68
-			}
69
-		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
70
-		} catch ( Exception $e ) {
71
-			// Don't report.
72
-		}
73
-	}
55
+    /**
56
+     * @param Wordpress_Content_Id $content_id
57
+     *
58
+     * @return void
59
+     * @throws Exception in case of error.
60
+     */
61
+    private static function set_entity_id( $content_id ) {
62
+        $content_service = Wordpress_Content_Service::get_instance();
63
+        try {
64
+            $existing_id = $content_service->get_entity_id( $content_id );
65
+            if ( empty( $existing_id ) ) {
66
+                $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() );
67
+                $content_service->set_entity_id( $content_id, $rel_uri );
68
+            }
69
+        // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
70
+        } catch ( Exception $e ) {
71
+            // Don't report.
72
+        }
73
+    }
74 74
 
75
-	private static function delete( $content_id ) {
76
-		$content_service = Wordpress_Content_Service::get_instance();
77
-		$content_service->delete( $content_id );
78
-	}
75
+    private static function delete( $content_id ) {
76
+        $content_service = Wordpress_Content_Service::get_instance();
77
+        $content_service->delete( $content_id );
78
+    }
79 79
 
80 80
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,47 +9,47 @@  discard block
 block discarded – undo
9 9
 class Wordpress_Dataset_Content_Service_Hooks {
10 10
 
11 11
 	public static function register() {
12
-		add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) );
13
-		add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) );
14
-		add_action( 'created_term', array( get_called_class(), 'created_term' ) );
15
-		add_action( 'delete_term', array( get_called_class(), 'delete_term' ) );
16
-		add_action( 'user_register', array( get_called_class(), 'user_register' ) );
17
-		add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) );
12
+		add_action('wp_insert_post', array(get_called_class(), 'insert_post'));
13
+		add_action('after_delete_post', array(get_called_class(), 'after_delete_post'));
14
+		add_action('created_term', array(get_called_class(), 'created_term'));
15
+		add_action('delete_term', array(get_called_class(), 'delete_term'));
16
+		add_action('user_register', array(get_called_class(), 'user_register'));
17
+		add_action('deleted_user', array(get_called_class(), 'deleted_user'));
18 18
 	}
19 19
 
20 20
 	/**
21 21
 	 * @throws Exception in case of error.
22 22
 	 */
23
-	public static function insert_post( $post_id ) {
24
-		if ( ! wp_is_post_revision( $post_id ) ) {
25
-			self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) );
23
+	public static function insert_post($post_id) {
24
+		if ( ! wp_is_post_revision($post_id)) {
25
+			self::set_entity_id(Wordpress_Content_Id::create_post($post_id));
26 26
 		}
27 27
 	}
28 28
 
29
-	public static function after_delete_post( $post_id ) {
30
-		self::delete( Wordpress_Content_Id::create_post( $post_id ) );
29
+	public static function after_delete_post($post_id) {
30
+		self::delete(Wordpress_Content_Id::create_post($post_id));
31 31
 	}
32 32
 
33 33
 	/**
34 34
 	 * @throws Exception in case of error.
35 35
 	 */
36
-	public static function created_term( $term_id ) {
37
-		self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) );
36
+	public static function created_term($term_id) {
37
+		self::set_entity_id(Wordpress_Content_Id::create_term($term_id));
38 38
 	}
39 39
 
40
-	public static function delete_term( $term_id ) {
41
-		self::delete( Wordpress_Content_Id::create_term( $term_id ) );
40
+	public static function delete_term($term_id) {
41
+		self::delete(Wordpress_Content_Id::create_term($term_id));
42 42
 	}
43 43
 
44 44
 	/**
45 45
 	 * @throws Exception in case of error.
46 46
 	 */
47
-	public static function user_register( $user_id ) {
48
-		self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) );
47
+	public static function user_register($user_id) {
48
+		self::set_entity_id(Wordpress_Content_Id::create_user($user_id));
49 49
 	}
50 50
 
51
-	public static function deleted_user( $user_id ) {
52
-		self::delete( Wordpress_Content_Id::create_user( $user_id ) );
51
+	public static function deleted_user($user_id) {
52
+		self::delete(Wordpress_Content_Id::create_user($user_id));
53 53
 	}
54 54
 
55 55
 	/**
@@ -58,23 +58,23 @@  discard block
 block discarded – undo
58 58
 	 * @return void
59 59
 	 * @throws Exception in case of error.
60 60
 	 */
61
-	private static function set_entity_id( $content_id ) {
61
+	private static function set_entity_id($content_id) {
62 62
 		$content_service = Wordpress_Content_Service::get_instance();
63 63
 		try {
64
-			$existing_id = $content_service->get_entity_id( $content_id );
65
-			if ( empty( $existing_id ) ) {
66
-				$rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() );
67
-				$content_service->set_entity_id( $content_id, $rel_uri );
64
+			$existing_id = $content_service->get_entity_id($content_id);
65
+			if (empty($existing_id)) {
66
+				$rel_uri = Entity_Uri_Generator::create_uri($content_id->get_type(), $content_id->get_id());
67
+				$content_service->set_entity_id($content_id, $rel_uri);
68 68
 			}
69 69
 		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
70
-		} catch ( Exception $e ) {
70
+		} catch (Exception $e) {
71 71
 			// Don't report.
72 72
 		}
73 73
 	}
74 74
 
75
-	private static function delete( $content_id ) {
75
+	private static function delete($content_id) {
76 76
 		$content_service = Wordpress_Content_Service::get_instance();
77
-		$content_service->delete( $content_id );
77
+		$content_service->delete($content_id);
78 78
 	}
79 79
 
80 80
 }
Please login to merge, or discard this patch.
src/wordlift/content/wordpress/class-wordpress-post-content-service.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@
 block discarded – undo
23 23
 	 */
24 24
 	public static function get_instance() {
25 25
 
26
-		if ( ! isset( self::$instance ) ) {
26
+		if ( ! isset(self::$instance)) {
27 27
 
28 28
 			// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
29
-			if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) {
29
+			if ( ! apply_filters('wl_feature__enable__rel-item-id', false)) {
30 30
 				self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance();
31 31
 			} else {
32 32
 				// Migrate `entity_url` from post-meta to wl_entities.
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -14,36 +14,36 @@
 block discarded – undo
14 14
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
15 15
 class Wordpress_Post_Content_Service {
16 16
 
17
-	private static $instance = null;
18
-
19
-	/**
20
-	 * The singleton instance. We use this only to provide this instance to those classes where we have no access to
21
-	 * the constructor.
22
-	 *
23
-	 * @return Content_Service
24
-	 */
25
-	public static function get_instance() {
26
-
27
-		if ( ! isset( self::$instance ) ) {
28
-
29
-			// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
-			if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) {
31
-				self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance();
32
-			} else {
33
-				// Migrate `entity_url` from post-meta to wl_entities.
34
-				$content_migration = new Content_Migration();
35
-				$content_migration->migrate();
36
-
37
-				// Migrate `main_ingredient`.
38
-				$main_ingredient_content_migration = new Main_Ingredient_Content_Migration();
39
-				$main_ingredient_content_migration->migrate();
40
-
41
-				// Create the post content service that uses wl_entities.
42
-				self::$instance = Wordpress_Post_Content_Table_Service::get_instance();
43
-			}
44
-		}
45
-
46
-		return self::$instance;
47
-	}
17
+    private static $instance = null;
18
+
19
+    /**
20
+     * The singleton instance. We use this only to provide this instance to those classes where we have no access to
21
+     * the constructor.
22
+     *
23
+     * @return Content_Service
24
+     */
25
+    public static function get_instance() {
26
+
27
+        if ( ! isset( self::$instance ) ) {
28
+
29
+            // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
30
+            if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) {
31
+                self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance();
32
+            } else {
33
+                // Migrate `entity_url` from post-meta to wl_entities.
34
+                $content_migration = new Content_Migration();
35
+                $content_migration->migrate();
36
+
37
+                // Migrate `main_ingredient`.
38
+                $main_ingredient_content_migration = new Main_Ingredient_Content_Migration();
39
+                $main_ingredient_content_migration->migrate();
40
+
41
+                // Create the post content service that uses wl_entities.
42
+                self::$instance = Wordpress_Post_Content_Table_Service::get_instance();
43
+            }
44
+        }
45
+
46
+        return self::$instance;
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.
wordlift/content/wordpress/class-wordpress-term-content-legacy-service.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -9,47 +9,47 @@  discard block
 block discarded – undo
9 9
 // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName
10 10
 class Wordpress_Term_Content_Legacy_Service extends Abstract_Wordpress_Content_Legacy_Service {
11 11
 
12
-	private static $instance = null;
13
-
14
-	/**
15
-	 * The singleton instance. We use this only to provide this instance to those classes where we have no access to
16
-	 * the constructor.
17
-	 *
18
-	 * @return Wordpress_Term_Content_Legacy_Service
19
-	 */
20
-	public static function get_instance() {
21
-
22
-		if ( ! isset( self::$instance ) ) {
23
-			self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' );
24
-		}
25
-
26
-		return self::$instance;
27
-	}
28
-
29
-	/**
30
-	 * @param string $uri The entity id, relative or absolute.
31
-	 *
32
-	 * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null.
33
-	 * @throws Exception in case of error. when the uri is not within the dataset URI scope.
34
-	 */
35
-	public function get_by_entity_id( $uri ) {
36
-		Assertions::is_string( $uri, '`uri` must be a string.' );
37
-		Assertions::not_empty( $uri, '`uri` cannot be empty.' );
38
-		Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
39
-
40
-		$abs_uri = $this->make_absolute( $uri );
41
-
42
-		Assertions::starts_with(
43
-			$abs_uri,
44
-			$this->get_dataset_uri(),
45
-			sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() )
46
-		);
47
-
48
-		global $wpdb;
49
-
50
-		$term_id = $wpdb->get_var(
51
-			$wpdb->prepare(
52
-				"
12
+    private static $instance = null;
13
+
14
+    /**
15
+     * The singleton instance. We use this only to provide this instance to those classes where we have no access to
16
+     * the constructor.
17
+     *
18
+     * @return Wordpress_Term_Content_Legacy_Service
19
+     */
20
+    public static function get_instance() {
21
+
22
+        if ( ! isset( self::$instance ) ) {
23
+            self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' );
24
+        }
25
+
26
+        return self::$instance;
27
+    }
28
+
29
+    /**
30
+     * @param string $uri The entity id, relative or absolute.
31
+     *
32
+     * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null.
33
+     * @throws Exception in case of error. when the uri is not within the dataset URI scope.
34
+     */
35
+    public function get_by_entity_id( $uri ) {
36
+        Assertions::is_string( $uri, '`uri` must be a string.' );
37
+        Assertions::not_empty( $uri, '`uri` cannot be empty.' );
38
+        Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
39
+
40
+        $abs_uri = $this->make_absolute( $uri );
41
+
42
+        Assertions::starts_with(
43
+            $abs_uri,
44
+            $this->get_dataset_uri(),
45
+            sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() )
46
+        );
47
+
48
+        global $wpdb;
49
+
50
+        $term_id = $wpdb->get_var(
51
+            $wpdb->prepare(
52
+                "
53 53
 			SELECT t.term_id 
54 54
 			FROM $wpdb->terms AS t 
55 55
 			INNER JOIN $wpdb->termmeta AS tm
@@ -57,70 +57,70 @@  discard block
 block discarded – undo
57 57
 			WHERE tm.meta_key = 'entity_url' AND tm.meta_value = %s
58 58
 			LIMIT 1
59 59
 		",
60
-				$abs_uri
61
-			)
62
-		);
63
-
64
-		if ( isset( $term_id ) ) {
65
-			return new Wordpress_Content( get_term( $term_id ) );
66
-		}
67
-
68
-		return null;
69
-	}
70
-
71
-	/**
72
-	 * @throws Exception in case of error. when `$uri` is not a string.
73
-	 */
74
-	public function get_by_entity_id_or_same_as( $uri ) {
75
-		Assertions::is_string( $uri, '`uri` must be a string.' );
76
-		Assertions::not_empty( '`uri` cannot be empty.' );
77
-
78
-		// If it's a relative URI, or it's an internal URI, look in entity ID.
79
-		if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) {
80
-			return $this->get_by_entity_id( $uri );
81
-		}
82
-
83
-		global $wpdb;
84
-
85
-		$term_id = $wpdb->get_var(
86
-			$wpdb->prepare(
87
-				"
60
+                $abs_uri
61
+            )
62
+        );
63
+
64
+        if ( isset( $term_id ) ) {
65
+            return new Wordpress_Content( get_term( $term_id ) );
66
+        }
67
+
68
+        return null;
69
+    }
70
+
71
+    /**
72
+     * @throws Exception in case of error. when `$uri` is not a string.
73
+     */
74
+    public function get_by_entity_id_or_same_as( $uri ) {
75
+        Assertions::is_string( $uri, '`uri` must be a string.' );
76
+        Assertions::not_empty( '`uri` cannot be empty.' );
77
+
78
+        // If it's a relative URI, or it's an internal URI, look in entity ID.
79
+        if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) {
80
+            return $this->get_by_entity_id( $uri );
81
+        }
82
+
83
+        global $wpdb;
84
+
85
+        $term_id = $wpdb->get_var(
86
+            $wpdb->prepare(
87
+                "
88 88
 			SELECT tm.term_id
89 89
 			FROM $wpdb->termmeta tm
90 90
 			WHERE tm.meta_key IN ( 'entity_url', 'entity_same_as' ) AND tm.meta_value = %s
91 91
 			LIMIT 1
92 92
 		",
93
-				$uri
94
-			)
95
-		);
96
-
97
-		if ( isset( $term_id ) ) {
98
-			return new Wordpress_Content( get_term( $term_id ) );
99
-		}
100
-
101
-		return null;
102
-	}
103
-
104
-	public function set_entity_id( $content_id, $uri ) {
105
-		Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' );
106
-		Assertions::not_empty( $uri, "`uri` can't be empty" );
107
-
108
-		if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) {
109
-			throw new Exception( '`uri` must be within the dataset URI scope.' );
110
-		}
111
-
112
-		$abs_url = $this->make_absolute( $uri );
113
-
114
-		update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url );
115
-	}
116
-
117
-	/**
118
-	 * @param Wordpress_Content_Id $content_id
119
-	 *
120
-	 * @return bool
121
-	 */
122
-	public function supports( $content_id ) {
123
-		return $content_id->get_type() === Object_Type_Enum::TERM;
124
-	}
93
+                $uri
94
+            )
95
+        );
96
+
97
+        if ( isset( $term_id ) ) {
98
+            return new Wordpress_Content( get_term( $term_id ) );
99
+        }
100
+
101
+        return null;
102
+    }
103
+
104
+    public function set_entity_id( $content_id, $uri ) {
105
+        Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' );
106
+        Assertions::not_empty( $uri, "`uri` can't be empty" );
107
+
108
+        if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) {
109
+            throw new Exception( '`uri` must be within the dataset URI scope.' );
110
+        }
111
+
112
+        $abs_url = $this->make_absolute( $uri );
113
+
114
+        update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url );
115
+    }
116
+
117
+    /**
118
+     * @param Wordpress_Content_Id $content_id
119
+     *
120
+     * @return bool
121
+     */
122
+    public function supports( $content_id ) {
123
+        return $content_id->get_type() === Object_Type_Enum::TERM;
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	public static function get_instance() {
21 21
 
22
-		if ( ! isset( self::$instance ) ) {
23
-			self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' );
22
+		if ( ! isset(self::$instance)) {
23
+			self::$instance = new self(Object_Type_Enum::TERM, 'get_term_meta');
24 24
 		}
25 25
 
26 26
 		return self::$instance;
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
 	 * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null.
33 33
 	 * @throws Exception in case of error. when the uri is not within the dataset URI scope.
34 34
 	 */
35
-	public function get_by_entity_id( $uri ) {
36
-		Assertions::is_string( $uri, '`uri` must be a string.' );
37
-		Assertions::not_empty( $uri, '`uri` cannot be empty.' );
38
-		Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' );
35
+	public function get_by_entity_id($uri) {
36
+		Assertions::is_string($uri, '`uri` must be a string.');
37
+		Assertions::not_empty($uri, '`uri` cannot be empty.');
38
+		Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.');
39 39
 
40
-		$abs_uri = $this->make_absolute( $uri );
40
+		$abs_uri = $this->make_absolute($uri);
41 41
 
42 42
 		Assertions::starts_with(
43 43
 			$abs_uri,
44 44
 			$this->get_dataset_uri(),
45
-			sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() )
45
+			sprintf('URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri())
46 46
 		);
47 47
 
48 48
 		global $wpdb;
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 			)
62 62
 		);
63 63
 
64
-		if ( isset( $term_id ) ) {
65
-			return new Wordpress_Content( get_term( $term_id ) );
64
+		if (isset($term_id)) {
65
+			return new Wordpress_Content(get_term($term_id));
66 66
 		}
67 67
 
68 68
 		return null;
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
71 71
 	/**
72 72
 	 * @throws Exception in case of error. when `$uri` is not a string.
73 73
 	 */
74
-	public function get_by_entity_id_or_same_as( $uri ) {
75
-		Assertions::is_string( $uri, '`uri` must be a string.' );
76
-		Assertions::not_empty( '`uri` cannot be empty.' );
74
+	public function get_by_entity_id_or_same_as($uri) {
75
+		Assertions::is_string($uri, '`uri` must be a string.');
76
+		Assertions::not_empty('`uri` cannot be empty.');
77 77
 
78 78
 		// If it's a relative URI, or it's an internal URI, look in entity ID.
79
-		if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) {
80
-			return $this->get_by_entity_id( $uri );
79
+		if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) {
80
+			return $this->get_by_entity_id($uri);
81 81
 		}
82 82
 
83 83
 		global $wpdb;
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
 			)
95 95
 		);
96 96
 
97
-		if ( isset( $term_id ) ) {
98
-			return new Wordpress_Content( get_term( $term_id ) );
97
+		if (isset($term_id)) {
98
+			return new Wordpress_Content(get_term($term_id));
99 99
 		}
100 100
 
101 101
 		return null;
102 102
 	}
103 103
 
104
-	public function set_entity_id( $content_id, $uri ) {
105
-		Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' );
106
-		Assertions::not_empty( $uri, "`uri` can't be empty" );
104
+	public function set_entity_id($content_id, $uri) {
105
+		Assertions::equals($content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.');
106
+		Assertions::not_empty($uri, "`uri` can't be empty");
107 107
 
108
-		if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) {
109
-			throw new Exception( '`uri` must be within the dataset URI scope.' );
108
+		if ($this->is_absolute($uri) && ! $this->is_internal($uri)) {
109
+			throw new Exception('`uri` must be within the dataset URI scope.');
110 110
 		}
111 111
 
112
-		$abs_url = $this->make_absolute( $uri );
112
+		$abs_url = $this->make_absolute($uri);
113 113
 
114
-		update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url );
114
+		update_term_meta($content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url);
115 115
 	}
116 116
 
117 117
 	/**
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @return bool
121 121
 	 */
122
-	public function supports( $content_id ) {
122
+	public function supports($content_id) {
123 123
 		return $content_id->get_type() === Object_Type_Enum::TERM;
124 124
 	}
125 125
 
Please login to merge, or discard this patch.