Passed
Push — master ( a1ed1d...263a69 )
by John
16:05 queued 13s
created
core/Data/LoginFlowV2Credentials.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -25,47 +25,47 @@
 block discarded – undo
25 25
 namespace OC\Core\Data;
26 26
 
27 27
 class LoginFlowV2Credentials implements \JsonSerializable {
28
-	/** @var string */
29
-	private $server;
30
-	/** @var string */
31
-	private $loginName;
32
-	/** @var string */
33
-	private $appPassword;
28
+    /** @var string */
29
+    private $server;
30
+    /** @var string */
31
+    private $loginName;
32
+    /** @var string */
33
+    private $appPassword;
34 34
 
35
-	public function __construct(string $server, string $loginName, string $appPassword) {
36
-		$this->server = $server;
37
-		$this->loginName = $loginName;
38
-		$this->appPassword = $appPassword;
39
-	}
35
+    public function __construct(string $server, string $loginName, string $appPassword) {
36
+        $this->server = $server;
37
+        $this->loginName = $loginName;
38
+        $this->appPassword = $appPassword;
39
+    }
40 40
 
41
-	/**
42
-	 * @return string
43
-	 */
44
-	public function getServer(): string {
45
-		return $this->server;
46
-	}
41
+    /**
42
+     * @return string
43
+     */
44
+    public function getServer(): string {
45
+        return $this->server;
46
+    }
47 47
 
48
-	/**
49
-	 * @return string
50
-	 */
51
-	public function getLoginName(): string {
52
-		return $this->loginName;
53
-	}
48
+    /**
49
+     * @return string
50
+     */
51
+    public function getLoginName(): string {
52
+        return $this->loginName;
53
+    }
54 54
 
55
-	/**
56
-	 * @return string
57
-	 */
58
-	public function getAppPassword(): string {
59
-		return $this->appPassword;
60
-	}
55
+    /**
56
+     * @return string
57
+     */
58
+    public function getAppPassword(): string {
59
+        return $this->appPassword;
60
+    }
61 61
 
62
-	public function jsonSerialize(): array {
63
-		return [
64
-			'server' => $this->server,
65
-			'loginName' => $this->loginName,
66
-			'appPassword' => $this->appPassword,
67
-		];
68
-	}
62
+    public function jsonSerialize(): array {
63
+        return [
64
+            'server' => $this->server,
65
+            'loginName' => $this->loginName,
66
+            'appPassword' => $this->appPassword,
67
+        ];
68
+    }
69 69
 
70 70
 
71 71
 }
Please login to merge, or discard this patch.
core/Service/LoginFlowV2Service.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 
212 212
 	private function hashToken(string $token): string {
213 213
 		$secret = $this->config->getSystemValue('secret');
214
-		return hash('sha512', $token . $secret);
214
+		return hash('sha512', $token.$secret);
215 215
 	}
216 216
 
217 217
 	private function getKeyPair(): array {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		while ($error = openssl_error_string()) {
242 242
 			$errors[] = $error;
243 243
 		}
244
-		$this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
244
+		$this->logger->critical('Something is wrong with your openssl setup: '.implode(', ', $errors));
245 245
 	}
246 246
 
