Completed
Push — master ( b5fb08...e29557 )
by Naveen
01:07
created
src/wordlift/jsonld/class-mentions.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -16,74 +16,74 @@
 block discarded – undo
16 16
 
17 17
 class Mentions {
18 18
 
19
-	public function __construct() {
20
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
21
-	}
19
+    public function __construct() {
20
+        add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
21
+    }
22 22
 
23
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
23
+    public function wl_after_get_jsonld( $jsonld, $post_id ) {
24 24
 
25
-		if ( count( $jsonld ) === 0 || ! array_key_exists( '@type', $jsonld[0] ) || array_key_exists( 'mentions', $jsonld[0] ) ) {
26
-			return $jsonld;
27
-		}
25
+        if ( count( $jsonld ) === 0 || ! array_key_exists( '@type', $jsonld[0] ) || array_key_exists( 'mentions', $jsonld[0] ) ) {
26
+            return $jsonld;
27
+        }
28 28
 
29 29
 
30
-		$type = $jsonld[0]['@type'];
30
+        $type = $jsonld[0]['@type'];
31 31
 
32 32
 
33 33
 
34
-		if ( ! $this->entity_is_descendant_of_creative_work( $type ) && ! $this->entity_is_creative_work( $type ) ) {
35
-			return $jsonld;
36
-		}
34
+        if ( ! $this->entity_is_descendant_of_creative_work( $type ) && ! $this->entity_is_creative_work( $type ) ) {
35
+            return $jsonld;
36
+        }
37 37
 
38
-		$entity_references = Object_Relation_Service::get_instance()
39
-		                                            ->get_references( $post_id, Object_Type_Enum::POST );
38
+        $entity_references = Object_Relation_Service::get_instance()
39
+                                                    ->get_references( $post_id, Object_Type_Enum::POST );
40 40
 
41 41
 
42 42
 
43
-		$jsonld[0]['mentions'] = array_values( array_filter( array_map( function ( $item ) {
44
-			$id = \Wordlift_Entity_Service::get_instance()->get_uri( $item->get_id() );
45
-			if ( ! $id ) {
46
-				return false;
47
-			}
43
+        $jsonld[0]['mentions'] = array_values( array_filter( array_map( function ( $item ) {
44
+            $id = \Wordlift_Entity_Service::get_instance()->get_uri( $item->get_id() );
45
+            if ( ! $id ) {
46
+                return false;
47
+            }
48 48
 
49
-			return array( '@id' => $id );
49
+            return array( '@id' => $id );
50 50
 
51
-		}, $entity_references ) ) );
51
+        }, $entity_references ) ) );
52 52
 
53
-		// Remove mentions if the count is zero.
54
-		if ( count( $jsonld[0]['mentions'] ) === 0 ) {
55
-			unset( $jsonld[0]['mentions'] );
56
-		}
53
+        // Remove mentions if the count is zero.
54
+        if ( count( $jsonld[0]['mentions'] ) === 0 ) {
55
+            unset( $jsonld[0]['mentions'] );
56
+        }
57 57
 
58 58
 
59
-		return $jsonld;
60
-	}
59
+        return $jsonld;
60
+    }
61 61
 
62 62
 
