Completed
Push — develop ( f5cfcc...e2baaf )
by Naveen
01:17
created
src/wordlift/http/class-http-client.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,27 +15,27 @@
 block discarded – undo
15 15
  */
16 16
 interface Http_Client {
17 17
 
18
-	/**
19
-	 * Perform a `GET` operation to the specified `$url`.
20
-	 *
21
-	 * @param string $url The URL.
22
-	 * @param array  $options An array of options to pass to WordPress {@link wp_remote_request} function, default: array().
23
-	 *
24
-	 * @return \WP_Error|array The response or WP_Error on failure.
25
-	 * @since 1.0.0
26
-	 *
27
-	 */
28
-	function get( $url, $options = array() );
18
+    /**
19
+     * Perform a `GET` operation to the specified `$url`.
20
+     *
21
+     * @param string $url The URL.
22
+     * @param array  $options An array of options to pass to WordPress {@link wp_remote_request} function, default: array().
23
+     *
24
+     * @return \WP_Error|array The response or WP_Error on failure.
25
+     * @since 1.0.0
26
+     *
27
+     */
28
+    function get( $url, $options = array() );
29 29
 
30
-	/**
31
-	 * Perform a request to the specified `$url`.
32
-	 *
33
-	 * @param string $url The URL.
34
-	 * @param array  $options An array of options to pass to WordPress {@link wp_remote_request} function, default: array().
35
-	 *
36
-	 * @return \WP_Error|array The response or WP_Error on failure.
37
-	 * @since 1.0.0
38
-	 */
39
-	function request( $url, $options = array() );
30
+    /**
31
+     * Perform a request to the specified `$url`.
32
+     *
33
+     * @param string $url The URL.
34
+     * @param array  $options An array of options to pass to WordPress {@link wp_remote_request} function, default: array().
35
+     *
36
+     * @return \WP_Error|array The response or WP_Error on failure.
37
+     * @since 1.0.0
38
+     */
39
+    function request( $url, $options = array() );
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * @since 1.0.0
26 26
 	 *
27 27
 	 */
28
-	function get( $url, $options = array() );
28
+	function get($url, $options = array());
29 29
 
30 30
 	/**
31 31
 	 * Perform a request to the specified `$url`.
@@ -36,6 +36,6 @@  discard block
 block discarded – undo
36 36
 	 * @return \WP_Error|array The response or WP_Error on failure.
37 37
 	 * @since 1.0.0
38 38
 	 */
39
-	function request( $url, $options = array() );
39
+	function request($url, $options = array());
40 40
 
41 41
 }
Please login to merge, or discard this patch.
src/wordlift/http/class-cacheable-http-client.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -15,108 +15,108 @@
 block discarded – undo
15 15
 // @@todo: add a hook to clear the cached files now and then.