247 247
 	private function encryptPassword(string $password, string $publicKey): string {
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -43,228 +43,228 @@
 block discarded – undo
43 43
 use Psr\Log\LoggerInterface;
44 44
 
45 45
 class LoginFlowV2Service {
46
-	private LoginFlowV2Mapper $mapper;
47
-	private ISecureRandom $random;
48
-	private ITimeFactory $time;
49
-	private IConfig $config;
50
-	private ICrypto $crypto;
51
-	private LoggerInterface $logger;
52
-	private IProvider $tokenProvider;
53
-
54
-	public function __construct(LoginFlowV2Mapper $mapper,
55
-								ISecureRandom $random,
56
-								ITimeFactory $time,
57
-								IConfig $config,
58
-								ICrypto $crypto,
59
-								LoggerInterface $logger,
60
-								IProvider $tokenProvider) {
61
-		$this->mapper = $mapper;
62
-		$this->random = $random;
63
-		$this->time = $time;
64
-		$this->config = $config;
65
-		$this->crypto = $crypto;
66
-		$this->logger = $logger;
67
-		$this->tokenProvider = $tokenProvider;
68
-	}
69
-
70
-	/**
71
-	 * @param string $pollToken
72
-	 * @return LoginFlowV2Credentials
73
-	 * @throws LoginFlowV2NotFoundException
74
-	 */
75
-	public function poll(string $pollToken): LoginFlowV2Credentials {
76
-		try {
77
-			$data = $this->mapper->getByPollToken($this->hashToken($pollToken));
78
-		} catch (DoesNotExistException $e) {
79
-			throw new LoginFlowV2NotFoundException('Invalid token');
80
-		}
81
-
82
-		$loginName = $data->getLoginName();
83
-		$server = $data->getServer();
84
-		$appPassword = $data->getAppPassword();
85
-
86
-		if ($loginName === null || $server === null || $appPassword === null) {
87
-			throw new LoginFlowV2NotFoundException('Token not yet ready');
88
-		}
89
-
90
-		// Remove the data from the DB
91
-		$this->mapper->delete($data);
92
-
93
-		try {
94
-			// Decrypt the apptoken
95
-			$privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken);
96
-			$appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey);
97
-		} catch (\Exception $e) {
98
-			throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted');
99
-		}
100
-
101
-		return new LoginFlowV2Credentials($server, $loginName, $appPassword);
102
-	}
103
-
104
-	/**
105
-	 * @param string $loginToken
106
-	 * @return LoginFlowV2
107
-	 * @throws LoginFlowV2NotFoundException
108
-	 */
109
-	public function getByLoginToken(string $loginToken): LoginFlowV2 {
110
-		try {
111
-			return $this->mapper->getByLoginToken($loginToken);
112
-		} catch (DoesNotExistException $e) {
113
-			throw new LoginFlowV2NotFoundException('Login token invalid');
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @param string $loginToken
119
-	 * @return bool returns true if the start was successfull. False if not.
120
-	 */
121
-	public function startLoginFlow(string $loginToken): bool {
122
-		try {
123
-			$data = $this->mapper->getByLoginToken($loginToken);
124
-		} catch (DoesNotExistException $e) {
125
-			return false;
126
-		}
127
-
128
-		$data->setStarted(1);
129
-		$this->mapper->update($data);
130
-
131
-		return true;
132
-	}
133
-
134
-	/**
135
-	 * @param string $loginToken
136
-	 * @param string $sessionId
137
-	 * @param string $server
138
-	 * @param string $userId
139
-	 * @return bool true if the flow was successfully completed false otherwise
140
-	 */
141
-	public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool {
142
-		try {
143
-			$data = $this->mapper->getByLoginToken($loginToken);
144
-		} catch (DoesNotExistException $e) {
145
-			return false;
146
-		}
147
-
148
-		try {
149
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
150
-			$loginName = $sessionToken->getLoginName();
151
-			try {
152
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
153
-			} catch (PasswordlessTokenException $ex) {
154
-				$password = null;
155
-			}
156
-		} catch (InvalidTokenException $ex) {
157
-			return false;
158
-		}
159
-
160
-		$appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
161
-		$this->tokenProvider->generateToken(
162
-			$appPassword,
163
-			$userId,
164
-			$loginName,
165
-			$password,
166
-			$data->getClientName(),
167
-			IToken::PERMANENT_TOKEN,
168
-			IToken::DO_NOT_REMEMBER
169
-		);
170
-
171
-		$data->setLoginName($loginName);
172
-		$data->setServer($server);
173
-
174
-		// Properly encrypt
175
-		$data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
176
-
177
-		$this->mapper->update($data);
178
-		return true;
179
-	}
180
-
181
-	public function flowDoneWithAppPassword(string $loginToken, string $server, string $loginName, string $appPassword): bool {
182
-		try {
183
-			$data = $this->mapper->getByLoginToken($loginToken);
184
-		} catch (DoesNotExistException $e) {
185
-			return false;
186
-		}
187
-
188
-		$data->setLoginName($loginName);
189
-		$data->setServer($server);
190
-
191
-		// Properly encrypt
192
-		$data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
193
-
194
-		$this->mapper->update($data);
195
-		return true;
196
-	}
197
-
198
-	public function createTokens(string $userAgent): LoginFlowV2Tokens {
199
-		$flow = new LoginFlowV2();
200
-		$pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
201
-		$loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
202
-		$flow->setPollToken($this->hashToken($pollToken));
203
-		$flow->setLoginToken($loginToken);
204
-		$flow->setStarted(0);
205
-		$flow->setTimestamp($this->time->getTime());
206
-		$flow->setClientName($userAgent);
207
-
208
-		[$publicKey, $privateKey] = $this->getKeyPair();
209
-		$privateKey = $this->crypto->encrypt($privateKey, $pollToken);
210
-
211
-		$flow->setPublicKey($publicKey);
212
-		$flow->setPrivateKey($privateKey);
213
-
214
-		$this->mapper->insert($flow);
215
-
216
-		return new LoginFlowV2Tokens($loginToken, $pollToken);
217
-	}
218
-
219
-	private function hashToken(string $token): string {
220
-		$secret = $this->config->getSystemValue('secret');
221
-		return hash('sha512', $token . $secret);
222
-	}
223
-
224
-	private function getKeyPair(): array {
225
-		$config = array_merge([
226
-			'digest_alg' => 'sha512',
227
-			'private_key_bits' => 2048,
228
-		], $this->config->getSystemValue('openssl', []));
229
-
230
-		// Generate new key
231
-		$res = openssl_pkey_new($config);
232
-		if ($res === false) {
233
-			$this->logOpensslError();
234
-			throw new \RuntimeException('Could not initialize keys');
235
-		}
236
-
237
-		if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
238
-			$this->logOpensslError();
239
-			throw new \RuntimeException('OpenSSL reported a problem');
240
-		}
241
-
242
-		// Extract the public key from $res to $pubKey
243
-		$publicKey = openssl_pkey_get_details($res);
244
-		$publicKey = $publicKey['key'];
245
-
246
-		return [$publicKey, $privateKey];
247
-	}
248
-
249
-	private function logOpensslError(): void {
250
-		$errors = [];
251
-		while ($error = openssl_error_string()) {
252
-			$errors[] = $error;
253
-		}
254
-		$this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
255
-	}
256
-
257
-	private function encryptPassword(string $password, string $publicKey): string {
258
-		openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
259
-		$encryptedPassword = base64_encode($encryptedPassword);
260
-
261
-		return $encryptedPassword;
262
-	}
263
-
264
-	private function decryptPassword(string $encryptedPassword, string $privateKey): string {
265
-		$encryptedPassword = base64_decode($encryptedPassword);
266
-		openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
267
-
268
-		return $password;
269
-	}
46
+    private LoginFlowV2Mapper $mapper;
47
+    private ISecureRandom $random;
48
+    private ITimeFactory $time;
49
+    private IConfig $config;
50
+    private ICrypto $crypto;
51
+    private LoggerInterface $logger;
52
+    private IProvider $tokenProvider;
53
+
54
+    public function __construct(LoginFlowV2Mapper $mapper,
55
+                                ISecureRandom $random,
56
+                                ITimeFactory $time,
57
+                                IConfig $config,
58
+                                ICrypto $crypto,
59
+                                LoggerInterface $logger,
60
+                                IProvider $tokenProvider) {
61
+        $this->mapper = $mapper;
62
+        $this->random = $random;
63
+        $this->time = $time;
64
+        $this->config = $config;
65
+        $this->crypto = $crypto;
66
+        $this->logger = $logger;
67
+        $this->tokenProvider = $tokenProvider;
68
+    }
69
+
70
+    /**
71
+     * @param string $pollToken
72
+     * @return LoginFlowV2Credentials
73
+     * @throws LoginFlowV2NotFoundException
74
+     */
75
+    public function poll(string $pollToken): LoginFlowV2Credentials {
76
+        try {
77
+            $data = $this->mapper->getByPollToken($this->hashToken($pollToken));
78
+        } catch (DoesNotExistException $e) {
79
+            throw new LoginFlowV2NotFoundException('Invalid token');
80
+        }
81
+
82
+        $loginName = $data->getLoginName();
83
+        $server = $data->getServer();
84
+        $appPassword = $data->getAppPassword();
85
+
86
+        if ($loginName === null || $server === null || $appPassword === null) {
87
+            throw new LoginFlowV2NotFoundException('Token not yet ready');
88
+        }
89
+
90
+        // Remove the data from the DB
91
+        $this->mapper->delete($data);
92
+
93
+        try {
94
+            // Decrypt the apptoken
95
+            $privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken);
96
+            $appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey);
97
+        } catch (\Exception $e) {
98
+            throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted');
99
+        }
100
+
101
+        return new LoginFlowV2Credentials($server, $loginName, $appPassword);
102
+    }
103
+
104
+    /**
105
+     * @param string $loginToken
106
+     * @return LoginFlowV2
107
+     * @throws LoginFlowV2NotFoundException
108
+     */
109
+    public function getByLoginToken(string $loginToken): LoginFlowV2 {
110
+        try {
111
+            return $this->mapper->getByLoginToken($loginToken);
112
+        } catch (DoesNotExistException $e) {
113
+            throw new LoginFlowV2NotFoundException('Login token invalid');
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @param string $loginToken
119
+     * @return bool returns true if the start was successfull. False if not.
120
+     */
121
+    public function startLoginFlow(string $loginToken): bool {
122
+        try {
123
+            $data = $this->mapper->getByLoginToken($loginToken);
124
+        } catch (DoesNotExistException $e) {
125
+            return false;
126
+        }
127
+
128
+        $data->setStarted(1);
129
+        $this->mapper->update($data);
130
+
131
+        return true;
132
+    }
133
+
134
+    /**
135
+     * @param string $loginToken
136
+     * @param string $sessionId
137
+     * @param string $server
138
+     * @param string $userId
139
+     * @return bool true if the flow was successfully completed false otherwise
140
+     */
141
+    public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool {
142
+        try {
143
+            $data = $this->mapper->getByLoginToken($loginToken);
144
+        } catch (DoesNotExistException $e) {
145
+            return false;
146
+        }
147
+
148
+        try {
149
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
150
+            $loginName = $sessionToken->getLoginName();
151
+            try {
152
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
153
+            } catch (PasswordlessTokenException $ex) {
154
+                $password = null;
155
+            }
156
+        } catch (InvalidTokenException $ex) {
157
+            return false;
158
+        }
159
+
160
+        $appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
161
+        $this->tokenProvider->generateToken(
162
+            $appPassword,
163
+            $userId,
164
+            $loginName,
165
+            $password,
166
+            $data->getClientName(),
167
+            IToken::PERMANENT_TOKEN,
168
+            IToken::DO_NOT_REMEMBER
169
+        );
170
+
171
+        $data->setLoginName($loginName);
172
+        $data->setServer($server);
173
+
174
+        // Properly encrypt
175
+        $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
176
+
177
+        $this->mapper->update($data);
178
+        return true;
179
+    }
180
+
181
+    public function flowDoneWithAppPassword(string $loginToken, string $server, string $loginName, string $appPassword): bool {
182
+        try {
183
+            $data = $this->mapper->getByLoginToken($loginToken);
184
+        } catch (DoesNotExistException $e) {
185
+            return false;
186
+        }
187
+
188
+        $data->setLoginName($loginName);
189
+        $data->setServer($server);
190
+
191
+        // Properly encrypt
192
+        $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
193
+
194
+        $this->mapper->update($data);
195
+        return true;
196
+    }
197
+
198
+    public function createTokens(string $userAgent): LoginFlowV2Tokens {
199
+        $flow = new LoginFlowV2();
200
+        $pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
201
+        $loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
202
+        $flow->setPollToken($this->hashToken($pollToken));
203
+        $flow->setLoginToken($loginToken);
204
+        $flow->setStarted(0);
205
+        $flow->setTimestamp($this->time->getTime());
206
+        $flow->setClientName($userAgent);
207
+
208
+        [$publicKey, $privateKey] = $this->getKeyPair();
209
+        $privateKey = $this->crypto->encrypt($privateKey, $pollToken);
210
+
211
+        $flow->setPublicKey($publicKey);
212
+        $flow->setPrivateKey($privateKey);
213
+
214
+        $this->mapper->insert($flow);
215
+
216
+        return new LoginFlowV2Tokens($loginToken, $pollToken);
217
+    }
218
+
219
+    private function hashToken(string $token): string {
220
+        $secret = $this->config->getSystemValue('secret');
221
+        return hash('sha512', $token . $secret);
222
+    }
223
+
224
+    private function getKeyPair(): array {
225
+        $config = array_merge([
226
+            'digest_alg' => 'sha512',
227
+            'private_key_bits' => 2048,
228
+        ], $this->config->getSystemValue('openssl', []));
229
+
230
+        // Generate new key
231
+        $res = openssl_pkey_new($config);
232
+        if ($res === false) {
233
+            $this->logOpensslError();
234
+            throw new \RuntimeException('Could not initialize keys');
235
+        }
236
+
237
+        if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
238
+            $this->logOpensslError();
239
+            throw new \RuntimeException('OpenSSL reported a problem');
240
+        }
241
+
242
+        // Extract the public key from $res to $pubKey
243
+        $publicKey = openssl_pkey_get_details($res);
244
+        $publicKey = $publicKey['key'];
245
+
246
+        return [$publicKey, $privateKey];
247
+    }
248
+
249
+    private function logOpensslError(): void {
250
+        $errors = [];
251
+        while ($error = openssl_error_string()) {
252
+            $errors[] = $error;
253
+        }
254
+        $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
255
+    }
256
+
257
+    private function encryptPassword(string $password, string $publicKey): string {
258
+        openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
259
+        $encryptedPassword = base64_encode($encryptedPassword);
260
+
261
+        return $encryptedPassword;
262
+    }
263
+
264
+    private function decryptPassword(string $encryptedPassword, string $privateKey): string {
265
+        $encryptedPassword = base64_decode($encryptedPassword);
266
+        openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
267
+
268
+        return $password;
269
+    }
270 270
 }
Please login to merge, or discard this patch.
core/Db/LoginFlowV2.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -49,37 +49,37 @@
 block discarded – undo
49 49
  * @method void setAppPassword(string $appPassword)
50 50
  */
51 51
 class LoginFlowV2 extends Entity {
52
-	/** @var int */
53
-	protected $timestamp;
54
-	/** @var int */
55
-	protected $started;
56
-	/** @var string */
57
-	protected $pollToken;
58
-	/** @var string */
59
-	protected $loginToken;
60
-	/** @var string */
61
-	protected $publicKey;
62
-	/** @var string */
63
-	protected $privateKey;
64
-	/** @var string */
65
-	protected $clientName;
66
-	/** @var string */
67
-	protected $loginName;
68
-	/** @var string */
69
-	protected $server;
70
-	/** @var string */
71
-	protected $appPassword;
52
+    /** @var int */
53
+    protected $timestamp;
54
+    /** @var int */
55
+    protected $started;
56
+    /** @var string */
57
+    protected $pollToken;
58
+    /** @var string */
59
+    protected $loginToken;
60
+    /** @var string */
61
+    protected $publicKey;
62
+    /** @var string */
63
+    protected $privateKey;
64
+    /** @var string */
65
+    protected $clientName;
66
+    /** @var string */
67
+    protected $loginName;
68
+    /** @var string */
69
+    protected $server;
70
+    /** @var string */
71
+    protected $appPassword;
72 72
 
73
-	public function __construct() {
74
-		$this->addType('timestamp', 'int');
75
-		$this->addType('started', 'int');
76
-		$this->addType('pollToken', 'string');
77
-		$this->addType('loginToken', 'string');
78
-		$this->addType('publicKey', 'string');
79
-		$this->addType('privateKey', 'string');
80
-		$this->addType('clientName', 'string');
81
-		$this->addType('loginName', 'string');
82
-		$this->addType('server', 'string');
83
-		$this->addType('appPassword', 'string');
84
-	}
73
+    public function __construct() {
74
+        $this->addType('timestamp', 'int');
75
+        $this->addType('started', 'int');
76
+        $this->addType('pollToken', 'string');
77
+        $this->addType('loginToken', 'string');
78
+        $this->addType('publicKey', 'string');
79
+        $this->addType('privateKey', 'string');
80
+        $this->addType('clientName', 'string');
81
+        $this->addType('loginName', 'string');
82
+        $this->addType('server', 'string');
83
+        $this->addType('appPassword', 'string');
84
+    }
85 85
 }