63
-	private function entity_is_descendant_of_creative_work( $type ) {
63
+    private function entity_is_descendant_of_creative_work( $type ) {
64 64
 
65
-		if ( ! is_array( $type ) ) {
66
-			$type = array( $type );
67
-		}
65
+        if ( ! is_array( $type ) ) {
66
+            $type = array( $type );
67
+        }
68 68
 
69
-		$creative_work_term = get_term_by( 'name', 'CreativeWork', \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
69
+        $creative_work_term = get_term_by( 'name', 'CreativeWork', \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
70 70
 
71
-		if ( ! $creative_work_term ) {
72
-			return false;
73
-		}
71
+        if ( ! $creative_work_term ) {
72
+            return false;
73
+        }
74 74
 
75
-		$descendants = get_term_meta( $creative_work_term->term_id, '_wl_parent_of' );
75
+        $descendants = get_term_meta( $creative_work_term->term_id, '_wl_parent_of' );
76 76
 
77
-		$slugs_to_schema_name = array_map( function ( $item ) {
78
-			return implode( '', array_map( 'ucfirst', explode( '-', $item ) ) );
79
-		}, $descendants );
77
+        $slugs_to_schema_name = array_map( function ( $item ) {
78
+            return implode( '', array_map( 'ucfirst', explode( '-', $item ) ) );
79
+        }, $descendants );
80 80
 
81
-		return count( array_intersect( $type, $slugs_to_schema_name ) ) > 0;
81
+        return count( array_intersect( $type, $slugs_to_schema_name ) ) > 0;
82 82
 
83
-	}
83
+    }
84 84
 
85
-	private function entity_is_creative_work( $type ) {
86
-		return ( $type === 'CreativeWork' ) || ( is_array( $type ) && in_array( 'CreativeWork', $type ) );
87
-	}
85
+    private function entity_is_creative_work( $type ) {
86
+        return ( $type === 'CreativeWork' ) || ( is_array( $type ) && in_array( 'CreativeWork', $type ) );
87
+    }
88 88
 
89 89
 }
90 90
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 class Mentions {
18 18
 
19 19
 	public function __construct() {
20
-		add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
20
+		add_filter('wl_after_get_jsonld', array($this, 'wl_after_get_jsonld'), 10, 2);
21 21
 	}
22 22
 
23
-	public function wl_after_get_jsonld( $jsonld, $post_id ) {
23
+	public function wl_after_get_jsonld($jsonld, $post_id) {
24 24
 
25
-		if ( count( $jsonld ) === 0 || ! array_key_exists( '@type', $jsonld[0] ) || array_key_exists( 'mentions', $jsonld[0] ) ) {
25
+		if (count($jsonld) === 0 || ! array_key_exists('@type', $jsonld[0]) || array_key_exists('mentions', $jsonld[0])) {
26 26
 			return $jsonld;
27 27
 		}
28 28
 
@@ -31,28 +31,28 @@  discard block
 block discarded – undo
31 31
 
32 32
 
33 33
 
34
-		if ( ! $this->entity_is_descendant_of_creative_work( $type ) && ! $this->entity_is_creative_work( $type ) ) {
34
+		if ( ! $this->entity_is_descendant_of_creative_work($type) && ! $this->entity_is_creative_work($type)) {
35 35
 			return $jsonld;
36 36
 		}
37 37
 
38 38
 		$entity_references = Object_Relation_Service::get_instance()
39
-		                                            ->get_references( $post_id, Object_Type_Enum::POST );
39
+		                                            ->get_references($post_id, Object_Type_Enum::POST);
40 40
 
41 41
 
42 42
 
43
-		$jsonld[0]['mentions'] = array_values( array_filter( array_map( function ( $item ) {
44
-			$id = \Wordlift_Entity_Service::get_instance()->get_uri( $item->get_id() );
45
-			if ( ! $id ) {
43
+		$jsonld[0]['mentions'] = array_values(array_filter(array_map(function($item) {
44
+			$id = \Wordlift_Entity_Service::get_instance()->get_uri($item->get_id());
45
+			if ( ! $id) {
46 46
 				return false;
47 47
 			}
48 48
 
49
-			return array( '@id' => $id );
49
+			return array('@id' => $id);
50 50
 
51
-		}, $entity_references ) ) );
51
+		}, $entity_references)));
52 52
 
53 53
 		// Remove mentions if the count is zero.
54
-		if ( count( $jsonld[0]['mentions'] ) === 0 ) {
55
-			unset( $jsonld[0]['mentions'] );
54
+		if (count($jsonld[0]['mentions']) === 0) {
55
+			unset($jsonld[0]['mentions']);
56 56
 		}
57 57
 
58 58
 
@@ -60,30 +60,30 @@  discard block
 block discarded – undo
60 60
 	}
61 61
 
62 62
 
63
-	private function entity_is_descendant_of_creative_work( $type ) {
63
+	private function entity_is_descendant_of_creative_work($type) {
64 64
 
65
-		if ( ! is_array( $type ) ) {
66
-			$type = array( $type );
65
+		if ( ! is_array($type)) {
66
+			$type = array($type);
67 67
 		}
68 68
 
69
-		$creative_work_term = get_term_by( 'name', 'CreativeWork', \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
69
+		$creative_work_term = get_term_by('name', 'CreativeWork', \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
70 70
 
71
-		if ( ! $creative_work_term ) {
71
+		if ( ! $creative_work_term) {
72 72
 			return false;
73 73
 		}
74 74
 
75
-		$descendants = get_term_meta( $creative_work_term->term_id, '_wl_parent_of' );
75
+		$descendants = get_term_meta($creative_work_term->term_id, '_wl_parent_of');
76 76
 
77
-		$slugs_to_schema_name = array_map( function ( $item ) {
78
-			return implode( '', array_map( 'ucfirst', explode( '-', $item ) ) );
79
-		}, $descendants );
77
+		$slugs_to_schema_name = array_map(function($item) {
78
+			return implode('', array_map('ucfirst', explode('-', $item)));
79
+		}, $descendants);
80 80
 
81
-		return count( array_intersect( $type, $slugs_to_schema_name ) ) > 0;
81
+		return count(array_intersect($type, $slugs_to_schema_name)) > 0;
82 82
 
83 83
 	}
84 84
 
85
-	private function entity_is_creative_work( $type ) {
86
-		return ( $type === 'CreativeWork' ) || ( is_array( $type ) && in_array( 'CreativeWork', $type ) );
85
+	private function entity_is_creative_work($type) {
86
+		return ($type === 'CreativeWork') || (is_array($type) && in_array('CreativeWork', $type));
87 87
 	}
88 88
 
89 89
 }
90 90
\ No newline at end of file
Please login to merge, or discard this patch.