Completed
Pull Request — develop (#1698)
by
unknown
01:26
created
src/wordlift/vocabulary/cache/class-cache-service-factory.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 class Cache_Service_Factory {
6 6
 
7
-	public static function get_cache_service() {
8
-		return new Options_Cache( 'wordlift-cmkg' );
9
-	}
7
+    public static function get_cache_service() {
8
+        return new Options_Cache( 'wordlift-cmkg' );
9
+    }
10 10
 
11 11
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 class Cache_Service_Factory {
6 6
 
7 7
 	public static function get_cache_service() {
8
-		return new Options_Cache( 'wordlift-cmkg' );
8
+		return new Options_Cache('wordlift-cmkg');
9 9
 	}
10 10
 
11 11
 }
Please login to merge, or discard this patch.
src/wordlift/link/class-link-builder.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -9,93 +9,93 @@
 block discarded – undo
9 9
 
10 10
 class Link_Builder {
11 11
 
12
-	private $id;
13
-	private $type;
14
-	private $label;
15
-	private $href;
16
-	private $entity_url;
17
-	/**
18
-	 * @var Object_Link_Provider
19
-	 */
20
-	private $object_link_provider;
21
-
22
-	public function __construct( $entity_url, $id ) {
23
-		$this->entity_url           = $entity_url;
24
-		$this->id                   = $id;
25
-		$this->object_link_provider = Object_Link_Provider::get_instance();
26
-		$this->type                 = $this->object_link_provider->get_object_type( $entity_url );
27
-	}
28
-
29
-	public static function create( $entity_url, $id ) {
30
-		return new Link_Builder( $entity_url, $id );
31
-	}
32
-
33
-	public function label( $label ) {
34
-		$this->label = $label;
35
-
36
-		return $this;
37
-	}
38
-
39
-	public function href( $href ) {
40
-		$this->href = $href;
41
-
42
-		return $this;
43
-	}
44
-
45
-	private function get_attributes_for_link() {
46
-		/**
47
-		 * Allow 3rd parties to add additional attributes to the anchor link.
48
-		 *
49
-		 * @since 3.26.0
50
-		 */
51
-		$default_attributes = array(
52
-			'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ),
53
-		);
54
-
55
-		/**
56
-		 * @since 3.32.0
57
-		 * Additional parameter {@link $this->type} is added to the filter denoting the type of
58
-		 * the entity url by the enum values {@link Object_Type_Enum}
59
-		 */
60
-		$attributes      = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type );
61
-		$attributes_html = '';
62
-		foreach ( $attributes as $key => $value ) {
63
-			$attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" ';
64
-		}
65
-
66
-		return $attributes_html;
67
-	}
68
-
69
-	/**
70
-	 * Get a `title` attribute with an alternative label for the link.
71
-	 *
72
-	 * If an alternative title isn't available an empty string is returned.
73
-	 *
74
-	 * @return string A `title` attribute with an alternative label or an empty
75
-	 *                string if none available.
76
-	 * @since 3.32.0
77
-	 */
78
-	private function get_title_attribute() {
79
-
80
-		// Get an alternative title.
81
-		$title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type );
82
-		if ( ! empty( $title ) ) {
83
-			return 'title="' . esc_attr( $title ) . '"';
84
-		}
85
-
86
-		return '';
87
-	}
88
-
89
-	/**
90
-	 * @return string
91
-	 */
92
-	public function generate_link() {
93
-		// Get an alternative title attribute.
94
-		$title_attribute = $this->get_title_attribute();
95
-		$attributes_html = $this->get_attributes_for_link();
96
-
97
-		// Return the link.
98
-		return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>";
99
-	}
12
+    private $id;
13
+    private $type;
14
+    private $label;
15
+    private $href;
16
+    private $entity_url;
17
+    /**
18
+     * @var Object_Link_Provider
19
+     */
20
+    private $object_link_provider;
21
+
22
+    public function __construct( $entity_url, $id ) {
23
+        $this->entity_url           = $entity_url;
24
+        $this->id                   = $id;
25
+        $this->object_link_provider = Object_Link_Provider::get_instance();
26
+        $this->type                 = $this->object_link_provider->get_object_type( $entity_url );
27
+    }
28
+
29
+    public static function create( $entity_url, $id ) {
30
+        return new Link_Builder( $entity_url, $id );
31
+    }
32
+
33
+    public function label( $label ) {
34
+        $this->label = $label;
35
+
36
+        return $this;
37
+    }
38
+
39
+    public function href( $href ) {
40
+        $this->href = $href;
41
+
42
+        return $this;
43
+    }
44
+
45
+    private function get_attributes_for_link() {
46
+        /**
47
+         * Allow 3rd parties to add additional attributes to the anchor link.
48
+         *
49
+         * @since 3.26.0
50
+         */
51
+        $default_attributes = array(
52
+            'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ),
53
+        );
54
+
55
+        /**
56
+         * @since 3.32.0
57
+         * Additional parameter {@link $this->type} is added to the filter denoting the type of
58
+         * the entity url by the enum values {@link Object_Type_Enum}
59
+         */
60
+        $attributes      = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type );
61
+        $attributes_html = '';
62
+        foreach ( $attributes as $key => $value ) {
63
+            $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" ';
64
+        }
65
+
66
+        return $attributes_html;
67
+    }
68
+
69
+    /**
70
+     * Get a `title` attribute with an alternative label for the link.
71
+     *
72
+     * If an alternative title isn't available an empty string is returned.
73
+     *
74
+     * @return string A `title` attribute with an alternative label or an empty
75
+     *                string if none available.
76
+     * @since 3.32.0
77
+     */
78
+    private function get_title_attribute() {
79
+
80
+        // Get an alternative title.
81
+        $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type );
82
+        if ( ! empty( $title ) ) {
83
+            return 'title="' . esc_attr( $title ) . '"';
84
+        }
85
+
86
+        return '';
87
+    }
88
+
89
+    /**
90
+     * @return string
91
+     */
92
+    public function generate_link() {
93
+        // Get an alternative title attribute.
94
+        $title_attribute = $this->get_title_attribute();
95
+        $attributes_html = $this->get_attributes_for_link();
96
+
97
+        // Return the link.
98
+        return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>";
99
+    }
100 100
 