Please login to merge, or discard this patch.
lib/public/Group/Backend/IHideFromCollaborationBackend.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@
 block discarded – undo
27 27
  * Allow the backend to mark groups to be excluded from being shown in search dialogs
28 28
  */
29 29
 interface IHideFromCollaborationBackend {
30
-	/**
31
-	 * Check if a group should be hidden from search dialogs
32
-	 *
33
-	 * @param string $groupId
34
-	 * @return bool
35
-	 * @since 16.0.0
36
-	 */
37
-	public function hideGroup(string $groupId): bool;
30
+    /**
31
+     * Check if a group should be hidden from search dialogs
32
+     *
33
+     * @param string $groupId
34
+     * @return bool
35
+     * @since 16.0.0
36
+     */
37
+    public function hideGroup(string $groupId): bool;
38 38
 }
Please login to merge, or discard this patch.
lib/private/FullTextSearch/Model/IndexDocument.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -389,7 +389,7 @@
 block discarded – undo
389 389
 		foreach ($ak as $source) {
390 390
 			$tags = $this->subTags[$source];
391 391
 			foreach ($tags as $tag) {
392
-				$subTags[] = $source . '_' . $tag;
392
+				$subTags[] = $source.'_'.$tag;
393 393
 			}
394 394
 		}
395 395
 
Please login to merge, or discard this patch.
Indentation   +934 added lines, -934 removed lines patch added patch discarded remove patch
@@ -47,940 +47,940 @@
 block discarded – undo
47 47
  * @package OC\FullTextSearch\Model
48 48
  */