16 16
 class Cacheable_Http_Client extends Simple_Http_Client {
17 17
 
18
-	/**
19
-	 * The TTL of cached responses in seconds.
20
-	 *
21
-	 * @var int $ttl The TTL in seconds.
22
-	 * @access private
23
-	 * @since 1.0.0
24
-	 */
25
-	private $ttl;
26
-
27
-	/**
28
-	 * The cache dir where the cached responses are written.
29
-	 *
30
-	 * @since 1.0.0
31
-	 * @access private
32
-	 * @var string $cache_dir The cache dir where the cached responses are written.
33
-	 */
34
-	private $cache_dir;
35
-
36
-	/**
37
-	 * A {@link Wordlift_Log_Service} instance.
38
-	 *
39
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
40
-	 * @access private
41
-	 * @since 1.0.0
42
-	 */
43
-	private $log;
44
-
45
-	/**
46
-	 * Create a {@link Cacheable_Http_Client} with the specified TTL, default 900 secs.
47
-	 *
48
-	 * @param int $ttl The cache TTL, default 900 secs.
49
-	 *
50
-	 * @since 1.0.0
51
-	 */
52
-	public function __construct( $ttl = 900 ) {
53
-
54
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
55
-
56
-		$this->ttl = $ttl;
57
-
58
-		// Get the temp dir and add the directory separator if missing.
59
-		$temp_dir = get_temp_dir();
60
-		if ( DIRECTORY_SEPARATOR !== substr( $temp_dir, - strlen( DIRECTORY_SEPARATOR ) ) ) {
61
-			$temp_dir .= DIRECTORY_SEPARATOR;
62
-		}
63
-		$this->cache_dir = $temp_dir . 'wlfb-http-cache';
64
-
65
-		$this->log->trace( "Creating the cache folder {$this->cache_dir}..." );
66
-		wp_mkdir_p( $this->cache_dir );
67
-
68
-	}
69
-
70
-	/**
71
-	 * @inheritDoc
72
-	 */
73
-	public function request( $url, $options = array() ) {
74
-
75
-		// Create a hash and a path to the cache file.
76
-		$hash     = md5( $url ) . '-' . md5( serialize( $options ) );
77
-		$filename = $this->get_path( $hash );
78
-
79
-		// If the cache file exists and it's not too old, then return it.
80
-		if ( file_exists( $filename ) && $this->ttl >= time() - filemtime( $filename ) ) {
81
-			$this->log->trace( "Cache HIT.\n" );
82
-
83
-			return json_decode( file_get_contents( $filename ), true );
84
-		}
85
-
86
-		$this->log->trace( "Cache MISS for URL $url, hash $hash.\n" );
87
-
88
-		// Get a fresh response and return it.
89
-		$response = parent::request( $url, $options );
90
-
91
-		// Return immediately, do not cache.
92
-		if ( is_wp_error( $response ) ) {
93
-			return $response;
94
-		}
95
-
96
-		// Do not cache response with invalid status codes or status code different from 2xx.
97
-		$code = wp_remote_retrieve_response_code( $response );
98
-		if ( ! is_numeric( $code ) || 2 !== intval( $code ) / 100 ) {
99
-			return $response;
100
-		}
101
-
102
-		// Cache.
103
-		@unlink( $filename );
104
-		@file_put_contents( $filename, json_encode( $response ) );
105
-
106
-		return $response;
107
-	}
108
-
109
-	/**
110
-	 * Get the full path for the given `$hash`. The file is not checked for its existence.
111
-	 *
112
-	 * @param string $hash A file hash.
113
-	 *
114
-	 * @return string The full path to the file.
115
-	 * @since 1.0.0
116
-	 */
117
-	private function get_path( $hash ) {
118
-
119
-		return $this->cache_dir . DIRECTORY_SEPARATOR . $hash;
120
-	}
18
+    /**
19
+     * The TTL of cached responses in seconds.
20
+     *
21
+     * @var int $ttl The TTL in seconds.
22
+     * @access private
23
+     * @since 1.0.0
24
+     */
25
+    private $ttl;
26
+
27
+    /**
28
+     * The cache dir where the cached responses are written.
29
+     *
30
+     * @since 1.0.0
31
+     * @access private
32
+     * @var string $cache_dir The cache dir where the cached responses are written.
33
+     */
34
+    private $cache_dir;
35
+
36
+    /**
37
+     * A {@link Wordlift_Log_Service} instance.
38
+     *
39
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
40
+     * @access private
41
+     * @since 1.0.0
42
+     */
43
+    private $log;
44
+
45
+    /**
46
+     * Create a {@link Cacheable_Http_Client} with the specified TTL, default 900 secs.
47
+     *
48
+     * @param int $ttl The cache TTL, default 900 secs.
49
+     *
50
+     * @since 1.0.0
51
+     */
52
+    public function __construct( $ttl = 900 ) {
53
+
54
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
55
+
56
+        $this->ttl = $ttl;
57
+
58
+        // Get the temp dir and add the directory separator if missing.
59
+        $temp_dir = get_temp_dir();
60
+        if ( DIRECTORY_SEPARATOR !== substr( $temp_dir, - strlen( DIRECTORY_SEPARATOR ) ) ) {
61
+            $temp_dir .= DIRECTORY_SEPARATOR;
62
+        }
63
+        $this->cache_dir = $temp_dir . 'wlfb-http-cache';
64
+
65
+        $this->log->trace( "Creating the cache folder {$this->cache_dir}..." );
66
+        wp_mkdir_p( $this->cache_dir );
67
+
68
+    }
69
+
70
+    /**
71
+     * @inheritDoc
72
+     */
73
+    public function request( $url, $options = array() ) {
74
+
75
+        // Create a hash and a path to the cache file.
76
+        $hash     = md5( $url ) . '-' . md5( serialize( $options ) );
77
+        $filename = $this->get_path( $hash );
78
+
79
+        // If the cache file exists and it's not too old, then return it.
80
+        if ( file_exists( $filename ) && $this->ttl >= time() - filemtime( $filename ) ) {
81
+            $this->log->trace( "Cache HIT.\n" );
82
+
83
+            return json_decode( file_get_contents( $filename ), true );
84
+        }
85
+
86
+        $this->log->trace( "Cache MISS for URL $url, hash $hash.\n" );
87
+
88
+        // Get a fresh response and return it.
89
+        $response = parent::request( $url, $options );
90
+
91
+        // Return immediately, do not cache.
92
+        if ( is_wp_error( $response ) ) {
93
+            return $response;
94
+        }
95
+
96
+        // Do not cache response with invalid status codes or status code different from 2xx.
97
+        $code = wp_remote_retrieve_response_code( $response );
98
+        if ( ! is_numeric( $code ) || 2 !== intval( $code ) / 100 ) {
99
+            return $response;
100
+        }
101
+
102
+        // Cache.
103
+        @unlink( $filename );
104
+        @file_put_contents( $filename, json_encode( $response ) );
105
+
106
+        return $response;
107
+    }
108
+
109
+    /**
110
+     * Get the full path for the given `$hash`. The file is not checked for its existence.
111
+     *
112
+     * @param string $hash A file hash.
113
+     *
114
+     * @return string The full path to the file.
115
+     * @since 1.0.0
116
+     */
117
+    private function get_path( $hash ) {
118
+
119
+        return $this->cache_dir . DIRECTORY_SEPARATOR . $hash;
120
+    }
121 121
 
122 122
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -49,59 +49,59 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @since 1.0.0
51 51
 	 */
52
-	public function __construct( $ttl = 900 ) {
52
+	public function __construct($ttl = 900) {
53 53
 
54
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
54
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
55 55
 
56 56
 		$this->ttl = $ttl;
57 57
 
58 58
 		// Get the temp dir and add the directory separator if missing.
59 59
 		$temp_dir = get_temp_dir();
60
-		if ( DIRECTORY_SEPARATOR !== substr( $temp_dir, - strlen( DIRECTORY_SEPARATOR ) ) ) {
60
+		if (DIRECTORY_SEPARATOR !== substr($temp_dir, - strlen(DIRECTORY_SEPARATOR))) {
61 61
 			$temp_dir .= DIRECTORY_SEPARATOR;
62 62
 		}
63
-		$this->cache_dir = $temp_dir . 'wlfb-http-cache';
63
+		$this->cache_dir = $temp_dir.'wlfb-http-cache';
64 64
 
65
-		$this->log->trace( "Creating the cache folder {$this->cache_dir}..." );
66
-		wp_mkdir_p( $this->cache_dir );
65
+		$this->log->trace("Creating the cache folder {$this->cache_dir}...");
66
+		wp_mkdir_p($this->cache_dir);
67 67
 
68 68
 	}
69 69
 
70 70
 	/**
71 71
 	 * @inheritDoc
72 72
 	 */
73
-	public function request( $url, $options = array() ) {
73
+	public function request($url, $options = array()) {
74 74
 
75 75
 		// Create a hash and a path to the cache file.
76
-		$hash     = md5( $url ) . '-' . md5( serialize( $options ) );
77
-		$filename = $this->get_path( $hash );
76
+		$hash     = md5($url).'-'.md5(serialize($options));
77
+		$filename = $this->get_path($hash);
78 78
 
79 79
 		// If the cache file exists and it's not too old, then return it.
80
-		if ( file_exists( $filename ) && $this->ttl >= time() - filemtime( $filename ) ) {
81
-			$this->log->trace( "Cache HIT.\n" );
80
+		if (file_exists($filename) && $this->ttl >= time() - filemtime($filename)) {
81
+			$this->log->trace("Cache HIT.\n");
82 82
 
83
-			return json_decode( file_get_contents( $filename ), true );
83
+			return json_decode(file_get_contents($filename), true);
84 84
 		}
85 85
 
86
-		$this->log->trace( "Cache MISS for URL $url, hash $hash.\n" );
86
+		$this->log->trace("Cache MISS for URL $url, hash $hash.\n");
87 87
 
88 88
 		// Get a fresh response and return it.
89
-		$response = parent::request( $url, $options );
89
+		$response = parent::request($url, $options);
90 90
 
91 91
 		// Return immediately, do not cache.
92
-		if ( is_wp_error( $response ) ) {
92
+		if (is_wp_error($response)) {
93 93
 			return $response;
94 94
 		}
95 95
 
96 96
 		// Do not cache response with invalid status codes or status code different from 2xx.
97
-		$code = wp_remote_retrieve_response_code( $response );
98
-		if ( ! is_numeric( $code ) || 2 !== intval( $code ) / 100 ) {
97
+		$code = wp_remote_retrieve_response_code($response);
98
+		if ( ! is_numeric($code) || 2 !== intval($code) / 100) {
99 99
 			return $response;
100 100
 		}
101 101
 
102 102
 		// Cache.
103
-		@unlink( $filename );
104
-		@file_put_contents( $filename, json_encode( $response ) );
103
+		@unlink($filename);
104
+		@file_put_contents($filename, json_encode($response));
105 105
 
106 106
 		return $response;
107 107
 	}
@@ -114,9 +114,9 @@  discard block
 block discarded – undo
114 114
 	 * @return string The full path to the file.
115 115
 	 * @since 1.0.0
116 116
 	 */
117
-	private function get_path( $hash ) {
117
+	private function get_path($hash) {
118 118
 
119
-		return $this->cache_dir . DIRECTORY_SEPARATOR . $hash;
119
+		return $this->cache_dir.DIRECTORY_SEPARATOR.$hash;
120 120
 	}
121 121
 
122 122
 }
Please login to merge, or discard this patch.
src/wordlift/http/class-simple-http-client.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@
 block discarded – undo
10 10
  */
11 11
 class Simple_Http_Client implements Http_Client {
12 12
 
13
-	/**
14
-	 * @inheritDoc
15
-	 */
16
-	public function get( $url, $options = array() ) {
13
+    /**
14
+     * @inheritDoc
15
+     */
16
+    public function get( $url, $options = array() ) {
17 17
 
18
-		$options['method'] = 'GET';
18
+        $options['method'] = 'GET';
19 19
 
20
-		return $this->request( $url, $options );
21
-	}
20
+        return $this->request( $url, $options );
21
+    }
22 22
 
23
-	/**
24
-	 * @inheritDoc
25
-	 */
26
-	public function request( $url, $options = array() ) {
23
+    /**
24
+     * @inheritDoc
25
+     */
26
+    public function request( $url, $options = array() ) {
27 27
 
28
-		return wp_remote_request( $url, $options );
29
-	}
28
+        return wp_remote_request( $url, $options );
29
+    }
30 30
 
31 31
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@
 block discarded – undo
13 13
 	/**
14 14
 	 * @inheritDoc
15 15
 	 */
16
-	public function get( $url, $options = array() ) {
16
+	public function get($url, $options = array()) {
17 17
 
18 18
 		$options['method'] = 'GET';
19 19
 
20
-		return $this->request( $url, $options );
20
+		return $this->request($url, $options);
21 21
 	}
22 22
 
23 23
 	/**
24 24
 	 * @inheritDoc
25 25
 	 */
26
-	public function request( $url, $options = array() ) {
26
+	public function request($url, $options = array()) {
27 27
 
28
-		return wp_remote_request( $url, $options );
28
+		return wp_remote_request($url, $options);
29 29
 	}
30 30
 
31 31
 }
Please login to merge, or discard this patch.
linked-data/rendition/class-wordlift-default-sparql-tuple-rendition.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -19,147 +19,147 @@
 block discarded – undo
19 19
  */
20 20
 class Wordlift_Default_Sparql_Tuple_Rendition implements Wordlift_Sparql_Tuple_Rendition {
21 21
 
22
-	/**
23
-	 * A {@link Wordlift_Storage} instance to read a property.
24
-	 *
25
-	 * @since  3.15.0
26
-	 * @access private
27
-	 * @var \Wordlift_Storage $storage A {@link Wordlift_Storage} instance to
28
-	 *                                 read a property.
29
-	 */
30
-	private $storage;
31
-
32
-	/**
33
-	 * The data type (or null if not set).
34
-	 *
35
-	 * @since  3.15.0
36
-	 * @access private
37
-	 * @var string|null $data_type The data type (or null if not set).
38
-	 */
39
-	private $data_type;
40
-
41
-	/**
42
-	 * The language (or null if not set).
43
-	 *
44
-	 * @since  3.15.0
45
-	 * @access private
46
-	 * @var string|null $language The language (or null if not set).
47
-	 */
48
-	private $language;
49
-
50
-	/**
51
-	 * The {@link Wordlift_Entity_Service} instance.
52
-	 *
53
-	 * @since  3.15.0
54
-	 * @access private
55
-	 * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
56
-	 */
57
-	private $entity_service;
58
-
59
-	/**
60
-	 * The predicate URI.
61
-	 *
62
-	 * @since  3.15.0
63
-	 * @access private
64
-	 * @var string $predicate The predicate URI.
65
-	 */
66
-	private $predicate;
67
-
68
-	/**
69
-	 * The URI suffix.
70
-	 *
71
-	 * @since 3.18.0
72
-	 * @access private
73
-	 * @var null|string $uri_suffix The URI suffix or null if no suffix is required.
74
-	 */
75
-	private $uri_suffix;
76
-
77
-	/**
78
-	 * Create a {@link Wordlift_Sparql_Tuple_Rendition} instance.
79
-	 *
80
-	 * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service}
81
-	 *                                                 instance.
82
-	 * @param \Wordlift_Storage        $storage The {@link Wordlift_Storage}
83
-	 *                                                 instance.
84
-	 * @param string                   $predicate The predicate URI.
85
-	 * @param string|null              $data_type The data type or null.
86
-	 * @param string|null              $language The language code or null.
87
-	 * @param string|null              $uri_suffix The URI suffix, used for example for 2nd level entities, like location.
88
-	 *
89
-	 * @since 3.15.0
90
-	 *
91
-	 */
92
-	public function __construct( $entity_service, $storage, $predicate, $data_type = null, $language = null, $uri_suffix = null ) {
93
-
94
-		$this->entity_service = $entity_service;
95
-		$this->storage        = $storage;
96
-		$this->predicate      = $predicate;
97
-		$this->data_type      = $data_type;
98
-		$this->language       = $language;
99
-		$this->uri_suffix     = ( ! is_null( $uri_suffix ) ) ? $uri_suffix : '';
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get tuple representations for the specified {@link WP_Post}.
105
-	 *
106
-	 * @param int $post_id The {@link WP_Post}'s id.
107
-	 *
108
-	 * @return array An array of tuples.
109
-	 * @since 3.15.0
110
-	 *
111
-	 */
112
-	public function get_insert_triples( $post_id ) {
113
-		// Get the entity URI.
114
-		$uri = $this->entity_service->get_uri( $post_id ) . $this->uri_suffix;
115
-
116
-		// Get the predicate, data type and language.
117
-		$predicate = $this->predicate;
118
-		$data_type = $this->data_type;
119
-		$language  = $this->language;
120
-
121
-		// Filter out empty values.
122
-		$class_name = get_class( $this->storage );
123
-		$values     = array_filter( (array) $this->storage->get( $post_id ), function ( $item ) use ( $class_name, $post_id ) {
124
-			return ! empty( $item );
125
-		} );
126
-
127
-		// Map the values to tuples.
128
-		return array_map( function ( $item ) use ( $uri, $predicate, $data_type, $language ) {
129
-
130
-			return sprintf( '<%s> <%s> %s . ',
131
-				Wordlift_Sparql_Service::escape_uri( $uri ),
132
-				Wordlift_Sparql_Service::escape_uri( $predicate ),
133
-				Wordlift_Sparql_Service::format( $item, $data_type, $language )
134
-			);
135
-		}, $values );
136
-	}
137
-
138
-	/**
139
-	 * Get the delete statement for current post id.
140
-	 *
141
-	 * @param int $post_id The post id.
142
-	 *
143
-	 * @return array An array containing delete statements for both
144
-	 *               the uri as subject and object.
145
-	 * @since 3.18.0
146
-	 *
147
-	 */
148
-	public function get_delete_triples( $post_id ) {
149
-		// Get the entity URI.
150
-		$uri = $this->entity_service->get_uri( $post_id ) . $this->uri_suffix;
151
-
152
-		return array(
153
-			// As object.
154
-			sprintf( '<%s> <%s> ?o',
155
-				Wordlift_Sparql_Service::escape_uri( $uri ),
156
-				Wordlift_Sparql_Service::escape_uri( $this->predicate )
157
-			),
158
-			// As subject.
159
-			sprintf( '?s <%s> <%s>',
160
-				Wordlift_Sparql_Service::escape_uri( $this->predicate ),
161
-				Wordlift_Sparql_Service::escape_uri( $uri )
162
-			),
163
-		);
164
-	}
22
+    /**
23
+     * A {@link Wordlift_Storage} instance to read a property.
24
+     *
25
+     * @since  3.15.0
26
+     * @access private
27
+     * @var \Wordlift_Storage $storage A {@link Wordlift_Storage} instance to
28
+     *                                 read a property.
29
+     */
30
+    private $storage;
31
+
32
+    /**
33
+     * The data type (or null if not set).
34
+     *
35
+     * @since  3.15.0
36
+     * @access private
37
+     * @var string|null $data_type The data type (or null if not set).
38
+     */
39
+    private $data_type;
40
+
41
+    /**
42
+     * The language (or null if not set).
43
+     *
44
+     * @since  3.15.0
45
+     * @access private
46
+     * @var string|null $language The language (or null if not set).
47
+     */
48
+    private $language;
49
+
50
+    /**
51
+     * The {@link Wordlift_Entity_Service} instance.
52
+     *
53
+     * @since  3.15.0
54
+     * @access private
55
+     * @var \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service} instance.
56
+     */
57
+    private $entity_service;
58
+
59
+    /**
60
+     * The predicate URI.
61
+     *
62
+     * @since  3.15.0
63
+     * @access private
64
+     * @var string $predicate The predicate URI.
65
+     */
66
+    private $predicate;
67
+
68
+    /**
69
+     * The URI suffix.
70
+     *
71
+     * @since 3.18.0
72
+     * @access private
73
+     * @var null|string $uri_suffix The URI suffix or null if no suffix is required.
74
+     */
75
+    private $uri_suffix;
76
+
77
+    /**
78
+     * Create a {@link Wordlift_Sparql_Tuple_Rendition} instance.
79
+     *
80
+     * @param \Wordlift_Entity_Service $entity_service The {@link Wordlift_Entity_Service}
81
+     *                                                 instance.
82
+     * @param \Wordlift_Storage        $storage The {@link Wordlift_Storage}
83
+     *                                                 instance.
84
+     * @param string                   $predicate The predicate URI.
85
+     * @param string|null              $data_type The data type or null.
86
+     * @param string|null              $language The language code or null.
87
+     * @param string|null              $uri_suffix The URI suffix, used for example for 2nd level entities, like location.
88
+     *
89
+     * @since 3.15.0
90
+     *
91
+     */
92
+    public function __construct( $entity_service, $storage, $predicate, $data_type = null, $language = null, $uri_suffix = null ) {
93
+
94
+        $this->entity_service = $entity_service;
95
+        $this->storage        = $storage;
96
+        $this->predicate      = $predicate;
97
+        $this->data_type      = $data_type;
98
+        $this->language       = $language;
99
+        $this->uri_suffix     = ( ! is_null( $uri_suffix ) ) ? $uri_suffix : '';
100
+
101
+    }
102
+
103
+    /**
104
+     * Get tuple representations for the specified {@link WP_Post}.
105
+     *
106
+     * @param int $post_id The {@link WP_Post}'s id.
107
+     *
108
+     * @return array An array of tuples.
109
+     * @since 3.15.0
110
+     *
111
+     */
112
+    public function get_insert_triples( $post_id ) {
113
+        // Get the entity URI.
114
+        $uri = $this->entity_service->get_uri( $post_id ) . $this->uri_suffix;
115
+
116
+        // Get the predicate, data type and language.
117
+        $predicate = $this->predicate;
118
+        $data_type = $this->data_type;
119
+        $language  = $this->language;
120
+
121
+        // Filter out empty values.
122
+        $class_name = get_class( $this->storage );
123
+        $values     = array_filter( (array) $this->storage->get( $post_id ), function ( $item ) use ( $class_name, $post_id ) {
124
+            return ! empty( $item );
125
+        } );
126
+
127
+        // Map the values to tuples.
128
+        return array_map( function ( $item ) use ( $uri, $predicate, $data_type, $language ) {
129
+
130
+            return sprintf( '<%s> <%s> %s . ',
131
+                Wordlift_Sparql_Service::escape_uri( $uri ),
132
+                Wordlift_Sparql_Service::escape_uri( $predicate ),
133
+                Wordlift_Sparql_Service::format( $item, $data_type, $language )
134
+            );
135
+        }, $values );
136
+    }
137
+
138
+    /**
139
+     * Get the delete statement for current post id.
140
+     *
141
+     * @param int $post_id The post id.
142
+     *
143
+     * @return array An array containing delete statements for both
144
+     *               the uri as subject and object.
145
+     * @since 3.18.0
146
+     *
147
+     */
148
+    public function get_delete_triples( $post_id ) {
149
+        // Get the entity URI.
150
+        $uri = $this->entity_service->get_uri( $post_id ) . $this->uri_suffix;
151
+
152
+        return array(
153
+            // As object.
154
+            sprintf( '<%s> <%s> ?o',
155
+                Wordlift_Sparql_Service::escape_uri( $uri ),
156
+                Wordlift_Sparql_Service::escape_uri( $this->predicate )
157
+            ),
158
+            // As subject.
159
+            sprintf( '?s <%s> <%s>',
160
+                Wordlift_Sparql_Service::escape_uri( $this->predicate ),
161
+                Wordlift_Sparql_Service::escape_uri( $uri )
162
+            ),
163
+        );
164
+    }
165 165
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 	 * @since 3.15.0
90 90
 	 *
91 91
 	 */
92
-	public function __construct( $entity_service, $storage, $predicate, $data_type = null, $language = null, $uri_suffix = null ) {
92
+	public function __construct($entity_service, $storage, $predicate, $data_type = null, $language = null, $uri_suffix = null) {
93 93
 
94 94
 		$this->entity_service = $entity_service;
95 95
 		$this->storage        = $storage;
96 96
 		$this->predicate      = $predicate;
97 97
 		$this->data_type      = $data_type;
98 98
 		$this->language       = $language;
99
-		$this->uri_suffix     = ( ! is_null( $uri_suffix ) ) ? $uri_suffix : '';
99
+		$this->uri_suffix     = ( ! is_null($uri_suffix)) ? $uri_suffix : '';
100 100
 
101 101
 	}
102 102
 
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 	 * @since 3.15.0
110 110
 	 *
111 111
 	 */
112
-	public function get_insert_triples( $post_id ) {
112
+	public function get_insert_triples($post_id) {
113 113
 		// Get the entity URI.
114
-		$uri = $this->entity_service->get_uri( $post_id ) . $this->uri_suffix;
114
+		$uri = $this->entity_service->get_uri($post_id).$this->uri_suffix;
115 115
 
116 116
 		// Get the predicate, data type and language.
117 117
 		$predicate = $this->predicate;
@@ -119,20 +119,20 @@  discard block
 block discarded – undo
119 119
 		$language  = $this->language;
120 120
 
121 121
 		// Filter out empty values.
122
-		$class_name = get_class( $this->storage );
123
-		$values     = array_filter( (array) $this->storage->get( $post_id ), function ( $item ) use ( $class_name, $post_id ) {
124
-			return ! empty( $item );
122
+		$class_name = get_class($this->storage);
123
+		$values     = array_filter((array) $this->storage->get($post_id), function($item) use ($class_name, $post_id) {
124
+			return ! empty($item);
125 125
 		} );
126 126
 
127 127
 		// Map the values to tuples.
128
-		return array_map( function ( $item ) use ( $uri, $predicate, $data_type, $language ) {
128
+		return array_map(function($item) use ($uri, $predicate, $data_type, $language) {
129 129
 
130
-			return sprintf( '<%s> <%s> %s . ',
131
-				Wordlift_Sparql_Service::escape_uri( $uri ),
132
-				Wordlift_Sparql_Service::escape_uri( $predicate ),
133
-				Wordlift_Sparql_Service::format( $item, $data_type, $language )
130
+			return sprintf('<%s> <%s> %s . ',
131
+				Wordlift_Sparql_Service::escape_uri($uri),
132
+				Wordlift_Sparql_Service::escape_uri($predicate),
133
+				Wordlift_Sparql_Service::format($item, $data_type, $language)
134 134
 			);
135
-		}, $values );
135
+		}, $values);
136 136
 	}
137 137
 
138 138
 	/**
@@ -145,20 +145,20 @@  discard block
 block discarded – undo
145 145
 	 * @since 3.18.0
146 146
 	 *
147 147
 	 */
148
-	public function get_delete_triples( $post_id ) {
148
+	public function get_delete_triples($post_id) {
149 149
 		// Get the entity URI.
150
-		$uri = $this->entity_service->get_uri( $post_id ) . $this->uri_suffix;
150
+		$uri = $this->entity_service->get_uri($post_id).$this->uri_suffix;
151 151
 
152 152
 		return array(
153 153
 			// As object.
154
-			sprintf( '<%s> <%s> ?o',
155
-				Wordlift_Sparql_Service::escape_uri( $uri ),
156
-				Wordlift_Sparql_Service::escape_uri( $this->predicate )
154
+			sprintf('<%s> <%s> ?o',
155
+				Wordlift_Sparql_Service::escape_uri($uri),
156
+				Wordlift_Sparql_Service::escape_uri($this->predicate)
157 157
 			),
158 158
 			// As subject.
159
-			sprintf( '?s <%s> <%s>',
160
-				Wordlift_Sparql_Service::escape_uri( $this->predicate ),
161
-				Wordlift_Sparql_Service::escape_uri( $uri )
159
+			sprintf('?s <%s> <%s>',
160
+				Wordlift_Sparql_Service::escape_uri($this->predicate),
161
+				Wordlift_Sparql_Service::escape_uri($uri)
162 162
 			),
163 163
 		);
164 164
 	}
Please login to merge, or discard this patch.
src/install/class-wordlift-install-3-23-4.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -14,32 +14,32 @@
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Install_3_23_4 extends Wordlift_Install {
16 16
 
17
-	/**
18
-	 * {@inheritdoc}
19
-	 */
20
-	protected static $version = '3.23.4';
17
+    /**
18
+     * {@inheritdoc}
19
+     */
20
+    protected static $version = '3.23.4';
21 21
 
22
-	public function install() {
22
+    public function install() {
23 23
 
24
-		$existing_term = get_term_by( 'slug', 'web-page', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
24
+        $existing_term = get_term_by( 'slug', 'web-page', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
25 25
 
26
-		// Bail out if term exists.
27
-		if ( false !== $existing_term ) {
28
-			return;
29
-		}
26
+        // Bail out if term exists.
27
+        if ( false !== $existing_term ) {
28
+            return;
29
+        }
30 30
 
31
-		$term = wp_insert_term(
32
-			'WebPage',
33
-			Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
34
-			array(
35
-				'slug'        => 'web-page',
36
-				'description' => 'A Web Page.',
37
-			)
38
-		);
31
+        $term = wp_insert_term(
32
+            'WebPage',
33
+            Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
34
+            array(
35
+                'slug'        => 'web-page',
36
+                'description' => 'A Web Page.',
37
+            )
38
+        );
39 39
 
40
-		update_term_meta( $term['term_id'], '_wl_name', 'WebPage' );
41
-		update_term_meta( $term['term_id'], '_wl_uri', "http://schema.org/WebPage" );
40
+        update_term_meta( $term['term_id'], '_wl_name', 'WebPage' );
41
+        update_term_meta( $term['term_id'], '_wl_uri', "http://schema.org/WebPage" );
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 
22 22
 	public function install() {
23 23
 
24
-		$existing_term = get_term_by( 'slug', 'web-page', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME );
24
+		$existing_term = get_term_by('slug', 'web-page', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME);
25 25
 
26 26
 		// Bail out if term exists.
27
-		if ( false !== $existing_term ) {
27
+		if (false !== $existing_term) {
28 28
 			return;
29 29
 		}
30 30
 
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 			)
38 38
 		);
39 39
 
40
-		update_term_meta( $term['term_id'], '_wl_name', 'WebPage' );
41
-		update_term_meta( $term['term_id'], '_wl_uri', "http://schema.org/WebPage" );
40
+		update_term_meta($term['term_id'], '_wl_name', 'WebPage');
41
+		update_term_meta($term['term_id'], '_wl_uri', "http://schema.org/WebPage");
42 42
 
43 43
 	}
44 44
 
Please login to merge, or discard this patch.
src/includes/cache/class-wordlift-file-cache-service.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -16,231 +16,231 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_File_Cache_Service implements Wordlift_Cache_Service {
18 18
 
19
-	/**
20
-	 * The cache directory.
21
-	 *
22
-	 * @since  3.16.0
23
-	 * @access private
24
-	 * @var string $cache_dir The root cache directory (ending with a trailing slash).
25
-	 */
26
-	private $cache_dir;
27
-
28
-	/**
29
-	 * The file extension for cache files (e.g. `.wlcache`).
30
-	 *
31
-	 * @since  3.16.0
32
-	 * @access private
33
-	 * @var string $file_extension The file extension for cache files (e.g. `.wlcache`).
34
-	 */
35
-	private $file_extension;
36
-
37
-	/**
38
-	 * A {@link Wordlift_Log_Service} instance.
39
-	 *
40
-	 * @since  3.16.0
41
-	 * @access private
42
-	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
43
-	 */
44
-	private $log;
45
-
46
-	/**
47
-	 * The {@link Wordlift_File_Cache_Service} registered instances.
48
-	 *
49
-	 * Each {@link Wordlift_File_Cache_Service} adds itself to the registered
50
-	 * instances.
51
-	 *
52
-	 * @since  3.16.3
53
-	 * @access private
54
-	 * @var array $instances An array of {@link Wordlift_File_Cache_Service} instances.
55
-	 */
56
-	private static $instances = array();
57
-
58
-	private static $instance;
59
-
60
-	/**
61
-	 * Create a {@link Wordlift_File_Cache_Service} instance.
62
-	 *
63
-	 * The File Cache Service requires a base cache directory (to which a unique
64
-	 * id for the current site will be appended) and a file extension for cache
65
-	 * files (by default `.wlcache`) is used.
66
-	 *
67
-	 * @param string $cache_dir The base cache directory.
68
-	 * @param string $file_extension The file extension, by default `.wlcache`.
69
-	 *
70
-	 * @since 3.16.0
71
-	 *
72
-	 */
73
-	public function __construct( $cache_dir, $file_extension = '.wlcache' ) {
74
-
75
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
76
-
77
-		// Set the cache directory using the base directory provided by the caller
78
-		// and appending a hash for the unique site id.
79
-		$this->cache_dir      = trailingslashit( $cache_dir ) . md5( get_site_url() ) . '/';
80
-		$this->file_extension = $file_extension;
81
-
82
-		// Create the cache dir.
83
-		if ( ! file_exists( $this->cache_dir ) ) {
84
-			@mkdir( $this->cache_dir, 0755, true );
85
-		}
86
-
87
-		// Add ourselves to the list of instances.
88
-		self::$instances[] = $this;
89
-
90
-		// Initialize the singleton and the ajax method.
91
-		if ( ! isset( self::$instance ) ) {
92
-			self::$instance = $this;
93
-
94
-			add_action( 'wp_ajax_wl_file_cache__flush_all', array( 'Wordlift_File_Cache_Service', 'flush_all' ) );
95
-		}
96
-
97
-		$this->log->debug( "File Cache service initialized on $this->cache_dir." );
98
-
99
-	}
100
-
101
-	/**
102
-	 * Get the cached response for the specified `id`.
103
-	 *
104
-	 * @param int $id The cache `id`.
105
-	 *
106
-	 * @return mixed|false The cached contents or false if the cache isn't found.
107
-	 * @since 3.16.0
108
-	 *
109
-	 */
110
-	function get_cache( $id ) {
111
-
112
-		// Bail out if we don't have the cache.
113
-		if ( ! $this->has_cache( $id ) ) {
114
-			return false;
115
-		}
116
-
117
-		// Get the filename.
118
-		$filename = $this->get_filename( $id );
119
-
120
-		$this->log->trace( "Trying to get cache contents for $id from $filename..." );
121
-
122
-		// Try to decode the contents.
123
-		$contents = json_decode( file_get_contents( $filename ), true );
124
-
125
-		// Return false if decoding failed, otherwise the decoded contents.
126
-		return $contents ?: false;
127
-	}
128
-
129
-	/**
130
-	 * Set the cache contents for the specified `id`.
131
-	 *
132
-	 * @param int $id The cache id.
133
-	 *
134
-	 * @return bool True if the `id` has a cache.
135
-	 * @since 3.16.0
136
-	 *
137
-	 */
138
-	function has_cache( $id ) {
139
-
140
-		// Get the filename.
141
-		$filename = $this->get_filename( $id );
142
-
143
-		// Bail out if the file doesn't exist.
144
-		return file_exists( $filename );
145
-	}
146
-
147
-	/**
148
-	 * @inheritdoc
149
-	 */
150
-	function set_cache( $id, $contents ) {
151
-
152
-		$filename = $this->get_filename( $id );
153
-
154
-		$this->log->trace( "Writing cache contents for $id to $filename..." );
155
-
156
-		@file_put_contents( $filename, wp_json_encode( $contents ) );
157
-
158
-	}
159
-
160
-	/**
161
-	 * Delete the cache for the specified `id`.
162
-	 *
163
-	 * @param int $id The cache `id`.
164
-	 *
165
-	 * @since 3.16.0
166
-	 *
167
-	 */
168
-	function delete_cache( $id ) {
169
-
170
-		$filename = $this->get_filename( $id );
19
+    /**
20
+     * The cache directory.
21
+     *
22
+     * @since  3.16.0
23
+     * @access private
24
+     * @var string $cache_dir The root cache directory (ending with a trailing slash).
25
+     */
26
+    private $cache_dir;
27
+
28
+    /**
29
+     * The file extension for cache files (e.g. `.wlcache`).
30
+     *
31
+     * @since  3.16.0
32
+     * @access private
33
+     * @var string $file_extension The file extension for cache files (e.g. `.wlcache`).
34
+     */
35
+    private $file_extension;
36
+
37
+    /**
38
+     * A {@link Wordlift_Log_Service} instance.
39
+     *
40
+     * @since  3.16.0
41
+     * @access private
42
+     * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
43
+     */
44
+    private $log;
45
+
46
+    /**
47
+     * The {@link Wordlift_File_Cache_Service} registered instances.
48
+     *
49
+     * Each {@link Wordlift_File_Cache_Service} adds itself to the registered
50
+     * instances.
51
+     *
52
+     * @since  3.16.3
53
+     * @access private
54
+     * @var array $instances An array of {@link Wordlift_File_Cache_Service} instances.
55
+     */
56
+    private static $instances = array();
57
+
58
+    private static $instance;
59
+
60
+    /**
61
+     * Create a {@link Wordlift_File_Cache_Service} instance.
62
+     *
63
+     * The File Cache Service requires a base cache directory (to which a unique
64
+     * id for the current site will be appended) and a file extension for cache
65
+     * files (by default `.wlcache`) is used.
66
+     *
67
+     * @param string $cache_dir The base cache directory.
68
+     * @param string $file_extension The file extension, by default `.wlcache`.
69
+     *
70
+     * @since 3.16.0
71
+     *
72
+     */
73
+    public function __construct( $cache_dir, $file_extension = '.wlcache' ) {
74
+
75
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
76
+
77
+        // Set the cache directory using the base directory provided by the caller
78
+        // and appending a hash for the unique site id.
79
+        $this->cache_dir      = trailingslashit( $cache_dir ) . md5( get_site_url() ) . '/';
80
+        $this->file_extension = $file_extension;
81
+
82
+        // Create the cache dir.
83
+        if ( ! file_exists( $this->cache_dir ) ) {
84
+            @mkdir( $this->cache_dir, 0755, true );
85
+        }
86
+
87
+        // Add ourselves to the list of instances.
88
+        self::$instances[] = $this;
89
+
90
+        // Initialize the singleton and the ajax method.
91
+        if ( ! isset( self::$instance ) ) {
92
+            self::$instance = $this;
93
+
94
+            add_action( 'wp_ajax_wl_file_cache__flush_all', array( 'Wordlift_File_Cache_Service', 'flush_all' ) );
95
+        }
96
+
97
+        $this->log->debug( "File Cache service initialized on $this->cache_dir." );
98
+
99
+    }
100
+
101
+    /**
102
+     * Get the cached response for the specified `id`.
103
+     *
104
+     * @param int $id The cache `id`.
105
+     *
106
+     * @return mixed|false The cached contents or false if the cache isn't found.
107
+     * @since 3.16.0
108
+     *
109
+     */
110
+    function get_cache( $id ) {
111
+
112
+        // Bail out if we don't have the cache.
113
+        if ( ! $this->has_cache( $id ) ) {
114
+            return false;
115
+        }
116
+
117
+        // Get the filename.
118
+        $filename = $this->get_filename( $id );
119
+
120
+        $this->log->trace( "Trying to get cache contents for $id from $filename..." );
121
+
122
+        // Try to decode the contents.
123
+        $contents = json_decode( file_get_contents( $filename ), true );
124
+
125
+        // Return false if decoding failed, otherwise the decoded contents.
126
+        return $contents ?: false;
127
+    }
128
+
129
+    /**
130
+     * Set the cache contents for the specified `id`.
131
+     *
132
+     * @param int $id The cache id.
133
+     *
134
+     * @return bool True if the `id` has a cache.
135
+     * @since 3.16.0
136
+     *
137
+     */
138
+    function has_cache( $id ) {
139
+
140
+        // Get the filename.
141
+        $filename = $this->get_filename( $id );
142
+
143
+        // Bail out if the file doesn't exist.
144
+        return file_exists( $filename );
145
+    }
146
+
147
+    /**
148
+     * @inheritdoc
149
+     */
150
+    function set_cache( $id, $contents ) {
151
+
152
+        $filename = $this->get_filename( $id );
153
+
154
+        $this->log->trace( "Writing cache contents for $id to $filename..." );
155
+
156
+        @file_put_contents( $filename, wp_json_encode( $contents ) );
157
+
158
+    }
159
+
160
+    /**
161
+     * Delete the cache for the specified `id`.
162
+     *
163
+     * @param int $id The cache `id`.
164
+     *
165
+     * @since 3.16.0
166
+     *
167
+     */
168
+    function delete_cache( $id ) {
169
+
170
+        $filename = $this->get_filename( $id );
171 171
 
172
-		$this->log->trace( "Deleting cache contents for $id, file $filename..." );
172
+        $this->log->trace( "Deleting cache contents for $id, file $filename..." );
173 173
 
174
-		if ( file_exists( $filename ) ) {
175
-			@unlink( $filename );
176
-		}
177
-
178
-	}
174
+        if ( file_exists( $filename ) ) {
175
+            @unlink( $filename );
176
+        }
177
+
178
+    }
179 179
 
180
-	/**
181
-	 * Flush the whole cache.
182
-	 *
183
-	 * @since 3.16.0
184
-	 */
185
-	function flush() {
180
+    /**
181
+     * Flush the whole cache.
182
+     *
183
+     * @since 3.16.0
184
+     */
185
+    function flush() {
186 186
 
187
-		// Bail out if the cache dir isn't set.
188
-		if ( empty( $this->cache_dir ) || '/' === $this->cache_dir ) {
189
-			return;
190
-		}
187
+        // Bail out if the cache dir isn't set.
188
+        if ( empty( $this->cache_dir ) || '/' === $this->cache_dir ) {
189
+            return;
190
+        }
191 191
 
192
-		$this->log->trace( "Flushing cache contents from $this->cache_dir..." );
192
+        $this->log->trace( "Flushing cache contents from $this->cache_dir..." );
193 193
 
194
-		$handle = @opendir( $this->cache_dir );
194
+        $handle = @opendir( $this->cache_dir );
195 195
 
196
-		// Bail out if the directory can't be opened.
197
-		if ( false === $handle ) {
198
-			return;
199
-		}
200
-
201
-		// Calculate the file extension length for matching file names.
202
-		$file_extension_length = strlen( $this->file_extension );
203
-
204
-		// Loop into the directory to delete files.
205
-		while ( false !== ( $entry = readdir( $handle ) ) ) {
206
-			if ( substr( $entry, - $file_extension_length ) === $this->file_extension
207
-			     && file_exists( $this->cache_dir . $entry ) ) {
208
-				$this->log->trace( "Deleting file {$this->cache_dir}{$entry}..." );
196
+        // Bail out if the directory can't be opened.
197
+        if ( false === $handle ) {
198
+            return;
199
+        }
200
+
201
+        // Calculate the file extension length for matching file names.
202
+        $file_extension_length = strlen( $this->file_extension );
203
+
204
+        // Loop into the directory to delete files.
205
+        while ( false !== ( $entry = readdir( $handle ) ) ) {
206
+            if ( substr( $entry, - $file_extension_length ) === $this->file_extension
207
+                 && file_exists( $this->cache_dir . $entry ) ) {
208
+                $this->log->trace( "Deleting file {$this->cache_dir}{$entry}..." );
209 209
 
210
-				@unlink( $this->cache_dir . $entry );
211
-			}
212
-		}
210
+                @unlink( $this->cache_dir . $entry );
211
+            }
212
+        }
213 213
 
214
-		// Finally closed the directory.
215
-		closedir( $handle );
214
+        // Finally closed the directory.
215
+        closedir( $handle );
216 216
 
217
-	}
217
+    }
218 218
 
219
-	public static function flush_all() {
219
+    public static function flush_all() {
220 220
 
221
-		foreach ( self::$instances as $instance ) {
222
-			$instance->flush();
223
-		}
221
+        foreach ( self::$instances as $instance ) {
222
+            $instance->flush();
223
+        }
224 224
 
225
-		if ( defined( 'DOING_AJAX' ) && DOING_AJAX
226
-		     && isset( $_REQUEST['action'] ) && 'wl_file_cache__flush_all' === $_REQUEST['action'] ) {
227
-			wp_send_json_success();
228
-		}
229
-
230
-	}
225
+        if ( defined( 'DOING_AJAX' ) && DOING_AJAX
226
+             && isset( $_REQUEST['action'] ) && 'wl_file_cache__flush_all' === $_REQUEST['action'] ) {
227
+            wp_send_json_success();
228
+        }
229
+
230
+    }
231 231
 
232
-	/**
233
-	 * Get the filename holding the cache contents for the specified `id`.
234
-	 *
235
-	 * @param int $id The cache `id`.
236
-	 *
237
-	 * @return string The filename.
238
-	 * @since 3.16.0
239
-	 *
240
-	 */
241
-	private function get_filename( $id ) {
232
+    /**
233
+     * Get the filename holding the cache contents for the specified `id`.
234
+     *
235
+     * @param int $id The cache `id`.
236
+     *
237
+     * @return string The filename.
238
+     * @since 3.16.0
239
+     *
240
+     */
241
+    private function get_filename( $id ) {
242 242
 
243
-		return $this->cache_dir . md5( $id ) . $this->file_extension;
244
-	}
243
+        return $this->cache_dir . md5( $id ) . $this->file_extension;
244
+    }
245 245
 
246 246
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -70,31 +70,31 @@  discard block
 block discarded – undo
70 70
 	 * @since 3.16.0
71 71
 	 *
72 72
 	 */
73
-	public function __construct( $cache_dir, $file_extension = '.wlcache' ) {
73
+	public function __construct($cache_dir, $file_extension = '.wlcache') {
74 74
 
75
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
75
+		$this->log = Wordlift_Log_Service::get_logger(get_class());
76 76
 
77 77
 		// Set the cache directory using the base directory provided by the caller
78 78
 		// and appending a hash for the unique site id.
79
-		$this->cache_dir      = trailingslashit( $cache_dir ) . md5( get_site_url() ) . '/';
79
+		$this->cache_dir      = trailingslashit($cache_dir).md5(get_site_url()).'/';
80 80
 		$this->file_extension = $file_extension;
81 81
 
82 82
 		// Create the cache dir.
83
-		if ( ! file_exists( $this->cache_dir ) ) {
84
-			@mkdir( $this->cache_dir, 0755, true );
83
+		if ( ! file_exists($this->cache_dir)) {
84
+			@mkdir($this->cache_dir, 0755, true);
85 85
 		}
86 86
 
87 87
 		// Add ourselves to the list of instances.
88 88
 		self::$instances[] = $this;
89 89
 
90 90
 		// Initialize the singleton and the ajax method.
91
-		if ( ! isset( self::$instance ) ) {
91
+		if ( ! isset(self::$instance)) {
92 92
 			self::$instance = $this;
93 93
 
94
-			add_action( 'wp_ajax_wl_file_cache__flush_all', array( 'Wordlift_File_Cache_Service', 'flush_all' ) );
94
+			add_action('wp_ajax_wl_file_cache__flush_all', array('Wordlift_File_Cache_Service', 'flush_all'));
95 95
 		}
96 96
 
97
-		$this->log->debug( "File Cache service initialized on $this->cache_dir." );
97
+		$this->log->debug("File Cache service initialized on $this->cache_dir.");
98 98
 
99 99
 	}
100 100
 
@@ -107,20 +107,20 @@  discard block
 block discarded – undo
107 107
 	 * @since 3.16.0
108 108
 	 *
109 109
 	 */
110
-	function get_cache( $id ) {
110
+	function get_cache($id) {
111 111
 
112 112
 		// Bail out if we don't have the cache.
113
-		if ( ! $this->has_cache( $id ) ) {
113
+		if ( ! $this->has_cache($id)) {
114 114
 			return false;
115 115
 		}
116 116
 
117 117
 		// Get the filename.
118
-		$filename = $this->get_filename( $id );
118
+		$filename = $this->get_filename($id);
119 119
 
120
-		$this->log->trace( "Trying to get cache contents for $id from $filename..." );
120
+		$this->log->trace("Trying to get cache contents for $id from $filename...");
121 121
 
122 122
 		// Try to decode the contents.
123
-		$contents = json_decode( file_get_contents( $filename ), true );
123
+		$contents = json_decode(file_get_contents($filename), true);
124 124
 
125 125
 		// Return false if decoding failed, otherwise the decoded contents.
126 126
 		return $contents ?: false;
@@ -135,25 +135,25 @@  discard block
 block discarded – undo
135 135
 	 * @since 3.16.0
136 136
 	 *
137 137
 	 */
138
-	function has_cache( $id ) {
138
+	function has_cache($id) {
139 139
 
140 140
 		// Get the filename.
141
-		$filename = $this->get_filename( $id );
141
+		$filename = $this->get_filename($id);
142 142
 
143 143
 		// Bail out if the file doesn't exist.
144
-		return file_exists( $filename );
144
+		return file_exists($filename);
145 145
 	}
146 146
 
147 147
 	/**
148 148
 	 * @inheritdoc
149 149
 	 */
150
-	function set_cache( $id, $contents ) {
150
+	function set_cache($id, $contents) {
151 151
 
152
-		$filename = $this->get_filename( $id );
152
+		$filename = $this->get_filename($id);
153 153
 
154
-		$this->log->trace( "Writing cache contents for $id to $filename..." );
154
+		$this->log->trace("Writing cache contents for $id to $filename...");
155 155
 
156
-		@file_put_contents( $filename, wp_json_encode( $contents ) );
156
+		@file_put_contents($filename, wp_json_encode($contents));
157 157
 
158 158
 	}
159 159
 
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
 	 * @since 3.16.0
166 166
 	 *
167 167
 	 */
168
-	function delete_cache( $id ) {
168
+	function delete_cache($id) {
169 169
 
170
-		$filename = $this->get_filename( $id );
170
+		$filename = $this->get_filename($id);
171 171
 
172
-		$this->log->trace( "Deleting cache contents for $id, file $filename..." );
172
+		$this->log->trace("Deleting cache contents for $id, file $filename...");
173 173
 
174
-		if ( file_exists( $filename ) ) {
175
-			@unlink( $filename );
174
+		if (file_exists($filename)) {
175
+			@unlink($filename);
176 176
 		}
177 177
 
178 178
 	}
@@ -185,45 +185,45 @@  discard block
 block discarded – undo
185 185
 	function flush() {
186 186
 
187 187
 		// Bail out if the cache dir isn't set.
188
-		if ( empty( $this->cache_dir ) || '/' === $this->cache_dir ) {
188
+		if (empty($this->cache_dir) || '/' === $this->cache_dir) {
189 189
 			return;
190 190
 		}
191 191
 
192
-		$this->log->trace( "Flushing cache contents from $this->cache_dir..." );
192
+		$this->log->trace("Flushing cache contents from $this->cache_dir...");
193 193
 
194
-		$handle = @opendir( $this->cache_dir );
194
+		$handle = @opendir($this->cache_dir);
195 195
 
196 196
 		// Bail out if the directory can't be opened.
197
-		if ( false === $handle ) {
197
+		if (false === $handle) {
198 198
 			return;
199 199
 		}
200 200
 
201 201
 		// Calculate the file extension length for matching file names.
202
-		$file_extension_length = strlen( $this->file_extension );
202
+		$file_extension_length = strlen($this->file_extension);
203 203
 
204 204
 		// Loop into the directory to delete files.
205
-		while ( false !== ( $entry = readdir( $handle ) ) ) {
206
-			if ( substr( $entry, - $file_extension_length ) === $this->file_extension
207
-			     && file_exists( $this->cache_dir . $entry ) ) {
208
-				$this->log->trace( "Deleting file {$this->cache_dir}{$entry}..." );
205
+		while (false !== ($entry = readdir($handle))) {
206
+			if (substr($entry, - $file_extension_length) === $this->file_extension
207
+			     && file_exists($this->cache_dir.$entry)) {
208
+				$this->log->trace("Deleting file {$this->cache_dir}{$entry}...");
209 209
 
210
-				@unlink( $this->cache_dir . $entry );
210
+				@unlink($this->cache_dir.$entry);
211 211
 			}
212 212
 		}
213 213
 
214 214
 		// Finally closed the directory.
215
-		closedir( $handle );
215
+		closedir($handle);
216 216
 
217 217
 	}
218 218
 
219 219
 	public static function flush_all() {
220 220
 
221
-		foreach ( self::$instances as $instance ) {
221
+		foreach (self::$instances as $instance) {
222 222
 			$instance->flush();
223 223
 		}
224 224
 
225
-		if ( defined( 'DOING_AJAX' ) && DOING_AJAX
226
-		     && isset( $_REQUEST['action'] ) && 'wl_file_cache__flush_all' === $_REQUEST['action'] ) {
225
+		if (defined('DOING_AJAX') && DOING_AJAX
226
+		     && isset($_REQUEST['action']) && 'wl_file_cache__flush_all' === $_REQUEST['action']) {
227 227
 			wp_send_json_success();
228 228
 		}
229 229
 
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	 * @since 3.16.0
239 239
 	 *
240 240
 	 */
241
-	private function get_filename( $id ) {
241
+	private function get_filename($id) {
242 242
 
243
-		return $this->cache_dir . md5( $id ) . $this->file_extension;
243
+		return $this->cache_dir.md5($id).$this->file_extension;
244 244
 	}
245 245
 
246 246
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-post-excerpt-helper.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -23,55 +23,55 @@
 block discarded – undo
23 23
  */
24 24
 class Wordlift_Post_Excerpt_Helper {
25 25
 
26
-	/**
27
-	 * Get the text excerpt for the provided {@link WP_Post}.
28
-	 *
29
-	 * Since anyone can hook on the excerpt generation filters, and
30
-	 * amend it with non textual content, we play it self and generate
31
-	 * the excerpt ourselves, mimicking the way wordpress core does it.
32
-	 *
33
-	 * @since 3.10.0
34
-	 *
35
-	 * @param WP_Post $post The {@link WP_Post}.
36
-	 * @param int     $length The desired excerpt length.
37
-	 * @param string  $more The desired more string.
38
-	 *
39
-	 * @return string The excerpt.
40
-	 */
41
-	public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
26
+    /**
27
+     * Get the text excerpt for the provided {@link WP_Post}.
28
+     *
29
+     * Since anyone can hook on the excerpt generation filters, and
30
+     * amend it with non textual content, we play it self and generate
31
+     * the excerpt ourselves, mimicking the way wordpress core does it.
32
+     *
33
+     * @since 3.10.0
34
+     *
35
+     * @param WP_Post $post The {@link WP_Post}.
36
+     * @param int     $length The desired excerpt length.
37
+     * @param string  $more The desired more string.
38
+     *
39
+     * @return string The excerpt.
40
+     */
41
+    public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
42 42
 
43
-		/*
43
+        /*
44 44
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
45 45
 		 * because the content is written elsewhere.
46 46
 		 *
47 47
 		 * @since 3.20.0
48 48
 		 */
49
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
49
+        $post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
50 50
 
51
-		// Filter shortcode content in post_content, before using it for trimming
52
-		$post_content = do_shortcode( $post_content );
51
+        // Filter shortcode content in post_content, before using it for trimming
52
+        $post_content = do_shortcode( $post_content );
53 53
 
54
-		// Get the excerpt and trim it. Use the `post_excerpt` if available.
55
-		$excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
54
+        // Get the excerpt and trim it. Use the `post_excerpt` if available.
55
+        $excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
56 56
 
57
-		// Remove shortcodes and decode html entities.
58
-		return html_entity_decode( self::strip_all_shortcodes( $excerpt ) );
59
-	}
57
+        // Remove shortcodes and decode html entities.
58
+        return html_entity_decode( self::strip_all_shortcodes( $excerpt ) );
59
+    }
60 60
 
61
-	/**
62
-	 * Remove all the shortcodes from the content. We're using our own function
63
-	 * because WordPress' own `strip_shortcodes` only takes into consideration
64
-	 * shortcodes for installed plugins/themes.
65
-	 *
66
-	 * @since 3.12.0
67
-	 *
68
-	 * @param string $content The content with shortcodes.
69
-	 *
70
-	 * @return string The content without shortcodes.
71
-	 */
72
-	private static function strip_all_shortcodes( $content ) {
61
+    /**
62
+     * Remove all the shortcodes from the content. We're using our own function
63
+     * because WordPress' own `strip_shortcodes` only takes into consideration
64
+     * shortcodes for installed plugins/themes.
65
+     *
66
+     * @since 3.12.0
67
+     *
68
+     * @param string $content The content with shortcodes.
69
+     *
70
+     * @return string The content without shortcodes.
71
+     */
72
+    private static function strip_all_shortcodes( $content ) {
73 73
 
74
-		return preg_replace( '/\[[^]]+\]/', '', $content );
75
-	}
74
+        return preg_replace( '/\[[^]]+\]/', '', $content );
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @return string The excerpt.
40 40
 	 */
41
-	public static function get_text_excerpt( $post, $length = 55, $more = '...' ) {
41
+	public static function get_text_excerpt($post, $length = 55, $more = '...') {
42 42
 
43 43
 		/*
44 44
 		 * Apply the `wl_post_content` filter, in case 3rd parties want to change the post content, e.g.
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
 		 *
47 47
 		 * @since 3.20.0
48 48
 		 */
49
-		$post_content = apply_filters( 'wl_post_content', $post->post_content, $post );
49
+		$post_content = apply_filters('wl_post_content', $post->post_content, $post);
50 50
 
51 51
 		// Filter shortcode content in post_content, before using it for trimming
52
-		$post_content = do_shortcode( $post_content );
52
+		$post_content = do_shortcode($post_content);
53 53
 
54 54
 		// Get the excerpt and trim it. Use the `post_excerpt` if available.
55
-		$excerpt = wp_trim_words( ! empty( $post->post_excerpt ) ? $post->post_excerpt : $post_content, $length, $more );
55
+		$excerpt = wp_trim_words( ! empty($post->post_excerpt) ? $post->post_excerpt : $post_content, $length, $more);
56 56
 
57 57
 		// Remove shortcodes and decode html entities.
58
-		return html_entity_decode( self::strip_all_shortcodes( $excerpt ) );
58
+		return html_entity_decode(self::strip_all_shortcodes($excerpt));
59 59
 	}
60 60
 
61 61
 	/**
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string The content without shortcodes.
71 71
 	 */
72
-	private static function strip_all_shortcodes( $content ) {
72
+	private static function strip_all_shortcodes($content) {
73 73
 
74
-		return preg_replace( '/\[[^]]+\]/', '', $content );
74
+		return preg_replace('/\[[^]]+\]/', '', $content);
75 75
 	}
76 76
 
77 77
 }
Please login to merge, or discard this patch.
src/wordlift/autocomplete/class-autocomplete-service.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,15 +11,15 @@
 block discarded – undo
11 11
 
12 12
 interface Autocomplete_Service {
13 13
 
14
-	/**
15
-	 * Query the service for the specified data.
16
-	 *
17
-	 * @param string $query The query.
18
-	 * @param string $scope The scope.
19
-	 * @param string|string[] $excludes URLs to exclude.
20
-	 *
21
-	 * @return array An array of results.
22
-	 */
23
-	public function query( $query, $scope, $excludes );
14
+    /**
15
+     * Query the service for the specified data.
16
+     *
17
+     * @param string $query The query.
18
+     * @param string $scope The scope.
19
+     * @param string|string[] $excludes URLs to exclude.
20
+     *
21
+     * @return array An array of results.
22
+     */
23
+    public function query( $query, $scope, $excludes );
24 24
 
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,6 +20,6 @@
 block discarded – undo
20 20
 	 *
21 21
 	 * @return array An array of results.
22 22
 	 */
23
-	public function query( $query, $scope, $excludes );
23
+	public function query($query, $scope, $excludes);
24 24
 
25 25
 }
Please login to merge, or discard this patch.
src/install/class-wordlift-install-all-entity-types.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -17,49 +17,49 @@
 block discarded – undo
17 17
  */
18 18
 class Wordlift_Install_All_Entity_Types extends Wordlift_Install {
19 19
 
20
-	/**
21
-	 * The option name for the version of the Schema.org taxonomy.
22
-	 *
23
-	 * @since 3.20.0
24
-	 */
25
-	const OPTION_NAME = 'wl_schemaorg_version';
20
+    /**
21
+     * The option name for the version of the Schema.org taxonomy.
22
+     *
23
+     * @since 3.20.0
24
+     */
25
+    const OPTION_NAME = 'wl_schemaorg_version';
26 26
 
27
-	/**
28
-	 * {@inheritdoc}
29
-	 */
30
-	protected static $version = '3.20.0';
27
+    /**
28
+     * {@inheritdoc}
29
+     */
30
+    protected static $version = '3.20.0';
31 31
 
32
-	/**
33
-	 * Perform the installation.
34
-	 *
35
-	 * @since 3.20.0
36
-	 */
37
-	public function install() {
32
+    /**
33
+     * Perform the installation.
34
+     *
35
+     * @since 3.20.0
36
+     */
37
+    public function install() {
38 38
 
39
-		$this->log->info( 'Installing `All Entity Types` configuration...' );
39
+        $this->log->info( 'Installing `All Entity Types` configuration...' );
40 40
 
41
-		// Get the Schema.org sync service instance.
42
-		$schema_sync_service = Wordlift_Schemaorg_Sync_Service::get_instance();
41
+        // Get the Schema.org sync service instance.
42
+        $schema_sync_service = Wordlift_Schemaorg_Sync_Service::get_instance();
43 43
 
44
-		// Try to load the Schema.org taxonomy and, if successful, update the local Schema.org version.
45
-		if ( $schema_sync_service->load_from_file() ) {
46
-			$this->log->debug( 'Updating `All Entity Types` configuration to 1.0.0.' );
44
+        // Try to load the Schema.org taxonomy and, if successful, update the local Schema.org version.
45
+        if ( $schema_sync_service->load_from_file() ) {
46
+            $this->log->debug( 'Updating `All Entity Types` configuration to 1.0.0.' );
47 47
 
48
-			update_option( self::OPTION_NAME, '1.0.0', true );
49
-		}
48
+            update_option( self::OPTION_NAME, '1.0.0', true );
49
+        }
50 50
 
51
-	}
51
+    }
52 52
 
53
-	/**
54
-	 * Whether the installation procedure must run.
55
-	 *
56
-	 * @since 3.20.0
57
-	 *
58
-	 * @return bool True if the installation procedure must run otherwise false.
59
-	 */
60
-	public function must_install() {
53
+    /**
54
+     * Whether the installation procedure must run.
55
+     *
56
+     * @since 3.20.0
57
+     *
58
+     * @return bool True if the installation procedure must run otherwise false.
59
+     */
60
+    public function must_install() {
61 61
 
62
-		return WL_ALL_ENTITY_TYPES && version_compare( '1.0.0', get_option( self::OPTION_NAME, '0.0.0' ), '>' );
63
-	}
62
+        return WL_ALL_ENTITY_TYPES && version_compare( '1.0.0', get_option( self::OPTION_NAME, '0.0.0' ), '>' );
63
+    }
64 64
 
65 65
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,16 +36,16 @@  discard block
 block discarded – undo
36 36
 	 */
37 37
 	public function install() {
38 38
 
39
-		$this->log->info( 'Installing `All Entity Types` configuration...' );
39
+		$this->log->info('Installing `All Entity Types` configuration...');
40 40
 
41 41
 		// Get the Schema.org sync service instance.
42 42
 		$schema_sync_service = Wordlift_Schemaorg_Sync_Service::get_instance();
43 43
 
44 44
 		// Try to load the Schema.org taxonomy and, if successful, update the local Schema.org version.
45
-		if ( $schema_sync_service->load_from_file() ) {
46
-			$this->log->debug( 'Updating `All Entity Types` configuration to 1.0.0.' );
45
+		if ($schema_sync_service->load_from_file()) {
46
+			$this->log->debug('Updating `All Entity Types` configuration to 1.0.0.');
47 47
 
48
-			update_option( self::OPTION_NAME, '1.0.0', true );
48
+			update_option(self::OPTION_NAME, '1.0.0', true);
49 49
 		}
50 50
 
51 51
 	}
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function must_install() {
61 61
 
62
-		return WL_ALL_ENTITY_TYPES && version_compare( '1.0.0', get_option( self::OPTION_NAME, '0.0.0' ), '>' );
62
+		return WL_ALL_ENTITY_TYPES && version_compare('1.0.0', get_option(self::OPTION_NAME, '0.0.0'), '>');
63 63
 	}
64 64
 
65 65
 }
Please login to merge, or discard this patch.