101 101
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -19,24 +19,24 @@  discard block
 block discarded – undo
19 19
 	 */
20 20
 	private $object_link_provider;
21 21
 
22
-	public function __construct( $entity_url, $id ) {
22
+	public function __construct($entity_url, $id) {
23 23
 		$this->entity_url           = $entity_url;
24 24
 		$this->id                   = $id;
25 25
 		$this->object_link_provider = Object_Link_Provider::get_instance();
26
-		$this->type                 = $this->object_link_provider->get_object_type( $entity_url );
26
+		$this->type                 = $this->object_link_provider->get_object_type($entity_url);
27 27
 	}
28 28
 
29
-	public static function create( $entity_url, $id ) {
30
-		return new Link_Builder( $entity_url, $id );
29
+	public static function create($entity_url, $id) {
30
+		return new Link_Builder($entity_url, $id);
31 31
 	}
32 32
 
33
-	public function label( $label ) {
33
+	public function label($label) {
34 34
 		$this->label = $label;
35 35
 
36 36
 		return $this;
37 37
 	}
38 38
 
39
-	public function href( $href ) {
39
+	public function href($href) {
40 40
 		$this->href = $href;
41 41
 
42 42
 		return $this;
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		 * @since 3.26.0
50 50
 		 */
51 51
 		$default_attributes = array(
52
-			'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ),
52
+			'id' => implode(';', $this->object_link_provider->get_same_as_uris($this->id, $this->type)),
53 53
 		);
54 54
 
55 55
 		/**
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
 		 * Additional parameter {@link $this->type} is added to the filter denoting the type of
58 58
 		 * the entity url by the enum values {@link Object_Type_Enum}
59 59
 		 */
60
-		$attributes      = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type );
60
+		$attributes      = apply_filters('wl_anchor_data_attributes', $default_attributes, $this->id, $this->type);
61 61
 		$attributes_html = '';
62
-		foreach ( $attributes as $key => $value ) {
63
-			$attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" ';
62
+		foreach ($attributes as $key => $value) {
63
+			$attributes_html .= ' data-'.esc_html($key).'="'.esc_attr($value).'" ';
64 64
 		}
65 65
 
66 66
 		return $attributes_html;
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 	private function get_title_attribute() {
79 79
 
80 80
 		// Get an alternative title.
81
-		$title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type );
82
-		if ( ! empty( $title ) ) {
83
-			return 'title="' . esc_attr( $title ) . '"';
81
+		$title = $this->object_link_provider->get_link_title($this->id, $this->label, $this->type);
82
+		if ( ! empty($title)) {
83
+			return 'title="'.esc_attr($title).'"';
84 84
 		}
85 85
 
86 86
 		return '';
Please login to merge, or discard this patch.
src/wordlift/link/class-link.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
 
10 10
 interface Link {
11 11
 
12
-	public function get_link_title( $id, $label_to_be_ignored );
12
+    public function get_link_title( $id, $label_to_be_ignored );
13 13
 
14
-	public function get_same_as_uris( $id );
14
+    public function get_same_as_uris( $id );
15 15
 
16
-	public function get_id( $uri );
16
+    public function get_id( $uri );
17 17
 
18
-	public function get_synonyms( $id );
18
+    public function get_synonyms( $id );
19 19
 
20
-	public function get_permalink( $id );
20
+    public function get_permalink( $id );
21 21
 
22
-	/**
23
-	 * Return the edit page link.
24
-	 *
25
-	 * @param $id
26
-	 *
27
-	 * @return string
28
-	 */
29
-	public function get_edit_page_link( $id );
22
+    /**
23
+     * Return the edit page link.
24
+     *
25
+     * @param $id
26
+     *
27
+     * @return string
28
+     */
29
+    public function get_edit_page_link( $id );
30 30
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,15 +9,15 @@  discard block
 block discarded – undo
9 9
 
10 10
 interface Link {
11 11
 
12
-	public function get_link_title( $id, $label_to_be_ignored );
12
+	public function get_link_title($id, $label_to_be_ignored);
13 13
 
14
-	public function get_same_as_uris( $id );
14
+	public function get_same_as_uris($id);
15 15
 
16
-	public function get_id( $uri );
16
+	public function get_id($uri);
17 17
 
18
-	public function get_synonyms( $id );
18
+	public function get_synonyms($id);
19 19
 
20
-	public function get_permalink( $id );
20
+	public function get_permalink($id);
21 21
 
22 22
 	/**
23 23
 	 * Return the edit page link.
@@ -26,5 +26,5 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return string
28 28
 	 */
29
-	public function get_edit_page_link( $id );
29
+	public function get_edit_page_link($id);
30 30
 }
Please login to merge, or discard this patch.
src/wordlift/link/class-default-link.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -11,19 +11,19 @@
 block discarded – undo
11 11
 
12 12
 abstract class Default_Link extends Singleton implements Link {
13 13
 
14
-	public function get_link_title( $id, $label_to_be_ignored ) {
14
+    public function get_link_title( $id, $label_to_be_ignored ) {
15 15
 
16
-		$entity_labels = $this->get_synonyms( $id );
16
+        $entity_labels = $this->get_synonyms( $id );
17 17
 
18
-		foreach ( $entity_labels as $entity_label ) {
19
-			// Return first synonym if it doesnt match the label.
20
-			if ( 0 !== strcasecmp( $entity_label, $label_to_be_ignored ) ) {
21
-				return $entity_label;
22
-			}
23
-		}
18
+        foreach ( $entity_labels as $entity_label ) {
19
+            // Return first synonym if it doesnt match the label.
20
+            if ( 0 !== strcasecmp( $entity_label, $label_to_be_ignored ) ) {
21
+                return $entity_label;
22
+            }
23
+        }
24 24
 
25
-		// If the label matches the synonym then dont add title attr.
26
-		return '';
27
-	}
25
+        // If the label matches the synonym then dont add title attr.
26
+        return '';
27
+    }
28 28
 
29 29
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
 
12 12
 abstract class Default_Link extends Singleton implements Link {
13 13
 
14
-	public function get_link_title( $id, $label_to_be_ignored ) {
14
+	public function get_link_title($id, $label_to_be_ignored) {
15 15
 
16
-		$entity_labels = $this->get_synonyms( $id );
16
+		$entity_labels = $this->get_synonyms($id);
17 17
 
18
-		foreach ( $entity_labels as $entity_label ) {
18
+		foreach ($entity_labels as $entity_label) {
19 19
 			// Return first synonym if it doesnt match the label.
20
-			if ( 0 !== strcasecmp( $entity_label, $label_to_be_ignored ) ) {
20
+			if (0 !== strcasecmp($entity_label, $label_to_be_ignored)) {
21 21
 				return $entity_label;
22 22
 			}
23 23
 		}
Please login to merge, or discard this patch.
src/wordlift/link/class-post-link.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -13,57 +13,57 @@
 block discarded – undo
13 13
 
14 14
 class Post_Link extends Default_Link {
15 15
 
16
-	/**
17
-	 * @var \Wordlift_Entity_Service
18
-	 */
19
-	private $entity_service;
16
+    /**
17
+     * @var \Wordlift_Entity_Service
18
+     */
19
+    private $entity_service;
20 20
 
21
-	public function __construct() {
22
-		parent::__construct();
23
-		$this->entity_service = Wordlift_Entity_Service::get_instance();
24
-	}
21
+    public function __construct() {
22
+        parent::__construct();
23
+        $this->entity_service = Wordlift_Entity_Service::get_instance();
24
+    }
25 25
 
26
-	public function get_same_as_uris( $id ) {
26
+    public function get_same_as_uris( $id ) {
27 27
 
28
-		return array_merge(
29
-			array( $this->entity_service->get_uri( $id ) ),
30
-			get_post_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS )
31
-		);
28
+        return array_merge(
29
+            array( $this->entity_service->get_uri( $id ) ),
30
+            get_post_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS )
31
+        );
32 32
 
33
-	}
33
+    }
34 34
 
35
-	public function get_id( $uri ) {
36
-		$content = Wordpress_Content_Service::get_instance()
37
-											->get_by_entity_id_or_same_as( $uri );
35
+    public function get_id( $uri ) {
36
+        $content = Wordpress_Content_Service::get_instance()
37
+                                            ->get_by_entity_id_or_same_as( $uri );
38 38
 
39
-		if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) {
40
-			return false;
41
-		}
39
+        if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) {
40
+            return false;
41
+        }
42 42
 
43
-		return $content->get_bag()->ID;
44
-	}
43
+        return $content->get_bag()->ID;
44
+    }
45 45
 
46
-	public function get_synonyms( $id ) {
47
-		// Get possible alternative entity_labels we can select from.
48
-		$entity_labels = $this->entity_service->get_alternative_labels( $id );
46
+    public function get_synonyms( $id ) {
47
+        // Get possible alternative entity_labels we can select from.
48
+        $entity_labels = $this->entity_service->get_alternative_labels( $id );
49 49
 
50
-		/*
50
+        /*
51 51
 		 * Since the original text might use an alternative entity_label than the
52 52
 		 * Entity title, add the title itself which is not returned by the api.
53 53
 		 */
54
-		$entity_labels[] = get_the_title( $id );
54
+        $entity_labels[] = get_the_title( $id );
55 55
 
56
-		// Add some randomness to the entity_label selection.
57
-		shuffle( $entity_labels );
56
+        // Add some randomness to the entity_label selection.
57
+        shuffle( $entity_labels );
58 58
 
59
-		return $entity_labels;
60
-	}
59
+        return $entity_labels;
60
+    }
61 61
 
62
-	public function get_permalink( $id ) {
63
-		return get_permalink( $id );
64
-	}
62
+    public function get_permalink( $id ) {
63
+        return get_permalink( $id );
64
+    }
65 65
 
66
-	public function get_edit_page_link( $id ) {
67
-		return get_edit_post_link( $id, 'none' );
68
-	}
66
+    public function get_edit_page_link( $id ) {
67
+        return get_edit_post_link( $id, 'none' );
68
+    }
69 69
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,47 +23,47 @@
 block discarded – undo
23 23
 		$this->entity_service = Wordlift_Entity_Service::get_instance();
24 24
 	}
25 25
 
26
-	public function get_same_as_uris( $id ) {
26
+	public function get_same_as_uris($id) {
27 27
 
28 28
 		return array_merge(
29
-			array( $this->entity_service->get_uri( $id ) ),
30
-			get_post_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS )
29
+			array($this->entity_service->get_uri($id)),
30
+			get_post_meta($id, Wordlift_Schema_Service::FIELD_SAME_AS)
31 31
 		);
32 32
 
33 33
 	}
34 34
 
35
-	public function get_id( $uri ) {
35
+	public function get_id($uri) {
36 36
 		$content = Wordpress_Content_Service::get_instance()
37
-											->get_by_entity_id_or_same_as( $uri );
37
+											->get_by_entity_id_or_same_as($uri);
38 38
 
39
-		if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) {
39
+		if ( ! isset($content) || ! is_a($content->get_bag(), '\WP_Post')) {
40 40
 			return false;
41 41
 		}
42 42
 
43 43
 		return $content->get_bag()->ID;
44 44
 	}
45 45
 
46
-	public function get_synonyms( $id ) {
46
+	public function get_synonyms($id) {
47 47
 		// Get possible alternative entity_labels we can select from.
48
-		$entity_labels = $this->entity_service->get_alternative_labels( $id );
48
+		$entity_labels = $this->entity_service->get_alternative_labels($id);
49 49
 
50 50
 		/*
51 51
 		 * Since the original text might use an alternative entity_label than the
52 52
 		 * Entity title, add the title itself which is not returned by the api.
53 53
 		 */
54
-		$entity_labels[] = get_the_title( $id );
54
+		$entity_labels[] = get_the_title($id);
55 55
 
56 56
 		// Add some randomness to the entity_label selection.
57
-		shuffle( $entity_labels );
57
+		shuffle($entity_labels);
58 58
 
59 59
 		return $entity_labels;
60 60
 	}
61 61
 
62
-	public function get_permalink( $id ) {
63
-		return get_permalink( $id );
62
+	public function get_permalink($id) {
63
+		return get_permalink($id);
64 64
 	}
65 65
 
66
-	public function get_edit_page_link( $id ) {
67
-		return get_edit_post_link( $id, 'none' );
66
+	public function get_edit_page_link($id) {
67
+		return get_edit_post_link($id, 'none');
68 68
 	}
69 69
 }
Please login to merge, or discard this patch.
src/wordlift/link/class-object-link-provider.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -11,110 +11,110 @@
 block discarded – undo
11 11
 use Wordlift\Object_Type_Enum;
12 12
 
13 13
 class Object_Link_Provider extends Singleton {
14
-	/**
15
-	 * @var array<Link>
16
-	 */
17
-	private $link_providers;
18
-
19
-	public function __construct() {
20
-		parent::__construct();
21
-		$this->link_providers = array(
22
-			Object_Type_Enum::POST => Post_Link::get_instance(),
23
-			Object_Type_Enum::TERM => Term_Link::get_instance(),
24
-		);
25
-	}
26
-
27
-	/**
28
-	 * @param $id int
29
-	 * @param $label_to_be_ignored string
30
-	 * @param $object_type int
31
-	 *
32
-	 * @return string
33
-	 */
34
-	public function get_link_title( $id, $label_to_be_ignored, $object_type ) {
35
-		$provider = $this->get_provider( $object_type );
36
-		if ( ! $provider ) {
37
-			return '';
38
-		}
39
-
40
-		return $provider->get_link_title( $id, $label_to_be_ignored );
41
-	}
42
-
43
-	/**
44
-	 * Return the object type by the entity uri.
45
-	 *
46
-	 * @return int which can be any of the {@link Object_Type_Enum} values.
47
-	 */
48
-	public function get_object_type( $uri ) {
49
-
50
-		$link_providers = $this->link_providers;
51
-		foreach ( $link_providers as $type => $provider ) {
52
-			/**
53
-			 * @var $provider Link
54
-			 */
55
-			$id = $provider->get_id( $uri );
56
-			if ( $id ) {
57
-				return $type;
58
-			}
59
-		}
60
-
61
-		return Object_Type_Enum::UNKNOWN;
62
-	}
63
-
64
-	public function get_same_as_uris( $id, $object_type ) {
65
-
66
-		$provider = $this->get_provider( $object_type );
67
-		if ( ! $provider ) {
68
-			return array();
69
-		}
70
-
71
-		return $provider->get_same_as_uris( $id );
72
-	}
73
-
74
-	/**
75
-	 * @param $object_type
76
-	 *
77
-	 * @return mixed|Link
78
-	 */
79
-	private function get_provider( $object_type ) {
80
-
81
-		if ( ! array_key_exists( $object_type, $this->link_providers ) ) {
82
-			return false;
83
-		}
84
-
85
-		return $this->link_providers[ $object_type ];
86
-	}
87
-
88
-	public function get_permalink( $id, $object_type ) {
89
-		$provider = $this->get_provider( $object_type );
90
-		if ( ! $provider ) {
91
-			return false;
92
-		}
93
-
94
-		return $provider->get_permalink( $id );
95
-	}
96
-
97
-	/**
98
-	 * Return the edit term page link.
99
-	 *
100
-	 * @param $object_id
101
-	 * @param $uri
102
-	 *
103
-	 * @return string | false
104
-	 * @since 3.32.0
105
-	 */
106
-	public function get_edit_page_link( $object_id, $uri ) {
107
-
108
-		$object_type = $this->get_object_type( $uri );
109
-
110
-		$provider = $this->get_provider( $object_type );
111
-
112
-		if ( ! $provider ) {
113
-			return false;
114
-		}
115
-
116
-		return $provider->get_edit_page_link( $object_id );
117
-
118
-	}
14
+    /**
15
+     * @var array<Link>
16
+     */
17
+    private $link_providers;
18
+
19
+    public function __construct() {
20
+        parent::__construct();
21
+        $this->link_providers = array(
22
+            Object_Type_Enum::POST => Post_Link::get_instance(),
23
+            Object_Type_Enum::TERM => Term_Link::get_instance(),
24
+        );
25
+    }
26
+
27
+    /**
28
+     * @param $id int
29
+     * @param $label_to_be_ignored string
30
+     * @param $object_type int
31
+     *
32
+     * @return string
33
+     */
34
+    public function get_link_title( $id, $label_to_be_ignored, $object_type ) {
35
+        $provider = $this->get_provider( $object_type );
36
+        if ( ! $provider ) {
37
+            return '';
38
+        }
39
+
40
+        return $provider->get_link_title( $id, $label_to_be_ignored );
41
+    }
42
+
43
+    /**
44
+     * Return the object type by the entity uri.
45
+     *
46
+     * @return int which can be any of the {@link Object_Type_Enum} values.
47
+     */
48
+    public function get_object_type( $uri ) {
49
+
50
+        $link_providers = $this->link_providers;
51
+        foreach ( $link_providers as $type => $provider ) {
52
+            /**
53
+             * @var $provider Link
54
+             */
55
+            $id = $provider->get_id( $uri );
56
+            if ( $id ) {
57
+                return $type;
58
+            }
59
+        }
60
+
61
+        return Object_Type_Enum::UNKNOWN;
62
+    }
63
+
64
+    public function get_same_as_uris( $id, $object_type ) {
65
+
66
+        $provider = $this->get_provider( $object_type );
67
+        if ( ! $provider ) {
68
+            return array();
69
+        }
70
+
71
+        return $provider->get_same_as_uris( $id );
72
+    }
73
+
74
+    /**
75
+     * @param $object_type
76
+     *
77
+     * @return mixed|Link
78
+     */
79
+    private function get_provider( $object_type ) {
80
+
81
+        if ( ! array_key_exists( $object_type, $this->link_providers ) ) {
82
+            return false;
83
+        }
84
+
85
+        return $this->link_providers[ $object_type ];
86
+    }
87
+
88
+    public function get_permalink( $id, $object_type ) {
89
+        $provider = $this->get_provider( $object_type );
90
+        if ( ! $provider ) {
91
+            return false;
92
+        }
93
+
94
+        return $provider->get_permalink( $id );
95
+    }
96
+
97
+    /**
98
+     * Return the edit term page link.
99
+     *
100
+     * @param $object_id
101
+     * @param $uri
102
+     *
103
+     * @return string | false
104
+     * @since 3.32.0
105
+     */
106
+    public function get_edit_page_link( $object_id, $uri ) {
107
+
108
+        $object_type = $this->get_object_type( $uri );
109
+
110
+        $provider = $this->get_provider( $object_type );
111
+
112
+        if ( ! $provider ) {
113
+            return false;
114
+        }
115
+
116
+        return $provider->get_edit_page_link( $object_id );
117
+
118
+    }
119 119
 
120 120
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @return string
33 33
 	 */
34
-	public function get_link_title( $id, $label_to_be_ignored, $object_type ) {
35
-		$provider = $this->get_provider( $object_type );
36
-		if ( ! $provider ) {
34
+	public function get_link_title($id, $label_to_be_ignored, $object_type) {
35
+		$provider = $this->get_provider($object_type);
36
+		if ( ! $provider) {
37 37
 			return '';
38 38
 		}
39 39
 
40
-		return $provider->get_link_title( $id, $label_to_be_ignored );
40
+		return $provider->get_link_title($id, $label_to_be_ignored);
41 41
 	}
42 42
 
43 43
 	/**
@@ -45,15 +45,15 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return int which can be any of the {@link Object_Type_Enum} values.
47 47
 	 */
48
-	public function get_object_type( $uri ) {
48
+	public function get_object_type($uri) {
49 49
 
50 50
 		$link_providers = $this->link_providers;
51
-		foreach ( $link_providers as $type => $provider ) {
51
+		foreach ($link_providers as $type => $provider) {
52 52
 			/**
53 53
 			 * @var $provider Link
54 54
 			 */
55
-			$id = $provider->get_id( $uri );
56
-			if ( $id ) {
55
+			$id = $provider->get_id($uri);
56
+			if ($id) {
57 57
 				return $type;
58 58
 			}
59 59
 		}
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
 		return Object_Type_Enum::UNKNOWN;
62 62
 	}
63 63
 
64
-	public function get_same_as_uris( $id, $object_type ) {
64
+	public function get_same_as_uris($id, $object_type) {
65 65
 
66
-		$provider = $this->get_provider( $object_type );
67
-		if ( ! $provider ) {
66
+		$provider = $this->get_provider($object_type);
67
+		if ( ! $provider) {
68 68
 			return array();
69 69
 		}
70 70
 
71
-		return $provider->get_same_as_uris( $id );
71
+		return $provider->get_same_as_uris($id);
72 72
 	}
73 73
 
74 74
 	/**
@@ -76,22 +76,22 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @return mixed|Link
78 78
 	 */
79
-	private function get_provider( $object_type ) {
79
+	private function get_provider($object_type) {
80 80
 
81
-		if ( ! array_key_exists( $object_type, $this->link_providers ) ) {
81
+		if ( ! array_key_exists($object_type, $this->link_providers)) {
82 82
 			return false;
83 83
 		}
84 84
 
85
-		return $this->link_providers[ $object_type ];
85
+		return $this->link_providers[$object_type];
86 86
 	}
87 87
 
88
-	public function get_permalink( $id, $object_type ) {
89
-		$provider = $this->get_provider( $object_type );
90
-		if ( ! $provider ) {
88
+	public function get_permalink($id, $object_type) {
89
+		$provider = $this->get_provider($object_type);
90
+		if ( ! $provider) {
91 91
 			return false;
92 92
 		}
93 93
 
94
-		return $provider->get_permalink( $id );
94
+		return $provider->get_permalink($id);
95 95
 	}
96 96
 
97 97
 	/**
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @return string | false
104 104
 	 * @since 3.32.0
105 105
 	 */
106
-	public function get_edit_page_link( $object_id, $uri ) {
106
+	public function get_edit_page_link($object_id, $uri) {
107 107
 
108
-		$object_type = $this->get_object_type( $uri );
108
+		$object_type = $this->get_object_type($uri);
109 109
 
110
-		$provider = $this->get_provider( $object_type );
110
+		$provider = $this->get_provider($object_type);
111 111
 
112
-		if ( ! $provider ) {
112
+		if ( ! $provider) {
113 113
 			return false;
114 114
 		}
115 115
 
116
-		return $provider->get_edit_page_link( $object_id );
116
+		return $provider->get_edit_page_link($object_id);
117 117
 
118 118
 	}
119 119
 
Please login to merge, or discard this patch.
src/wordlift/no-editor-analysis/class-meta-box.php 2 patches
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -10,38 +10,38 @@
 block discarded – undo
10 10
 
11 11
 class Meta_Box {
12 12
 
13
-	const META_BOX_ID = 'wl-no-editor-analysis-meta-box';
14
-
15
-	public function init() {
16
-		add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
17
-	}
18
-
19
-	public function add_meta_box( $post_type ) {
20
-
21
-		// We enable it for only the post types which doesn't support the editor and
22
-		// enabled on the filter.
23
-		if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( get_the_ID() ) ) {
24
-			return;
25
-		}
26
-
27
-		add_meta_box(
28
-			self::META_BOX_ID,
29
-			__( 'WordLift', 'wordlift' ),
30
-			array( $this, 'render_meta_box' ),
31
-			$post_type,
32
-			'side',
33
-			'high'
34
-		);
35
-
36
-	}
37
-
38
-	public function render_meta_box() {
39
-		echo sprintf(
40
-			"<div id='%s'></div><div id='%s'></div>",
41
-			esc_attr( 'wl-no-editor-analysis-meta-box-content' ),
42
-			// Div to store the entities.
43
-			esc_attr( 'wl-no-editor-analysis-meta-box-storage' )
44
-		);
45
-	}
13
+    const META_BOX_ID = 'wl-no-editor-analysis-meta-box';
14
+
15
+    public function init() {
16
+        add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
17
+    }
18
+
19
+    public function add_meta_box( $post_type ) {
20
+
21
+        // We enable it for only the post types which doesn't support the editor and
22
+        // enabled on the filter.
23
+        if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( get_the_ID() ) ) {
24
+            return;
25
+        }
26
+
27
+        add_meta_box(
28
+            self::META_BOX_ID,
29
+            __( 'WordLift', 'wordlift' ),
30
+            array( $this, 'render_meta_box' ),
31
+            $post_type,
32
+            'side',
33
+            'high'
34
+        );
35
+
36
+    }
37
+
38
+    public function render_meta_box() {
39
+        echo sprintf(
40
+            "<div id='%s'></div><div id='%s'></div>",
41
+            esc_attr( 'wl-no-editor-analysis-meta-box-content' ),
42
+            // Div to store the entities.
43
+            esc_attr( 'wl-no-editor-analysis-meta-box-storage' )
44
+        );
45
+    }
46 46
 
47 47
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,21 +13,21 @@  discard block
 block discarded – undo
13 13
 	const META_BOX_ID = 'wl-no-editor-analysis-meta-box';
14 14
 
15 15
 	public function init() {
16
-		add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
16
+		add_action('add_meta_boxes', array($this, 'add_meta_box'));
17 17
 	}
18 18
 
19
-	public function add_meta_box( $post_type ) {
19
+	public function add_meta_box($post_type) {
20 20
 
21 21
 		// We enable it for only the post types which doesn't support the editor and
22 22
 		// enabled on the filter.
23
-		if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( get_the_ID() ) ) {
23
+		if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used(get_the_ID())) {
24 24
 			return;
25 25
 		}
26 26
 
27 27
 		add_meta_box(
28 28
 			self::META_BOX_ID,
29
-			__( 'WordLift', 'wordlift' ),
30
-			array( $this, 'render_meta_box' ),
29
+			__('WordLift', 'wordlift'),
30
+			array($this, 'render_meta_box'),
31 31
 			$post_type,
32 32
 			'side',
33 33
 			'high'
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	public function render_meta_box() {
39 39
 		echo sprintf(
40 40
 			"<div id='%s'></div><div id='%s'></div>",
41
-			esc_attr( 'wl-no-editor-analysis-meta-box-content' ),
41
+			esc_attr('wl-no-editor-analysis-meta-box-content'),
42 42
 			// Div to store the entities.
43
-			esc_attr( 'wl-no-editor-analysis-meta-box-storage' )
43
+			esc_attr('wl-no-editor-analysis-meta-box-storage')
44 44
 		);
45 45
 	}
46 46
 
Please login to merge, or discard this patch.
src/wordlift/no-editor-analysis/class-post-type.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -3,19 +3,19 @@
 block discarded – undo
3 3
 
4 4
 class Post_Type {
5 5
 
6
-	public static function is_no_editor_analysis_enabled_for_post_type( $post_type ) {
6
+    public static function is_no_editor_analysis_enabled_for_post_type( $post_type ) {
7 7
 
8
-		if ( ! $post_type ) {
9
-			return false;
10
-		}
8
+        if ( ! $post_type ) {
9
+            return false;
10
+        }
11 11
 
12
-		if ( ! post_type_exists( $post_type ) ) {
13
-			return false;
14
-		}
12
+        if ( ! post_type_exists( $post_type ) ) {
13
+            return false;
14
+        }
15 15
 
16
-		// Enable it on post types which doesn't have editor by default.
17
-		return ! post_type_supports( $post_type, 'editor' );
16
+        // Enable it on post types which doesn't have editor by default.
17
+        return ! post_type_supports( $post_type, 'editor' );
18 18
 
19
-	}
19
+    }
20 20
 
21 21
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -3,18 +3,18 @@
 block discarded – undo
3 3
 
4 4
 class Post_Type {
5 5
 
6
-	public static function is_no_editor_analysis_enabled_for_post_type( $post_type ) {
6
+	public static function is_no_editor_analysis_enabled_for_post_type($post_type) {
7 7
 
8
-		if ( ! $post_type ) {
8
+		if ( ! $post_type) {
9 9
 			return false;
10 10
 		}
11 11
 
12
-		if ( ! post_type_exists( $post_type ) ) {
12
+		if ( ! post_type_exists($post_type)) {
13 13
 			return false;
14 14
 		}
15 15
 
16 16
 		// Enable it on post types which doesn't have editor by default.
17
-		return ! post_type_supports( $post_type, 'editor' );
17
+		return ! post_type_supports($post_type, 'editor');
18 18
 
19 19
 	}
20 20
 
Please login to merge, or discard this patch.
src/wordlift/no-editor-analysis/class-edit-post-scripts.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
 
8 8
 class Edit_Post_Scripts extends Edit_Post_Loader {
9 9
 
10
-	const HANDLE = 'wl-no-editor-analysis-deps';
11
-
12
-	public function run_on_edit_post_screen() {
13
-
14
-		// Dont load this script if the post doesnt support it.
15
-		if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( get_the_ID() ) ) {
16
-			return;
17
-		}
18
-
19
-		Scripts_Helper::enqueue_based_on_wordpress_version(
20
-			self::HANDLE,
21
-			plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/no-editor-analysis',
22
-			array(
23
-				'react',
24
-				'react-dom',
25
-				'wp-api-fetch',
26
-				'wp-blocks',
27
-				'wp-components',
28
-				'wp-data',
29
-				'wp-element',
30
-				'wp-hooks',
31
-				'wp-polyfill',
32
-				'wp-rich-text',
33
-			),
34
-			true
35
-		);
36
-
37
-		wp_enqueue_style(
38
-			self::HANDLE,
39
-			plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/no-editor-analysis.full.css',
40
-			array(),
41
-			WORDLIFT_VERSION
42
-		);
43
-
44
-	}
10
+    const HANDLE = 'wl-no-editor-analysis-deps';
11
+
12
+    public function run_on_edit_post_screen() {
13
+
14
+        // Dont load this script if the post doesnt support it.
15
+        if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( get_the_ID() ) ) {
16
+            return;
17
+        }
18
+
19
+        Scripts_Helper::enqueue_based_on_wordpress_version(
20
+            self::HANDLE,
21
+            plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/no-editor-analysis',
22
+            array(
23
+                'react',
24
+                'react-dom',
25
+                'wp-api-fetch',
26
+                'wp-blocks',
27
+                'wp-components',
28
+                'wp-data',
29
+                'wp-element',
30
+                'wp-hooks',
31
+                'wp-polyfill',
32
+                'wp-rich-text',
33
+            ),
34
+            true
35
+        );
36
+
37
+        wp_enqueue_style(
38
+            self::HANDLE,
39
+            plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/no-editor-analysis.full.css',
40
+            array(),
41
+            WORDLIFT_VERSION
42
+        );
43
+
44
+    }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@  discard block
 block discarded – undo
12 12
 	public function run_on_edit_post_screen() {
13 13
 
14 14
 		// Dont load this script if the post doesnt support it.
15
-		if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( get_the_ID() ) ) {
15
+		if ( ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used(get_the_ID())) {
16 16
 			return;
17 17
 		}
18 18
 
19 19
 		Scripts_Helper::enqueue_based_on_wordpress_version(
20 20
 			self::HANDLE,
21
-			plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/no-editor-analysis',
21
+			plugin_dir_url(dirname(__DIR__)).'js/dist/no-editor-analysis',
22 22
 			array(
23 23
 				'react',
24 24
 				'react-dom',
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
 		wp_enqueue_style(
38 38
 			self::HANDLE,
39
-			plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/no-editor-analysis.full.css',
39
+			plugin_dir_url(dirname(__DIR__)).'js/dist/no-editor-analysis.full.css',
40 40
 			array(),
41 41
 			WORDLIFT_VERSION
42 42
 		);
Please login to merge, or discard this patch.