49 49
 class IndexDocument implements IIndexDocument, JsonSerializable {
50
-	/** @var string */
51
-	protected $id = '';
50
+    /** @var string */
51
+    protected $id = '';
52 52
 
53
-	/** @var string */
54
-	protected $providerId = '';
53
+    /** @var string */
54
+    protected $providerId = '';
55 55
 
56
-	/** @var DocumentAccess */
57
-	protected $access;
58
-
59
-	/** @var IIndex */
60
-	protected $index;
61
-
62
-	/** @var int */
63
-	protected $modifiedTime = 0;
64
-
65
-	/** @var string */
66
-	protected $source = '';
67
-
68
-	/** @var array */
69
-	protected $tags = [];
70
-
71
-	/** @var array */
72
-	protected $metaTags = [];
73
-
74
-	/** @var array */
75
-	protected $subTags = [];
76
-
77
-	/** @var string */
78
-	protected $title = '';
79
-
80
-	/** @var string */
81
-	protected $content = '';
82
-
83
-	/** @var string */
84
-	protected $hash = '';
85
-
86
-	/** @var array */
87
-	protected $parts = [];
88
-
89
-	/** @var string */
90
-	protected $link = '';
91
-
92
-	/** @var array */
93
-	protected $more = [];
94
-
95
-	/** @var array */
96
-	protected $excerpts = [];
97
-
98
-	/** @var string */
99
-	protected $score = '';
100
-
101
-	/** @var array */
102
-	protected $info = [];
103
-
104
-	/** @var int */
105
-	protected $contentEncoded = 0;
106
-
107
-
108
-	/**
109
-	 * IIndexDocument constructor.
110
-	 *
111
-	 * On creation, we assure the uniqueness of the object using the providerId
112
-	 * and the Id of the original document.
113
-	 *
114
-	 * @since 15.0.0
115
-	 *
116
-	 * @param string $providerId
117
-	 * @param string $documentId
118
-	 */
119
-	public function __construct(string $providerId, string $documentId) {
120
-		$this->providerId = $providerId;
121
-		$this->id = $documentId;
122
-	}
123
-
124
-
125
-	/**
126
-	 * Returns the Id of the original document.
127
-	 *
128
-	 * @since 15.0.0
129
-	 *
130
-	 * @return string
131
-	 */
132
-	final public function getId(): string {
133
-		return $this->id;
134
-	}
135
-
136
-
137
-	/**
138
-	 * Returns the Id of the provider.
139
-	 *
140
-	 * @since 15.0.0
141
-	 *
142
-	 * @return string
143
-	 */
144
-	final public function getProviderId(): string {
145
-		return $this->providerId;
146
-	}
147
-
148
-
149
-	/**
150
-	 * Set the Index related to the IIndexDocument.
151
-	 *
152
-	 * @see IIndex
153
-	 *
154
-	 * @since 15.0.0
155
-	 *
156
-	 * @param IIndex $index
157
-	 *
158
-	 * @return IIndexDocument
159
-	 */
160
-	final public function setIndex(IIndex $index): IIndexDocument {
161
-		$this->index = $index;
162
-
163
-		return $this;
164
-	}
165
-
166
-	/**
167
-	 * Get the Index.
168
-	 *
169
-	 * @since 15.0.0
170
-	 *
171
-	 * @return IIndex
172
-	 */
173
-	final public function getIndex(): IIndex {
174
-		return $this->index;
175
-	}
176
-
177
-	/**
178
-	 * return if Index is defined.
179
-	 *
180
-	 * @since 16.0.0
181
-	 *
182
-	 * @return bool
183
-	 */
184
-	final public function hasIndex(): bool {
185
-		return ($this->index !== null);
186
-	}
187
-
188
-
189
-	/**
190
-	 * Set the modified time of the original document.
191
-	 *
192
-	 * @since 15.0.0
193
-	 *
194
-	 * @param int $modifiedTime
195
-	 *
196
-	 * @return IIndexDocument
197
-	 */
198
-	final public function setModifiedTime(int $modifiedTime): IIndexDocument {
199
-		$this->modifiedTime = $modifiedTime;
200
-
201
-		return $this;
202
-	}
203
-
204
-	/**
205
-	 * Get the modified time of the original document.
206
-	 *
207
-	 * @since 15.0.0
208
-	 *
209
-	 * @return int
210
-	 */
211
-	final public function getModifiedTime(): int {
212
-		return $this->modifiedTime;
213
-	}
214
-
215
-	/**
216
-	 * Check if the original document of the IIndexDocument is older than $time.
217
-	 *
218
-	 * @since 15.0.0
219
-	 *
220
-	 * @param int $time
221
-	 *
222
-	 * @return bool
223
-	 */
224
-	final public function isOlderThan(int $time): bool {
225
-		return ($this->modifiedTime < $time);
226
-	}
227
-
228
-
229
-	/**
230
-	 * Set the read rights of the original document using a IDocumentAccess.
231
-	 *
232
-	 * @see IDocumentAccess
233
-	 *
234
-	 * @since 15.0.0
235
-	 *
236
-	 * @param IDocumentAccess $access
237
-	 *
238
-	 * @return $this
239
-	 */
240
-	final public function setAccess(IDocumentAccess $access): IIndexDocument {
241
-		$this->access = $access;
242
-
243
-		return $this;
244
-	}
245
-
246
-	/**
247
-	 * Get the IDocumentAccess related to the original document.
248
-	 *
249
-	 * @since 15.0.0
250
-	 *
251
-	 * @return IDocumentAccess
252
-	 */
253
-	final public function getAccess(): IDocumentAccess {
254
-		return $this->access;
255
-	}
256
-
257
-
258
-	/**
259
-	 * Add a tag to the list.
260
-	 *
261
-	 * @since 15.0.0
262
-	 *
263
-	 * @param string $tag
264
-	 *
265
-	 * @return IIndexDocument
266
-	 */
267
-	final public function addTag(string $tag): IIndexDocument {
268
-		$this->tags[] = $tag;
269
-
270
-		return $this;
271
-	}
272
-
273
-	/**
274
-	 * Set the list of tags assigned to the original document.
275
-	 *
276
-	 * @since 15.0.0
277
-	 *
278
-	 * @param array $tags
279
-	 *
280
-	 * @return IIndexDocument
281
-	 */
282
-	final public function setTags(array $tags): IIndexDocument {
283
-		$this->tags = $tags;
284
-
285
-		return $this;
286
-	}
287
-
288
-	/**
289
-	 * Get the list of tags assigned to the original document.
290
-	 *
291
-	 * @since 15.0.0
292
-	 *
293
-	 * @return array
294
-	 */
295
-	final public function getTags(): array {
296
-		return $this->tags;
297
-	}
298
-
299
-
300
-	/**
301
-	 * Add a meta tag to the list.
302
-	 *
303
-	 * @since 15.0.0
304
-	 *
305
-	 * @param string $tag
306
-	 *
307
-	 * @return IIndexDocument
308
-	 */
309
-	final public function addMetaTag(string $tag): IIndexDocument {
310
-		$this->metaTags[] = $tag;
311
-
312
-		return $this;
313
-	}
314
-
315
-	/**
316
-	 * Set the list of meta tags assigned to the original document.
317
-	 *
318
-	 * @since 15.0.0
319
-	 *
320
-	 * @param array $tags
321
-	 *
322
-	 * @return IIndexDocument
323
-	 */
324
-	final public function setMetaTags(array $tags): IIndexDocument {
325
-		$this->metaTags = $tags;
326
-
327
-		return $this;
328
-	}
329
-
330
-	/**
331
-	 * Get the list of meta tags assigned to the original document.
332
-	 *
333
-	 * @since 15.0.0
334
-	 *
335
-	 * @return array
336
-	 */
337
-	final public function getMetaTags(): array {
338
-		return $this->metaTags;
339
-	}
340
-
341
-
342
-	/**
343
-	 * Add a sub tag to the list.
344
-	 *
345
-	 * @since 15.0.0
346
-	 *
347
-	 * @param string $sub
348
-	 * @param string $tag
349
-	 *
350
-	 * @return IIndexDocument
351
-	 */
352
-	final public function addSubTag(string $sub, string $tag): IIndexDocument {
353
-		if (!array_key_exists($sub, $this->subTags)) {
354
-			$this->subTags[$sub] = [];
355
-		}
356
-
357
-		$this->subTags[$sub][] = $tag;
358
-
359
-		return $this;
360
-	}
361
-
362
-
363
-	/**
364
-	 * Set the list of sub tags assigned to the original document.
365
-	 *
366
-	 * @since 15.0.0
367
-	 *
368
-	 * @param array $tags
369
-	 *
370
-	 * @return IIndexDocument
371
-	 */
372
-	final public function setSubTags(array $tags): IIndexDocument {
373
-		$this->subTags = $tags;
374
-
375
-		return $this;
376
-	}
377
-
378
-	/**
379
-	 * Get the list of sub tags assigned to the original document.
380
-	 * If $formatted is true, the result will be formatted in a one
381
-	 * dimensional array.
382
-	 *
383
-	 * @since 15.0.0
384
-	 *
385
-	 * @param bool $formatted
386
-	 *
387
-	 * @return array
388
-	 */
389
-	final public function getSubTags(bool $formatted = false): array {
390
-		if ($formatted === false) {
391
-			return $this->subTags;
392
-		}
393
-
394
-		$subTags = [];
395
-		$ak = array_keys($this->subTags);
396
-		foreach ($ak as $source) {
397
-			$tags = $this->subTags[$source];
398
-			foreach ($tags as $tag) {
399
-				$subTags[] = $source . '_' . $tag;
400
-			}
401
-		}
402
-
403
-		return $subTags;
404
-	}
405
-
406
-
407
-	/**
408
-	 * Set the source of the original document.
409
-	 *
410
-	 * @since 15.0.0
411
-	 *
412
-	 * @param string $source
413
-	 *
414
-	 * @return IIndexDocument
415
-	 */
416
-	final public function setSource(string $source): IIndexDocument {
417
-		$this->source = $source;
418
-
419
-		return $this;
420
-	}
421
-
422
-	/**
423
-	 * Get the source of the original document.
424
-	 *
425
-	 * @since 15.0.0
426
-	 *
427
-	 * @return string
428
-	 */
429
-	final public function getSource(): string {
430
-		return $this->source;
431
-	}
432
-
433
-
434
-	/**
435
-	 * Set the title of the original document.
436
-	 *
437
-	 * @since 15.0.0
438
-	 *
439
-	 * @param string $title
440
-	 *
441
-	 * @return IIndexDocument
442
-	 */
443
-	final public function setTitle(string $title): IIndexDocument {
444
-		$this->title = $title;
445
-
446
-		return $this;
447
-	}
448
-
449
-	/**
450
-	 * Get the title of the original document.
451
-	 *
452
-	 * @since 15.0.0
453
-	 *
454
-	 * @return string
455
-	 */
456
-	final public function getTitle(): string {
457
-		return $this->title;
458
-	}
459
-
460
-
461
-	/**
462
-	 * Set the content of the document.
463
-	 * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or
464
-	 * encoded in base64.
465
-	 *
466
-	 * @since 15.0.0
467
-	 *
468
-	 * @param string $content
469
-	 * @param int $encoded
470
-	 *
471
-	 * @return IIndexDocument
472
-	 */
473
-	final public function setContent(string $content, int $encoded = 0): IIndexDocument {
474
-		$this->content = $content;
475
-		$this->contentEncoded = $encoded;
476
-
477
-		return $this;
478
-	}
479
-
480
-	/**
481
-	 * Get the content of the original document.
482
-	 *
483
-	 * @since 15.0.0
484
-	 *
485
-	 * @return string
486
-	 */
487
-	final public function getContent(): string {
488
-		return $this->content;
489
-	}
490
-
491
-	/**
492
-	 * Returns the type of the encoding on the content.
493
-	 *
494
-	 * @since 15.0.0
495
-	 *
496
-	 * @return int
497
-	 */
498
-	final public function isContentEncoded(): int {
499
-		return $this->contentEncoded;
500
-	}
501
-
502
-	/**
503
-	 * Return the size of the content.
504
-	 *
505
-	 * @since 15.0.0
506
-	 *
507
-	 * @return int
508
-	 */
509
-	final public function getContentSize(): int {
510
-		return strlen($this->getContent());
511
-	}
512
-
513
-
514
-	/**
515
-	 * Generate an hash, based on the content of the original document.
516
-	 *
517
-	 * @since 15.0.0
518
-	 *
519
-	 * @return IIndexDocument
520
-	 */
521
-	final public function initHash(): IIndexDocument {
522
-		if ($this->getContent() === '' || is_null($this->getContent())) {
523
-			return $this;
524
-		}
525
-
526
-		$this->hash = hash("md5", $this->getContent());
527
-
528
-		return $this;
529
-	}
530
-
531
-	/**
532
-	 * Set the hash of the original document.
533
-	 *
534
-	 * @since 15.0.0
535
-	 *
536
-	 * @param string $hash
537
-	 *
538
-	 * @return IIndexDocument
539
-	 */
540
-	final public function setHash(string $hash): IIndexDocument {
541
-		$this->hash = $hash;
542
-
543
-		return $this;
544
-	}
545
-
546
-	/**
547
-	 * Get the hash of the original document.
548
-	 *
549
-	 * @since 15.0.0
550
-	 *
551
-	 * @return string
552
-	 */
553
-	final public function getHash(): string {
554
-		return $this->hash;
555
-	}
556
-
557
-
558
-	/**
559
-	 * Add a part, identified by a string, and its content.
560
-	 *
561
-	 * It is strongly advised to use alphanumerical chars with no space in the
562
-	 * $part string.
563
-	 *
564
-	 * @since 15.0.0
565
-	 *
566
-	 * @param string $part
567
-	 * @param string $content
568
-	 *
569
-	 * @return IIndexDocument
570
-	 */
571
-	final public function addPart(string $part, string $content): IIndexDocument {
572
-		$this->parts[$part] = $content;
573
-
574
-		return $this;
575
-	}
576
-
577
-	/**
578
-	 * Set all parts and their content.
579
-	 *
580
-	 * @since 15.0.0
581
-	 *
582
-	 * @param array $parts
583
-	 *
584
-	 * @return IIndexDocument
585
-	 */
586
-	final public function setParts(array $parts): IIndexDocument {
587
-		$this->parts = $parts;
588
-
589
-		return $this;
590
-	}
591
-
592
-	/**
593
-	 * Get all parts of the IIndexDocument.
594
-	 *
595
-	 * @since 15.0.0
596
-	 *
597
-	 * @return array
598
-	 */
599
-	final public function getParts(): array {
600
-		return $this->parts;
601
-	}
602
-
603
-
604
-	/**
605
-	 * Add a link, usable by the frontend.
606
-	 *
607
-	 * @since 15.0.0
608
-	 *
609
-	 * @param string $link
610
-	 *
611
-	 * @return IIndexDocument
612
-	 */
613
-	final public function setLink(string $link): IIndexDocument {
614
-		$this->link = $link;
615
-
616
-		return $this;
617
-	}
618
-
619
-	/**
620
-	 * Get the link.
621
-	 *
622
-	 * @since 15.0.0
623
-	 *
624
-	 * @return string
625
-	 */
626
-	final public function getLink(): string {
627
-		return $this->link;
628
-	}
629
-
630
-
631
-	/**
632
-	 * Set more information that couldn't be set using other method.
633
-	 *
634
-	 * @since 15.0.0
635
-	 *
636
-	 * @param array $more
637
-	 *
638
-	 * @return IIndexDocument
639
-	 */
640
-	final public function setMore(array $more): IIndexDocument {
641
-		$this->more = $more;
642
-
643
-		return $this;
644
-	}
645
-
646
-	/**
647
-	 * Get more information.
648
-	 *
649
-	 * @since 15.0.0
650
-	 *
651
-	 * @return array
652
-	 */
653
-	final public function getMore(): array {
654
-		return $this->more;
655
-	}
656
-
657
-
658
-	/**
659
-	 * Add some excerpt of the content of the original document, usually based
660
-	 * on the search request.
661
-	 *
662
-	 * @since 16.0.0
663
-	 *
664
-	 * @param string $source
665
-	 * @param string $excerpt
666
-	 *
667
-	 * @return IIndexDocument
668
-	 */
669
-	final public function addExcerpt(string $source, string $excerpt): IIndexDocument {
670
-		$this->excerpts[] =
671
-			[
672
-				'source' => $source,
673
-				'excerpt' => $this->cleanExcerpt($excerpt)
674
-			];
675
-
676
-		return $this;
677
-	}
678
-
679
-
680
-	/**
681
-	 * Set all excerpts of the content of the original document.
682
-	 *
683
-	 * @since 16.0.0
684
-	 *
685
-	 * @param array $excerpts
686
-	 *
687
-	 * @return IIndexDocument
688
-	 */
689
-	final public function setExcerpts(array $excerpts): IIndexDocument {
690
-		$new = [];
691
-		foreach ($excerpts as $entry) {
692
-			$new[] = [
693
-				'source' => $entry['source'],
694
-				'excerpt' => $this->cleanExcerpt($entry['excerpt'])
695
-			];
696
-		}
697
-
698
-		$this->excerpts = $new;
699
-
700
-		return $this;
701
-	}
702
-
703
-	/**
704
-	 * Get all excerpts of the content of the original document.
705
-	 *
706
-	 * @since 15.0.0
707
-	 *
708
-	 * @return array
709
-	 */
710
-	final public function getExcerpts(): array {
711
-		return $this->excerpts;
712
-	}
713
-
714
-	/**
715
-	 * Clean excerpt.
716
-	 *
717
-	 * @since 16.0.0
718
-	 *
719
-	 * @param string $excerpt
720
-	 * @return string
721
-	 */
722
-	private function cleanExcerpt(string $excerpt): string {
723
-		$excerpt = str_replace("\\n", ' ', $excerpt);
724
-		$excerpt = str_replace("\\r", ' ', $excerpt);
725
-		$excerpt = str_replace("\\t", ' ', $excerpt);
726
-		$excerpt = str_replace("\n", ' ', $excerpt);
727
-		$excerpt = str_replace("\r", ' ', $excerpt);
728
-		$excerpt = str_replace("\t", ' ', $excerpt);
729
-
730
-		return $excerpt;
731
-	}
732
-
733
-
734
-	/**
735
-	 * Set the score to the result assigned to this document during a search
736
-	 * request.
737
-	 *
738
-	 * @since 15.0.0
739
-	 *
740
-	 * @param string $score
741
-	 *
742
-	 * @return IIndexDocument
743
-	 */
744
-	final public function setScore(string $score): IIndexDocument {
745
-		$this->score = $score;
746
-
747
-		return $this;
748
-	}
749
-
750
-	/**
751
-	 * Get the score.
752
-	 *
753
-	 * @since 15.0.0
754
-	 *
755
-	 * @return string
756
-	 */
757
-	final public function getScore(): string {
758
-		return $this->score;
759
-	}
760
-
761
-
762
-	/**
763
-	 * Set some information about the original document that will be available
764
-	 * to the front-end when displaying search result. (as string)
765
-	 * Because this information will not be indexed, this method can also be
766
-	 * used to manage some data while filling the IIndexDocument before its
767
-	 * indexing.
768
-	 *
769
-	 * @since 15.0.0
770
-	 *
771
-	 * @param string $info
772
-	 * @param string $value
773
-	 *
774
-	 * @return IIndexDocument
775
-	 */
776
-	final public function setInfo(string $info, string $value): IIndexDocument {
777
-		$this->info[$info] = $value;
778
-
779
-		return $this;
780
-	}
781
-
782
-	/**
783
-	 * Get an information about a document. (string)
784
-	 *
785
-	 * @since 15.0.0
786
-	 *
787
-	 * @param string $info
788
-	 * @param string $default
789
-	 *
790
-	 * @return string
791
-	 */
792
-	final public function getInfo(string $info, string $default = ''): string {
793
-		if (!key_exists($info, $this->info)) {
794
-			return $default;
795
-		}
796
-
797
-		return $this->info[$info];
798
-	}
799
-
800
-	/**
801
-	 * Set some information about the original document that will be available
802
-	 * to the front-end when displaying search result. (as array)
803
-	 * Because this information will not be indexed, this method can also be
804
-	 * used to manage some data while filling the IIndexDocument before its
805
-	 * indexing.
806
-	 *
807
-	 * @since 15.0.0
808
-	 *
809
-	 * @param string $info
810
-	 * @param array $value
811
-	 *
812
-	 * @return IIndexDocument
813
-	 */
814
-	final public function setInfoArray(string $info, array $value): IIndexDocument {
815
-		$this->info[$info] = $value;
816
-
817
-		return $this;
818
-	}
819
-
820
-	/**
821
-	 * Get an information about a document. (array)
822
-	 *
823
-	 * @since 15.0.0
824
-	 *
825
-	 * @param string $info
826
-	 * @param array $default
827
-	 *
828
-	 * @return array
829
-	 */
830
-	final public function getInfoArray(string $info, array $default = []): array {
831
-		if (!key_exists($info, $this->info)) {
832
-			return $default;
833
-		}
834
-
835
-		return $this->info[$info];
836
-	}
837
-
838
-	/**
839
-	 * Set some information about the original document that will be available
840
-	 * to the front-end when displaying search result. (as int)
841
-	 * Because this information will not be indexed, this method can also be
842
-	 * used to manage some data while filling the IIndexDocument before its
843
-	 * indexing.
844
-	 *
845
-	 * @since 15.0.0
846
-	 *
847
-	 * @param string $info
848
-	 * @param int $value
849
-	 *
850
-	 * @return IIndexDocument
851
-	 */
852
-	final public function setInfoInt(string $info, int $value): IIndexDocument {
853
-		$this->info[$info] = $value;
854
-
855
-		return $this;
856
-	}
857
-
858
-	/**
859
-	 * Get an information about a document. (int)
860
-	 *
861
-	 * @since 15.0.0
862
-	 *
863
-	 * @param string $info
864
-	 * @param int $default
865
-	 *
866
-	 * @return int
867
-	 */
868
-	final public function getInfoInt(string $info, int $default = 0): int {
869
-		if (!key_exists($info, $this->info)) {
870
-			return $default;
871
-		}
872
-
873
-		return $this->info[$info];
874
-	}
875
-
876
-	/**
877
-	 * Set some information about the original document that will be available
878
-	 * to the front-end when displaying search result. (as bool)
879
-	 * Because this information will not be indexed, this method can also be
880
-	 * used to manage some data while filling the IIndexDocument before its
881
-	 * indexing.
882
-	 *
883
-	 * @since 15.0.0
884
-	 *
885
-	 * @param string $info
886
-	 * @param bool $value
887
-	 *
888
-	 * @return IIndexDocument
889
-	 */
890
-	final public function setInfoBool(string $info, bool $value): IIndexDocument {
891
-		$this->info[$info] = $value;
892
-
893
-		return $this;
894
-	}
895
-
896
-	/**
897
-	 * Get an information about a document. (bool)
898
-	 *
899
-	 * @since 15.0.0
900
-	 *
901
-	 * @param string $info
902
-	 * @param bool $default
903
-	 *
904
-	 * @return bool
905
-	 */
906
-	final public function getInfoBool(string $info, bool $default = false): bool {
907
-		if (!key_exists($info, $this->info)) {
908
-			return $default;
909
-		}
910
-
911
-		return $this->info[$info];
912
-	}
913
-
914
-	/**
915
-	 * Get all info.
916
-	 *
917
-	 * @since 15.0.0
918
-	 *
919
-	 * @return array
920
-	 */
921
-	final public function getInfoAll(): array {
922
-		$info = [];
923
-		foreach ($this->info as $k => $v) {
924
-			if (substr($k, 0, 1) === '_') {
925
-				continue;
926
-			}
927
-
928
-			$info[$k] = $v;
929
-		}
930
-
931
-		return $info;
932
-	}
933
-
934
-
935
-	/**
936
-	 * @since 15.0.0
937
-	 *
938
-	 * On some version of PHP, it is better to force destruct the object.
939
-	 * And during the index, the number of generated IIndexDocument can be
940
-	 * _huge_.
941
-	 */
942
-	public function __destruct() {
943
-		unset($this->id);
944
-		unset($this->providerId);
945
-		unset($this->access);
946
-		unset($this->modifiedTime);
947
-		unset($this->title);
948
-		unset($this->content);
949
-		unset($this->hash);
950
-		unset($this->link);
951
-		unset($this->source);
952
-		unset($this->tags);
953
-		unset($this->metaTags);
954
-		unset($this->subTags);
955
-		unset($this->more);
956
-		unset($this->excerpts);
957
-		unset($this->score);
958
-		unset($this->info);
959
-		unset($this->contentEncoded);
960
-	}
961
-
962
-	/**
963
-	 * @since 15.0.0
964
-	 */
965
-	public function jsonSerialize(): array {
966
-		return [
967
-			'id' => $this->getId(),
968
-			'providerId' => $this->getProviderId(),
969
-			'access' => $this->access,
970
-			'modifiedTime' => $this->getModifiedTime(),
971
-			'title' => $this->getTitle(),
972
-			'link' => $this->getLink(),
973
-			'index' => $this->index,
974
-			'source' => $this->getSource(),
975
-			'info' => $this->getInfoAll(),
976
-			'hash' => $this->getHash(),
977
-			'contentSize' => $this->getContentSize(),
978
-			'tags' => $this->getTags(),
979
-			'metatags' => $this->getMetaTags(),
980
-			'subtags' => $this->getSubTags(),
981
-			'more' => $this->getMore(),
982
-			'excerpts' => $this->getExcerpts(),
983
-			'score' => $this->getScore()
984
-		];
985
-	}
56
+    /** @var DocumentAccess */
57
+    protected $access;
58
+
59
+    /** @var IIndex */
60
+    protected $index;
61
+
62
+    /** @var int */
63
+    protected $modifiedTime = 0;
64
+
65
+    /** @var string */
66
+    protected $source = '';
67
+
68
+    /** @var array */
69
+    protected $tags = [];
70
+
71
+    /** @var array */
72
+    protected $metaTags = [];
73
+
74
+    /** @var array */
75
+    protected $subTags = [];
76
+
77
+    /** @var string */
78
+    protected $title = '';
79
+
80
+    /** @var string */
81
+    protected $content = '';
82
+
83
+    /** @var string */
84
+    protected $hash = '';
85
+
86
+    /** @var array */
87
+    protected $parts = [];
88
+
89
+    /** @var string */
90
+    protected $link = '';
91
+
92
+    /** @var array */
93
+    protected $more = [];
94
+
95
+    /** @var array */
96
+    protected $excerpts = [];
97
+
98
+    /** @var string */
99
+    protected $score = '';
100
+
101
+    /** @var array */
102
+    protected $info = [];
103
+
104
+    /** @var int */
105
+    protected $contentEncoded = 0;
106
+
107
+
108
+    /**
109
+     * IIndexDocument constructor.
110
+     *
111
+     * On creation, we assure the uniqueness of the object using the providerId
112
+     * and the Id of the original document.
113
+     *
114
+     * @since 15.0.0
115
+     *
116
+     * @param string $providerId
117
+     * @param string $documentId
118
+     */
119
+    public function __construct(string $providerId, string $documentId) {
120
+        $this->providerId = $providerId;
121
+        $this->id = $documentId;
122
+    }
123
+
124
+
125
+    /**
126
+     * Returns the Id of the original document.
127
+     *
128
+     * @since 15.0.0
129
+     *
130
+     * @return string
131
+     */
132
+    final public function getId(): string {
133
+        return $this->id;
134
+    }
135
+
136
+
137
+    /**
138
+     * Returns the Id of the provider.
139
+     *
140
+     * @since 15.0.0
141
+     *
142
+     * @return string
143
+     */
144
+    final public function getProviderId(): string {
145
+        return $this->providerId;
146
+    }
147
+
148
+
149
+    /**
150
+     * Set the Index related to the IIndexDocument.
151
+     *
152
+     * @see IIndex
153
+     *
154
+     * @since 15.0.0
155
+     *
156
+     * @param IIndex $index
157
+     *
158
+     * @return IIndexDocument
159
+     */
160
+    final public function setIndex(IIndex $index): IIndexDocument {
161
+        $this->index = $index;
162
+
163
+        return $this;
164
+    }
165
+
166
+    /**
167
+     * Get the Index.
168
+     *
169
+     * @since 15.0.0
170
+     *
171
+     * @return IIndex
172
+     */
173
+    final public function getIndex(): IIndex {
174
+        return $this->index;
175
+    }
176
+
177
+    /**
178
+     * return if Index is defined.
179
+     *
180
+     * @since 16.0.0
181
+     *
182
+     * @return bool
183
+     */
184
+    final public function hasIndex(): bool {
185
+        return ($this->index !== null);
186
+    }
187
+
188
+
189
+    /**
190
+     * Set the modified time of the original document.
191
+     *
192
+     * @since 15.0.0
193
+     *
194
+     * @param int $modifiedTime
195
+     *
196
+     * @return IIndexDocument
197
+     */
198
+    final public function setModifiedTime(int $modifiedTime): IIndexDocument {
199
+        $this->modifiedTime = $modifiedTime;
200
+
201
+        return $this;
202
+    }
203
+
204
+    /**
205
+     * Get the modified time of the original document.
206
+     *
207
+     * @since 15.0.0
208
+     *
209
+     * @return int
210
+     */
211
+    final public function getModifiedTime(): int {
212
+        return $this->modifiedTime;
213
+    }
214
+
215
+    /**
216
+     * Check if the original document of the IIndexDocument is older than $time.
217
+     *
218
+     * @since 15.0.0
219
+     *
220
+     * @param int $time
221
+     *
222
+     * @return bool
223
+     */
224
+    final public function isOlderThan(int $time): bool {
225
+        return ($this->modifiedTime < $time);
226
+    }
227
+
228
+
229
+    /**
230
+     * Set the read rights of the original document using a IDocumentAccess.
231
+     *
232
+     * @see IDocumentAccess
233
+     *
234
+     * @since 15.0.0
235
+     *
236
+     * @param IDocumentAccess $access
237
+     *
238
+     * @return $this
239
+     */
240
+    final public function setAccess(IDocumentAccess $access): IIndexDocument {
241
+        $this->access = $access;
242
+
243
+        return $this;
244
+    }
245
+
246
+    /**
247
+     * Get the IDocumentAccess related to the original document.
248
+     *
249
+     * @since 15.0.0
250
+     *
251
+     * @return IDocumentAccess
252
+     */
253
+    final public function getAccess(): IDocumentAccess {
254
+        return $this->access;
255
+    }
256
+
257
+
258
+    /**
259
+     * Add a tag to the list.
260
+     *
261
+     * @since 15.0.0
262
+     *
263
+     * @param string $tag
264
+     *
265
+     * @return IIndexDocument
266
+     */
267
+    final public function addTag(string $tag): IIndexDocument {
268
+        $this->tags[] = $tag;
269
+
270
+        return $this;
271
+    }
272
+
273
+    /**
274
+     * Set the list of tags assigned to the original document.
275
+     *
276
+     * @since 15.0.0
277
+     *
278
+     * @param array $tags
279
+     *
280
+     * @return IIndexDocument
281
+     */
282
+    final public function setTags(array $tags): IIndexDocument {
283
+        $this->tags = $tags;
284
+
285
+        return $this;
286
+    }
287
+
288
+    /**
289
+     * Get the list of tags assigned to the original document.
290
+     *
291
+     * @since 15.0.0
292
+     *
293
+     * @return array
294
+     */
295
+    final public function getTags(): array {
296
+        return $this->tags;
297
+    }
298
+
299
+
300
+    /**
301
+     * Add a meta tag to the list.
302
+     *
303
+     * @since 15.0.0
304
+     *
305
+     * @param string $tag
306
+     *
307
+     * @return IIndexDocument
308
+     */
309
+    final public function addMetaTag(string $tag): IIndexDocument {
310
+        $this->metaTags[] = $tag;
311
+
312
+        return $this;
313
+    }
314
+
315
+    /**
316
+     * Set the list of meta tags assigned to the original document.
317
+     *
318
+     * @since 15.0.0
319
+     *
320
+     * @param array $tags
321
+     *
322
+     * @return IIndexDocument
323
+     */
324
+    final public function setMetaTags(array $tags): IIndexDocument {
325
+        $this->metaTags = $tags;
326
+
327
+        return $this;
328
+    }
329
+
330
+    /**
331
+     * Get the list of meta tags assigned to the original document.
332
+     *
333
+     * @since 15.0.0
334
+     *
335
+     * @return array
336
+     */
337
+    final public function getMetaTags(): array {
338
+        return $this->metaTags;
339
+    }
340
+
341
+
342
+    /**
343
+     * Add a sub tag to the list.
344
+     *
345
+     * @since 15.0.0
346
+     *
347
+     * @param string $sub
348
+     * @param string $tag
349
+     *
350
+     * @return IIndexDocument
351
+     */
352
+    final public function addSubTag(string $sub, string $tag): IIndexDocument {
353
+        if (!array_key_exists($sub, $this->subTags)) {
354
+            $this->subTags[$sub] = [];
355
+        }
356
+
357
+        $this->subTags[$sub][] = $tag;
358
+
359
+        return $this;
360
+    }
361
+
362
+
363
+    /**
364
+     * Set the list of sub tags assigned to the original document.
365
+     *
366
+     * @since 15.0.0
367
+     *
368
+     * @param array $tags
369
+     *
370
+     * @return IIndexDocument
371
+     */
372
+    final public function setSubTags(array $tags): IIndexDocument {
373
+        $this->subTags = $tags;
374
+
375
+        return $this;
376
+    }
377
+
378
+    /**
379
+     * Get the list of sub tags assigned to the original document.
380
+     * If $formatted is true, the result will be formatted in a one
381
+     * dimensional array.
382
+     *
383
+     * @since 15.0.0
384
+     *
385
+     * @param bool $formatted
386
+     *
387
+     * @return array
388
+     */
389
+    final public function getSubTags(bool $formatted = false): array {
390
+        if ($formatted === false) {
391
+            return $this->subTags;
392
+        }
393
+
394
+        $subTags = [];
395
+        $ak = array_keys($this->subTags);
396
+        foreach ($ak as $source) {
397
+            $tags = $this->subTags[$source];
398
+            foreach ($tags as $tag) {
399
+                $subTags[] = $source . '_' . $tag;
400
+            }
401
+        }
402
+
403
+        return $subTags;
404
+    }
405
+
406
+
407
+    /**
408
+     * Set the source of the original document.
409
+     *
410
+     * @since 15.0.0
411
+     *
412
+     * @param string $source
413
+     *
414
+     * @return IIndexDocument
415
+     */
416
+    final public function setSource(string $source): IIndexDocument {
417
+        $this->source = $source;
418
+
419
+        return $this;
420
+    }
421
+
422
+    /**
423
+     * Get the source of the original document.
424
+     *
425
+     * @since 15.0.0
426
+     *
427
+     * @return string
428
+     */
429
+    final public function getSource(): string {
430
+        return $this->source;
431
+    }
432
+
433
+
434
+    /**
435
+     * Set the title of the original document.
436
+     *
437
+     * @since 15.0.0
438
+     *
439
+     * @param string $title
440
+     *
441
+     * @return IIndexDocument
442
+     */
443
+    final public function setTitle(string $title): IIndexDocument {
444
+        $this->title = $title;
445
+
446
+        return $this;
447
+    }
448
+
449
+    /**
450
+     * Get the title of the original document.
451
+     *
452
+     * @since 15.0.0
453
+     *
454
+     * @return string
455
+     */
456
+    final public function getTitle(): string {
457
+        return $this->title;
458
+    }
459
+
460
+
461
+    /**
462
+     * Set the content of the document.
463
+     * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or
464
+     * encoded in base64.
465
+     *
466
+     * @since 15.0.0
467
+     *
468
+     * @param string $content
469
+     * @param int $encoded
470
+     *
471
+     * @return IIndexDocument
472
+     */
473
+    final public function setContent(string $content, int $encoded = 0): IIndexDocument {
474
+        $this->content = $content;
475
+        $this->contentEncoded = $encoded;
476
+
477
+        return $this;
478
+    }
479
+
480
+    /**
481
+     * Get the content of the original document.
482
+     *
483
+     * @since 15.0.0
484
+     *
485
+     * @return string
486
+     */
487
+    final public function getContent(): string {
488
+        return $this->content;
489
+    }
490
+
491
+    /**
492
+     * Returns the type of the encoding on the content.
493
+     *
494
+     * @since 15.0.0
495
+     *
496
+     * @return int
497
+     */
498
+    final public function isContentEncoded(): int {
499
+        return $this->contentEncoded;
500
+    }
501
+
502
+    /**
503
+     * Return the size of the content.
504
+     *
505
+     * @since 15.0.0
506
+     *
507
+     * @return int
508
+     */
509
+    final public function getContentSize(): int {
510
+        return strlen($this->getContent());
511
+    }
512
+
513
+
514
+    /**
515
+     * Generate an hash, based on the content of the original document.
516
+     *
517
+     * @since 15.0.0
518
+     *
519
+     * @return IIndexDocument
520
+     */
521
+    final public function initHash(): IIndexDocument {
522
+        if ($this->getContent() === '' || is_null($this->getContent())) {
523
+            return $this;
524
+        }
525
+
526
+        $this->hash = hash("md5", $this->getContent());
527
+
528
+        return $this;
529
+    }
530
+
531
+    /**
532
+     * Set the hash of the original document.
533
+     *
534
+     * @since 15.0.0
535
+     *
536
+     * @param string $hash
537
+     *
538
+     * @return IIndexDocument
539
+     */
540
+    final public function setHash(string $hash): IIndexDocument {
541
+        $this->hash = $hash;
542
+
543
+        return $this;
544
+    }
545
+
546
+    /**
547
+     * Get the hash of the original document.
548
+     *
549
+     * @since 15.0.0
550
+     *
551
+     * @return string
552
+     */
553
+    final public function getHash(): string {
554
+        return $this->hash;
555
+    }
556
+
557
+
558
+    /**
559
+     * Add a part, identified by a string, and its content.
560
+     *
561
+     * It is strongly advised to use alphanumerical chars with no space in the
562
+     * $part string.
563
+     *
564
+     * @since 15.0.0
565
+     *
566
+     * @param string $part
567
+     * @param string $content
568
+     *
569
+     * @return IIndexDocument
570
+     */
571
+    final public function addPart(string $part, string $content): IIndexDocument {
572
+        $this->parts[$part] = $content;
573
+
574
+        return $this;
575
+    }
576
+
577
+    /**
578
+     * Set all parts and their content.
579
+     *
580
+     * @since 15.0.0
581
+     *
582
+     * @param array $parts
583
+     *
584
+     * @return IIndexDocument
585
+     */
586
+    final public function setParts(array $parts): IIndexDocument {
587
+        $this->parts = $parts;
588
+
589
+        return $this;
590
+    }
591
+
592
+    /**
593
+     * Get all parts of the IIndexDocument.
594
+     *
595
+     * @since 15.0.0
596
+     *
597
+     * @return array
598
+     */
599
+    final public function getParts(): array {
600
+        return $this->parts;
601
+    }
602
+
603
+
604
+    /**
605
+     * Add a link, usable by the frontend.
606
+     *
607
+     * @since 15.0.0
608
+     *
609
+     * @param string $link
610
+     *
611
+     * @return IIndexDocument
612
+     */
613
+    final public function setLink(string $link): IIndexDocument {
614
+        $this->link = $link;
615
+
616
+        return $this;
617
+    }
618
+
619
+    /**
620
+     * Get the link.
621
+     *
622
+     * @since 15.0.0
623
+     *
624
+     * @return string
625
+     */
626
+    final public function getLink(): string {
627
+        return $this->link;
628
+    }
629
+
630
+
631
+    /**
632
+     * Set more information that couldn't be set using other method.
633
+     *
634
+     * @since 15.0.0
635
+     *
636
+     * @param array $more
637
+     *
638
+     * @return IIndexDocument
639
+     */
640
+    final public function setMore(array $more): IIndexDocument {
641
+        $this->more = $more;
642
+
643
+        return $this;
644
+    }
645
+
646
+    /**
647
+     * Get more information.
648
+     *
649
+     * @since 15.0.0
650
+     *
651
+     * @return array
652
+     */
653
+    final public function getMore(): array {
654
+        return $this->more;
655
+    }
656
+
657
+
658
+    /**
659
+     * Add some excerpt of the content of the original document, usually based
660
+     * on the search request.
661
+     *
662
+     * @since 16.0.0
663
+     *
664
+     * @param string $source
665
+     * @param string $excerpt
666
+     *
667
+     * @return IIndexDocument
668
+     */
669
+    final public function addExcerpt(string $source, string $excerpt): IIndexDocument {
670
+        $this->excerpts[] =
671
+            [
672
+                'source' => $source,
673
+                'excerpt' => $this->cleanExcerpt($excerpt)
674
+            ];
675
+
676
+        return $this;
677
+    }
678
+
679
+
680
+    /**
681
+     * Set all excerpts of the content of the original document.
682
+     *
683
+     * @since 16.0.0
684
+     *
685
+     * @param array $excerpts
686
+     *
687
+     * @return IIndexDocument
688
+     */
689
+    final public function setExcerpts(array $excerpts): IIndexDocument {
690
+        $new = [];
691
+        foreach ($excerpts as $entry) {
692
+            $new[] = [
693
+                'source' => $entry['source'],
694
+                'excerpt' => $this->cleanExcerpt($entry['excerpt'])
695
+            ];
696
+        }
697
+
698
+        $this->excerpts = $new;
699
+
700
+        return $this;
701
+    }
702
+
703
+    /**
704
+     * Get all excerpts of the content of the original document.
705
+     *
706
+     * @since 15.0.0
707
+     *
708
+     * @return array
709
+     */
710
+    final public function getExcerpts(): array {
711
+        return $this->excerpts;
712
+    }
713
+
714
+    /**
715
+     * Clean excerpt.
716
+     *
717
+     * @since 16.0.0
718
+     *
719
+     * @param string $excerpt
720
+     * @return string
721
+     */
722
+    private function cleanExcerpt(string $excerpt): string {
723
+        $excerpt = str_replace("\\n", ' ', $excerpt);
724
+        $excerpt = str_replace("\\r", ' ', $excerpt);
725
+        $excerpt = str_replace("\\t", ' ', $excerpt);
726
+        $excerpt = str_replace("\n", ' ', $excerpt);
727
+        $excerpt = str_replace("\r", ' ', $excerpt);
728
+        $excerpt = str_replace("\t", ' ', $excerpt);
729
+
730
+        return $excerpt;
731
+    }
732
+
733
+
734
+    /**
735
+     * Set the score to the result assigned to this document during a search
736
+     * request.
737
+     *
738
+     * @since 15.0.0
739
+     *
740
+     * @param string $score
741
+     *
742
+     * @return IIndexDocument
743
+     */
744
+    final public function setScore(string $score): IIndexDocument {
745
+        $this->score = $score;
746
+
747
+        return $this;
748
+    }
749
+
750
+    /**
751
+     * Get the score.
752
+     *
753
+     * @since 15.0.0
754
+     *
755
+     * @return string
756
+     */
757
+    final public function getScore(): string {
758
+        return $this->score;
759
+    }
760
+
761
+
762
+    /**
763
+     * Set some information about the original document that will be available
764
+     * to the front-end when displaying search result. (as string)
765
+     * Because this information will not be indexed, this method can also be
766
+     * used to manage some data while filling the IIndexDocument before its
767
+     * indexing.
768
+     *
769
+     * @since 15.0.0
770
+     *
771
+     * @param string $info
772
+     * @param string $value
773
+     *
774
+     * @return IIndexDocument
775
+     */
776
+    final public function setInfo(string $info, string $value): IIndexDocument {
777
+        $this->info[$info] = $value;
778
+
779
+        return $this;
780
+    }
781
+
782
+    /**
783
+     * Get an information about a document. (string)
784
+     *
785
+     * @since 15.0.0
786
+     *
787
+     * @param string $info
788
+     * @param string $default
789
+     *
790
+     * @return string
791
+     */
792
+    final public function getInfo(string $info, string $default = ''): string {
793
+        if (!key_exists($info, $this->info)) {
794
+            return $default;
795
+        }
796
+
797
+        return $this->info[$info];
798
+    }
799
+
800
+    /**
801
+     * Set some information about the original document that will be available
802
+     * to the front-end when displaying search result. (as array)
803
+     * Because this information will not be indexed, this method can also be
804
+     * used to manage some data while filling the IIndexDocument before its
805
+     * indexing.
806
+     *
807
+     * @since 15.0.0
808
+     *
809
+     * @param string $info
810
+     * @param array $value
811
+     *
812
+     * @return IIndexDocument
813
+     */
814
+    final public function setInfoArray(string $info, array $value): IIndexDocument {
815
+        $this->info[$info] = $value;
816
+
817
+        return $this;
818
+    }
819
+
820
+    /**
821
+     * Get an information about a document. (array)
822
+     *
823
+     * @since 15.0.0
824
+     *
825
+     * @param string $info
826
+     * @param array $default
827
+     *
828
+     * @return array
829
+     */
830
+    final public function getInfoArray(string $info, array $default = []): array {
831
+        if (!key_exists($info, $this->info)) {
832
+            return $default;
833
+        }
834
+
835
+        return $this->info[$info];
836
+    }
837
+
838
+    /**
839
+     * Set some information about the original document that will be available
840
+     * to the front-end when displaying search result. (as int)
841
+     * Because this information will not be indexed, this method can also be
842
+     * used to manage some data while filling the IIndexDocument before its
843
+     * indexing.
844
+     *
845
+     * @since 15.0.0
846
+     *
847
+     * @param string $info
848
+     * @param int $value
849
+     *
850
+     * @return IIndexDocument
851
+     */
852
+    final public function setInfoInt(string $info, int $value): IIndexDocument {
853
+        $this->info[$info] = $value;
854
+
855
+        return $this;
856
+    }
857
+
858
+    /**
859
+     * Get an information about a document. (int)
860
+     *
861
+     * @since 15.0.0
862
+     *
863
+     * @param string $info
864
+     * @param int $default
865
+     *
866
+     * @return int
867
+     */
868
+    final public function getInfoInt(string $info, int $default = 0): int {
869
+        if (!key_exists($info, $this->info)) {
870
+            return $default;
871
+        }
872
+
873
+        return $this->info[$info];
874
+    }
875
+
876
+    /**
877
+     * Set some information about the original document that will be available
878
+     * to the front-end when displaying search result. (as bool)
879
+     * Because this information will not be indexed, this method can also be
880
+     * used to manage some data while filling the IIndexDocument before its
881
+     * indexing.
882
+     *
883
+     * @since 15.0.0
884
+     *
885
+     * @param string $info
886
+     * @param bool $value
887
+     *
888
+     * @return IIndexDocument
889
+     */
890
+    final public function setInfoBool(string $info, bool $value): IIndexDocument {
891
+        $this->info[$info] = $value;
892
+
893
+        return $this;
894
+    }
895
+
896
+    /**
897
+     * Get an information about a document. (bool)
898
+     *
899
+     * @since 15.0.0
900
+     *
901
+     * @param string $info
902
+     * @param bool $default
903
+     *
904
+     * @return bool
905
+     */
906
+    final public function getInfoBool(string $info, bool $default = false): bool {
907
+        if (!key_exists($info, $this->info)) {
908
+            return $default;
909
+        }
910
+
911
+        return $this->info[$info];
912
+    }
913
+
914
+    /**
915
+     * Get all info.
916
+     *
917
+     * @since 15.0.0
918
+     *
919
+     * @return array
920
+     */
921
+    final public function getInfoAll(): array {
922
+        $info = [];
923
+        foreach ($this->info as $k => $v) {
924
+            if (substr($k, 0, 1) === '_') {
925
+                continue;
926
+            }
927
+
928
+            $info[$k] = $v;
929
+        }
930
+
931
+        return $info;
932
+    }
933
+
934
+
935
+    /**
936
+     * @since 15.0.0
937
+     *
938
+     * On some version of PHP, it is better to force destruct the object.
939
+     * And during the index, the number of generated IIndexDocument can be
940
+     * _huge_.
941
+     */
942
+    public function __destruct() {
943
+        unset($this->id);
944
+        unset($this->providerId);
945
+        unset($this->access);
946
+        unset($this->modifiedTime);
947
+        unset($this->title);
948
+        unset($this->content);
949
+        unset($this->hash);
950
+        unset($this->link);
951
+        unset($this->source);
952
+        unset($this->tags);
953
+        unset($this->metaTags);
954
+        unset($this->subTags);
955
+        unset($this->more);
956
+        unset($this->excerpts);
957
+        unset($this->score);
958
+        unset($this->info);
959
+        unset($this->contentEncoded);
960
+    }
961
+
962
+    /**
963
+     * @since 15.0.0
964
+     */
965
+    public function jsonSerialize(): array {
966
+        return [
967
+            'id' => $this->getId(),
968
+            'providerId' => $this->getProviderId(),
969
+            'access' => $this->access,
970
+            'modifiedTime' => $this->getModifiedTime(),
971
+            'title' => $this->getTitle(),
972
+            'link' => $this->getLink(),
973
+            'index' => $this->index,
974
+            'source' => $this->getSource(),
975
+            'info' => $this->getInfoAll(),
976
+            'hash' => $this->getHash(),
977
+            'contentSize' => $this->getContentSize(),
978
+            'tags' => $this->getTags(),
979
+            'metatags' => $this->getMetaTags(),
980
+            'subtags' => $this->getSubTags(),
981
+            'more' => $this->getMore(),
982
+            'excerpts' => $this->getExcerpts(),
983
+            'score' => $this->getScore()
984
+        ];
985
+    }
986 986
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 		$providers = $this->registry->getProviderStates($event->getUser());
54 54
 
55 55
 		// Loop over all providers. If all are disabled we remove the job
56
-		$state = array_reduce($providers, function (bool $carry, bool $enabled) {
56
+		$state = array_reduce($providers, function(bool $carry, bool $enabled) {
57 57
 			return $carry || $enabled;
58 58
 		}, false);
59 59
 
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -35,33 +35,33 @@
 block discarded – undo
35 35
 
36 36
 class ProviderDisabled implements IEventListener {
37 37
 
38
-	/** @var IRegistry */
39
-	private $registry;
38
+    /** @var IRegistry */
39
+    private $registry;
40 40
 
41
-	/** @var IJobList */
42
-	private $jobList;
41
+    /** @var IJobList */
42
+    private $jobList;
43 43
 
44
-	public function __construct(IRegistry $registry,
45
-								IJobList $jobList) {
46
-		$this->registry = $registry;
47
-		$this->jobList = $jobList;
48
-	}
44
+    public function __construct(IRegistry $registry,
45
+                                IJobList $jobList) {
46
+        $this->registry = $registry;
47
+        $this->jobList = $jobList;
48
+    }
49 49
 
50
-	public function handle(Event $event): void {
51
-		if (!($event instanceof RegistryEvent)) {
52
-			return;
53
-		}
50
+    public function handle(Event $event): void {
51
+        if (!($event instanceof RegistryEvent)) {
52
+            return;
53
+        }
54 54
 
55
-		$providers = $this->registry->getProviderStates($event->getUser());
55
+        $providers = $this->registry->getProviderStates($event->getUser());
56 56
 
57
-		// Loop over all providers. If all are disabled we remove the job
58
-		$state = array_reduce($providers, function (bool $carry, bool $enabled) {
59
-			return $carry || $enabled;
60
-		}, false);
57
+        // Loop over all providers. If all are disabled we remove the job
58
+        $state = array_reduce($providers, function (bool $carry, bool $enabled) {
59
+            return $carry || $enabled;
60
+        }, false);
61 61
 
62
-		if ($state === false) {
63
-			$this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]);
64
-		}
65
-	}
62
+        if ($state === false) {
63
+            $this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]);
64
+        }
65
+    }
66 66
 
67 67
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Db/AccessToken.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,20 +34,20 @@
 block discarded – undo
34 34
  * @method void setHashedCode(string $token)
35 35
  */
36 36
 class AccessToken extends Entity {
37
-	/** @var int */
38
-	protected $tokenId;
39
-	/** @var int */
40
-	protected $clientId;
41
-	/** @var string */
42
-	protected $hashedCode;
43
-	/** @var string */
44
-	protected $encryptedToken;
37
+    /** @var int */
38
+    protected $tokenId;
39
+    /** @var int */
40
+    protected $clientId;
41
+    /** @var string */
42
+    protected $hashedCode;
43
+    /** @var string */
44
+    protected $encryptedToken;
45 45
 
46
-	public function __construct() {
47
-		$this->addType('id', 'int');
48
-		$this->addType('tokenId', 'int');
49
-		$this->addType('clientId', 'int');
50
-		$this->addType('hashedCode', 'string');
51
-		$this->addType('encryptedToken', 'string');
52
-	}
46
+    public function __construct() {
47
+        $this->addType('id', 'int');
48
+        $this->addType('tokenId', 'int');
49
+        $this->addType('clientId', 'int');
50
+        $this->addType('hashedCode', 'string');
51
+        $this->addType('encryptedToken', 'string');
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Exceptions/WipeTokenException.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,16 +26,16 @@
 block discarded – undo
26 26
 use OC\Authentication\Token\IToken;
27 27
 
28 28
 class WipeTokenException extends InvalidTokenException {
29
-	/** @var IToken */
30
-	private $token;
29
+    /** @var IToken */
30
+    private $token;
31 31
 
32
-	public function __construct(IToken $token) {
33
-		parent::__construct();
32
+    public function __construct(IToken $token) {
33
+        parent::__construct();
34 34
 
35
-		$this->token = $token;
36
-	}
35
+        $this->token = $token;
36
+    }
37 37
 
38
-	public function getToken(): IToken {
39
-		return $this->token;
40
-	}
38
+    public function getToken(): IToken {
39
+        return $this->token;
40
+    }
41 41
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/RegenerateBirthdayCalendars.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -30,43 +30,43 @@
 block discarded – undo
30 30
 
31 31
 class RegenerateBirthdayCalendars implements IRepairStep {
32 32
 
33
-	/** @var IJobList */
34
-	private $jobList;
33
+    /** @var IJobList */
34
+    private $jobList;
35 35
 
36
-	/** @var IConfig */
37
-	private $config;
36
+    /** @var IConfig */
37
+    private $config;
38 38
 
39
-	/**
40
-	 * @param IJobList $jobList
41
-	 * @param IConfig $config
42
-	 */
43
-	public function __construct(IJobList $jobList,
44
-								IConfig $config) {
45
-		$this->jobList = $jobList;
46
-		$this->config = $config;
47
-	}
39
+    /**
40
+     * @param IJobList $jobList
41
+     * @param IConfig $config
42
+     */
43
+    public function __construct(IJobList $jobList,
44
+                                IConfig $config) {
45
+        $this->jobList = $jobList;
46
+        $this->config = $config;
47
+    }
48 48
 
49
-	/**
50
-	 * @return string
51
-	 */
52
-	public function getName() {
53
-		return 'Regenerating birthday calendars to use new icons and fix old birthday events without year';
54
-	}
49
+    /**
50
+     * @return string
51
+     */
52
+    public function getName() {
53
+        return 'Regenerating birthday calendars to use new icons and fix old birthday events without year';
54
+    }
55 55
 
56
-	/**
57
-	 * @param IOutput $output
58
-	 */
59
-	public function run(IOutput $output) {
60
-		// only run once
61
-		if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') {
62
-			$output->info('Repair step already executed');
63
-			return;
64
-		}
56
+    /**
57
+     * @param IOutput $output
58
+     */
59
+    public function run(IOutput $output) {
60
+        // only run once
61
+        if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') {
62
+            $output->info('Repair step already executed');
63
+            return;
64
+        }
65 65
 
66
-		$output->info('Adding background jobs to regenerate birthday calendar');
67
-		$this->jobList->add(RegisterRegenerateBirthdayCalendars::class);
66
+        $output->info('Adding background jobs to regenerate birthday calendar');
67
+        $this->jobList->add(RegisterRegenerateBirthdayCalendars::class);
68 68
 
69
-		// if all were done, no need to redo the repair during next upgrade
70
-		$this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
71
-	}
69
+        // if all were done, no need to redo the repair during next upgrade
70
+        $this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
71
+    }
72 72
 }
Please login to merge, or discard this patch.