Completed
Push — master ( 80b21c...5129a7 )
by Joas
29:44 queued 15s
created
core/Migrations/Version24000Date20211222112246.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -33,66 +33,66 @@
 block discarded – undo
33 33
 use OCP\Migration\SimpleMigrationStep;
34 34
 
35 35
 class Version24000Date20211222112246 extends SimpleMigrationStep {
36
-	private const TABLE_NAME = 'reactions';
36
+    private const TABLE_NAME = 'reactions';
37 37
 
38
-	/**
39
-	 * @param IOutput $output
40
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
41
-	 * @param array $options
42
-	 * @return null|ISchemaWrapper
43
-	 */
44
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
45
-		/** @var ISchemaWrapper $schema */
46
-		$schema = $schemaClosure();
38
+    /**
39
+     * @param IOutput $output
40
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
41
+     * @param array $options
42
+     * @return null|ISchemaWrapper
43
+     */
44
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
45
+        /** @var ISchemaWrapper $schema */
46
+        $schema = $schemaClosure();
47 47
 
48
-		$action = false;
49
-		$comments = $schema->getTable('comments');
50
-		if (!$comments->hasColumn('reactions')) {
51
-			$comments->addColumn('reactions', Types::STRING, [
52
-				'notnull' => false,
53
-				'length' => 4000,
54
-			]);
55
-			$action = true;
56
-		}
48
+        $action = false;
49
+        $comments = $schema->getTable('comments');
50
+        if (!$comments->hasColumn('reactions')) {
51
+            $comments->addColumn('reactions', Types::STRING, [
52
+                'notnull' => false,
53
+                'length' => 4000,
54
+            ]);
55
+            $action = true;
56
+        }
57 57
 
58
-		if (!$schema->hasTable(self::TABLE_NAME)) {
59
-			$table = $schema->createTable(self::TABLE_NAME);
60
-			$table->addColumn('id', Types::BIGINT, [
61
-				'autoincrement' => true,
62
-				'notnull' => true,
63
-				'length' => 11,
64
-				'unsigned' => true,
65
-			]);
66
-			$table->addColumn('parent_id', Types::BIGINT, [
67
-				'notnull' => true,
68
-				'length' => 11,
69
-				'unsigned' => true,
70
-			]);
71
-			$table->addColumn('message_id', Types::BIGINT, [
72
-				'notnull' => true,
73
-				'length' => 11,
74
-				'unsigned' => true,
75
-			]);
76
-			$table->addColumn('actor_type', Types::STRING, [
77
-				'notnull' => true,
78
-				'length' => 64,
79
-				'default' => '',
80
-			]);
81
-			$table->addColumn('actor_id', Types::STRING, [
82
-				'notnull' => true,
83
-				'length' => 64,
84
-				'default' => '',
85
-			]);
86
-			$table->addColumn('reaction', Types::STRING, [
87
-				'notnull' => true,
88
-				'length' => 32,
89
-			]);
90
-			$table->setPrimaryKey(['id']);
91
-			$table->addIndex(['reaction'], 'comment_reaction');
92
-			$table->addIndex(['parent_id'], 'comment_reaction_parent_id');
93
-			$table->addUniqueIndex(['parent_id', 'actor_type', 'actor_id', 'reaction'], 'comment_reaction_unique');
94
-			$action = true;
95
-		}
96
-		return $action ? $schema : null;
97
-	}
58
+        if (!$schema->hasTable(self::TABLE_NAME)) {
59
+            $table = $schema->createTable(self::TABLE_NAME);
60
+            $table->addColumn('id', Types::BIGINT, [
61
+                'autoincrement' => true,
62
+                'notnull' => true,
63
+                'length' => 11,
64
+                'unsigned' => true,
65
+            ]);
66
+            $table->addColumn('parent_id', Types::BIGINT, [
67
+                'notnull' => true,
68
+                'length' => 11,
69
+                'unsigned' => true,
70
+            ]);
71
+            $table->addColumn('message_id', Types::BIGINT, [
72
+                'notnull' => true,
73
+                'length' => 11,
74
+                'unsigned' => true,
75
+            ]);
76
+            $table->addColumn('actor_type', Types::STRING, [
77
+                'notnull' => true,
78
+                'length' => 64,
79
+                'default' => '',
80
+            ]);
81
+            $table->addColumn('actor_id', Types::STRING, [
82
+                'notnull' => true,
83
+                'length' => 64,
84
+                'default' => '',
85
+            ]);
86
+            $table->addColumn('reaction', Types::STRING, [
87
+                'notnull' => true,
88
+                'length' => 32,
89
+            ]);
90
+            $table->setPrimaryKey(['id']);
91
+            $table->addIndex(['reaction'], 'comment_reaction');
92
+            $table->addIndex(['parent_id'], 'comment_reaction_parent_id');
93
+            $table->addUniqueIndex(['parent_id', 'actor_type', 'actor_id', 'reaction'], 'comment_reaction_unique');
94
+            $action = true;
95
+        }
96
+        return $action ? $schema : null;
97
+    }
98 98
 }
Please login to merge, or discard this patch.
lib/private/Profile/TProfileHelper.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@
 block discarded – undo
29 29
 use OCP\IConfig;
30 30
 
31 31
 trait TProfileHelper {
32
-	protected function isProfileEnabledByDefault(IConfig $config): ?bool {
33
-		return filter_var(
34
-			$config->getAppValue('settings', 'profile_enabled_by_default', '1'),
35
-			FILTER_VALIDATE_BOOLEAN,
36
-			FILTER_NULL_ON_FAILURE,
37
-		);
38
-	}
32
+    protected function isProfileEnabledByDefault(IConfig $config): ?bool {
33
+        return filter_var(
34
+            $config->getAppValue('settings', 'profile_enabled_by_default', '1'),
35
+            FILTER_VALIDATE_BOOLEAN,
36
+            FILTER_NULL_ON_FAILURE,
37
+        );
38
+    }
39 39
 }
Please login to merge, or discard this patch.
apps/user_status/lib/Listener/BeforeTemplateRenderedListener.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,11 +89,11 @@
 block discarded – undo
89 89
 			return;
90 90
 		}
91 91
 
92
-		$this->initialState->provideLazyInitialState(Application::APP_ID, 'status', function () {
92
+		$this->initialState->provideLazyInitialState(Application::APP_ID, 'status', function() {
93 93
 			return $this->jsDataService;
94 94
 		});
95 95
 
96
-		$this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function () use ($user) {
96
+		$this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function() use ($user) {
97 97
 			return ['profileEnabled' => $this->profileManager->isProfileEnabled($user)];
98 98
 		});
99 99
 
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -23,53 +23,53 @@
 block discarded – undo
23 23
 /** @template-implements IEventListener<BeforeTemplateRenderedEvent> */
24 24
 class BeforeTemplateRenderedListener implements IEventListener {
25 25
 
26
-	/** @var ProfileManager */
27
-	private $profileManager;
26
+    /** @var ProfileManager */
27
+    private $profileManager;
28 28
 
29
-	/**
30
-	 * BeforeTemplateRenderedListener constructor.
31
-	 *
32
-	 * @param ProfileManager $profileManager
33
-	 * @param IUserSession $userSession
34
-	 * @param IInitialStateService $initialState
35
-	 * @param JSDataService $jsDataService
36
-	 */
37
-	public function __construct(
38
-		ProfileManager $profileManager,
39
-		private IUserSession $userSession,
40
-		private IInitialStateService $initialState,
41
-		private JSDataService $jsDataService,
42
-	) {
43
-		$this->profileManager = $profileManager;
44
-	}
29
+    /**
30
+     * BeforeTemplateRenderedListener constructor.
31
+     *
32
+     * @param ProfileManager $profileManager
33
+     * @param IUserSession $userSession
34
+     * @param IInitialStateService $initialState
35
+     * @param JSDataService $jsDataService
36
+     */
37
+    public function __construct(
38
+        ProfileManager $profileManager,
39
+        private IUserSession $userSession,
40
+        private IInitialStateService $initialState,
41
+        private JSDataService $jsDataService,
42
+    ) {
43
+        $this->profileManager = $profileManager;
44
+    }
45 45
 
46
-	/**
47
-	 * @inheritDoc
48
-	 */
49
-	public function handle(Event $event): void {
50
-		$user = $this->userSession->getUser();
51
-		if ($user === null) {
52
-			return;
53
-		}
46
+    /**
47
+     * @inheritDoc
48
+     */
49
+    public function handle(Event $event): void {
50
+        $user = $this->userSession->getUser();
51
+        if ($user === null) {
52
+            return;
53
+        }
54 54
 
55
-		if (!($event instanceof BeforeTemplateRenderedEvent)) {
56
-			// Unrelated
57
-			return;
58
-		}
55
+        if (!($event instanceof BeforeTemplateRenderedEvent)) {
56
+            // Unrelated
57
+            return;
58
+        }
59 59
 
60
-		if (!$event->isLoggedIn() || $event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
61
-			return;
62
-		}
60
+        if (!$event->isLoggedIn() || $event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_USER) {
61
+            return;
62
+        }
63 63
 
64
-		$this->initialState->provideLazyInitialState(Application::APP_ID, 'status', function () {
65
-			return $this->jsDataService;
66
-		});
64
+        $this->initialState->provideLazyInitialState(Application::APP_ID, 'status', function () {
65
+            return $this->jsDataService;
66
+        });
67 67
 
68
-		$this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function () use ($user) {
69
-			return ['profileEnabled' => $this->profileManager->isProfileEnabled($user)];
70
-		});
68
+        $this->initialState->provideLazyInitialState(Application::APP_ID, 'profileEnabled', function () use ($user) {
69
+            return ['profileEnabled' => $this->profileManager->isProfileEnabled($user)];
70
+        });
71 71
 
72
-		Util::addScript('user_status', 'menu');
73
-		Util::addStyle('user_status', 'user-status-menu');
74
-	}
72
+        Util::addScript('user_status', 'menu');
73
+        Util::addStyle('user_status', 'user-status-menu');
74
+    }
75 75
 }
Please login to merge, or discard this patch.
lib/public/IRequestId.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@
 block discarded – undo
28 28
  * @since 24.0.0
29 29
  */
30 30
 interface IRequestId {
31
-	/**
32
-	 * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
33
-	 * If `mod_unique_id` is installed this value will be taken.
34
-	 *
35
-	 * @return string
36
-	 * @since 24.0.0
37
-	 */
38
-	public function getId(): string;
31
+    /**
32
+     * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
33
+     * If `mod_unique_id` is installed this value will be taken.
34
+     *
35
+     * @return string
36
+     * @since 24.0.0
37
+     */
38
+    public function getId(): string;
39 39
 }
Please login to merge, or discard this patch.
apps/settings/lib/Controller/AuthSettingsController.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		}
147 147
 
148 148
 		if (mb_strlen($name) > 128) {
149
-			$name = mb_substr($name, 0, 120) . '…';
149
+			$name = mb_substr($name, 0, 120).'…';
150 150
 		}
151 151
 
152 152
 		$token = $this->generateRandomDeviceToken();
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 		}
247 247
 
248 248
 		if (mb_strlen($name) > 128) {
249
-			$name = mb_substr($name, 0, 120) . '…';
249
+			$name = mb_substr($name, 0, 120).'…';
250 250
 		}
251 251
 
252 252
 		if ($token instanceof INamedToken && $name !== $currentName) {
Please login to merge, or discard this patch.
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -32,254 +32,254 @@
 block discarded – undo
32 32
 use Psr\Log\LoggerInterface;
33 33
 
34 34
 class AuthSettingsController extends Controller {
35
-	/** @var IProvider */
36
-	private $tokenProvider;
37
-
38
-	/** @var RemoteWipe */
39
-	private $remoteWipe;
40
-
41
-	/**
42
-	 * @param string $appName
43
-	 * @param IRequest $request
44
-	 * @param IProvider $tokenProvider
45
-	 * @param ISession $session
46
-	 * @param ISecureRandom $random
47
-	 * @param string|null $userId
48
-	 * @param IUserSession $userSession
49
-	 * @param IManager $activityManager
50
-	 * @param RemoteWipe $remoteWipe
51
-	 * @param LoggerInterface $logger
52
-	 */
53
-	public function __construct(
54
-		string $appName,
55
-		IRequest $request,
56
-		IProvider $tokenProvider,
57
-		private ISession $session,
58
-		private ISecureRandom $random,
59
-		private ?string $userId,
60
-		private IUserSession $userSession,
61
-		private IManager $activityManager,
62
-		RemoteWipe $remoteWipe,
63
-		private LoggerInterface $logger,
64
-	) {
65
-		parent::__construct($appName, $request);
66
-		$this->tokenProvider = $tokenProvider;
67
-		$this->remoteWipe = $remoteWipe;
68
-	}
69
-
70
-	/**
71
-	 * @NoSubAdminRequired
72
-	 *
73
-	 * @param string $name
74
-	 * @return JSONResponse
75
-	 */
76
-	#[NoAdminRequired]
77
-	#[PasswordConfirmationRequired]
78
-	public function create($name) {
79
-		if ($this->checkAppToken()) {
80
-			return $this->getServiceNotAvailableResponse();
81
-		}
82
-
83
-		try {
84
-			$sessionId = $this->session->getId();
85
-		} catch (SessionNotAvailableException $ex) {
86
-			return $this->getServiceNotAvailableResponse();
87
-		}
88
-		if ($this->userSession->getImpersonatingUserID() !== null) {
89
-			return $this->getServiceNotAvailableResponse();
90
-		}
91
-
92
-		try {
93
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
94
-			$loginName = $sessionToken->getLoginName();
95
-			try {
96
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
97
-			} catch (PasswordlessTokenException $ex) {
98
-				$password = null;
99
-			}
100
-		} catch (InvalidTokenException $ex) {
101
-			return $this->getServiceNotAvailableResponse();
102
-		}
103
-
104
-		if (mb_strlen($name) > 128) {
105
-			$name = mb_substr($name, 0, 120) . '…';
106
-		}
107
-
108
-		$token = $this->generateRandomDeviceToken();
109
-		$deviceToken = $this->tokenProvider->generateToken($token, $this->userId, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
110
-		$tokenData = $deviceToken->jsonSerialize();
111
-		$tokenData['canDelete'] = true;
112
-		$tokenData['canRename'] = true;
113
-
114
-		$this->publishActivity(Provider::APP_TOKEN_CREATED, $deviceToken->getId(), ['name' => $deviceToken->getName()]);
115
-
116
-		return new JSONResponse([
117
-			'token' => $token,
118
-			'loginName' => $loginName,
119
-			'deviceToken' => $tokenData,
120
-		]);
121
-	}
122
-
123
-	/**
124
-	 * @return JSONResponse
125
-	 */
126
-	private function getServiceNotAvailableResponse() {
127
-		$resp = new JSONResponse();
128
-		$resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
129
-		return $resp;
130
-	}
131
-
132
-	/**
133
-	 * Return a 25 digit device password
134
-	 *
135
-	 * Example: AbCdE-fGhJk-MnPqR-sTwXy-23456
136
-	 *
137
-	 * @return string
138
-	 */
139
-	private function generateRandomDeviceToken() {
140
-		$groups = [];
141
-		for ($i = 0; $i < 5; $i++) {
142
-			$groups[] = $this->random->generate(5, ISecureRandom::CHAR_HUMAN_READABLE);
143
-		}
144
-		return implode('-', $groups);
145
-	}
146
-
147
-	private function checkAppToken(): bool {
148
-		return $this->session->exists('app_password');
149
-	}
150
-
151
-	/**
152
-	 * @NoSubAdminRequired
153
-	 *
154
-	 * @param int $id
155
-	 * @return array|JSONResponse
156
-	 */
157
-	#[NoAdminRequired]
158
-	public function destroy($id) {
159
-		if ($this->checkAppToken()) {
160
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
161
-		}
162
-
163
-		try {
164
-			$token = $this->findTokenByIdAndUser($id);
165
-		} catch (WipeTokenException $e) {
166
-			//continue as we can destroy tokens in wipe
167
-			$token = $e->getToken();
168
-		} catch (InvalidTokenException $e) {
169
-			return new JSONResponse([], Http::STATUS_NOT_FOUND);
170
-		}
171
-
172
-		$this->tokenProvider->invalidateTokenById($this->userId, $token->getId());
173
-		$this->publishActivity(Provider::APP_TOKEN_DELETED, $token->getId(), ['name' => $token->getName()]);
174
-		return [];
175
-	}
176
-
177
-	/**
178
-	 * @NoSubAdminRequired
179
-	 *
180
-	 * @param int $id
181
-	 * @param array $scope
182
-	 * @param string $name
183
-	 * @return array|JSONResponse
184
-	 */
185
-	#[NoAdminRequired]
186
-	public function update($id, array $scope, string $name) {
187
-		if ($this->checkAppToken()) {
188
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
189
-		}
190
-
191
-		try {
192
-			$token = $this->findTokenByIdAndUser($id);
193
-		} catch (InvalidTokenException $e) {
194
-			return new JSONResponse([], Http::STATUS_NOT_FOUND);
195
-		}
196
-
197
-		$currentName = $token->getName();
198
-
199
-		if ($scope !== $token->getScopeAsArray()) {
200
-			$token->setScope([IToken::SCOPE_FILESYSTEM => $scope[IToken::SCOPE_FILESYSTEM]]);
201
-			$this->publishActivity($scope[IToken::SCOPE_FILESYSTEM] ? Provider::APP_TOKEN_FILESYSTEM_GRANTED : Provider::APP_TOKEN_FILESYSTEM_REVOKED, $token->getId(), ['name' => $currentName]);
202
-		}
203
-
204
-		if (mb_strlen($name) > 128) {
205
-			$name = mb_substr($name, 0, 120) . '…';
206
-		}
207
-
208
-		if ($token instanceof INamedToken && $name !== $currentName) {
209
-			$token->setName($name);
210
-			$this->publishActivity(Provider::APP_TOKEN_RENAMED, $token->getId(), ['name' => $currentName, 'newName' => $name]);
211
-		}
212
-
213
-		$this->tokenProvider->updateToken($token);
214
-		return [];
215
-	}
216
-
217
-	/**
218
-	 * @param string $subject
219
-	 * @param int $id
220
-	 * @param array $parameters
221
-	 */
222
-	private function publishActivity(string $subject, int $id, array $parameters = []): void {
223
-		$event = $this->activityManager->generateEvent();
224
-		$event->setApp('settings')
225
-			->setType('security')
226
-			->setAffectedUser($this->userId)
227
-			->setAuthor($this->userId)
228
-			->setSubject($subject, $parameters)
229
-			->setObject('app_token', $id, 'App Password');
230
-
231
-		try {
232
-			$this->activityManager->publish($event);
233
-		} catch (BadMethodCallException $e) {
234
-			$this->logger->warning('could not publish activity', ['exception' => $e]);
235
-		}
236
-	}
237
-
238
-	/**
239
-	 * Find a token by given id and check if uid for current session belongs to this token
240
-	 *
241
-	 * @param int $id
242
-	 * @return IToken
243
-	 * @throws InvalidTokenException
244
-	 */
245
-	private function findTokenByIdAndUser(int $id): IToken {
246
-		try {
247
-			$token = $this->tokenProvider->getTokenById($id);
248
-		} catch (ExpiredTokenException $e) {
249
-			$token = $e->getToken();
250
-		}
251
-		if ($token->getUID() !== $this->userId) {
252
-			/** @psalm-suppress DeprecatedClass We have to throw the OC version so both OC and OCP catches catch it */
253
-			throw new OcInvalidTokenException('This token does not belong to you!');
254
-		}
255
-		return $token;
256
-	}
257
-
258
-	/**
259
-	 * @NoSubAdminRequired
260
-	 *
261
-	 * @param int $id
262
-	 * @return JSONResponse
263
-	 * @throws InvalidTokenException
264
-	 * @throws ExpiredTokenException
265
-	 */
266
-	#[NoAdminRequired]
267
-	#[PasswordConfirmationRequired]
268
-	public function wipe(int $id): JSONResponse {
269
-		if ($this->checkAppToken()) {
270
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
271
-		}
272
-
273
-		try {
274
-			$token = $this->findTokenByIdAndUser($id);
275
-		} catch (InvalidTokenException $e) {
276
-			return new JSONResponse([], Http::STATUS_NOT_FOUND);
277
-		}
278
-
279
-		if (!$this->remoteWipe->markTokenForWipe($token)) {
280
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
281
-		}
282
-
283
-		return new JSONResponse([]);
284
-	}
35
+    /** @var IProvider */
36
+    private $tokenProvider;
37
+
38
+    /** @var RemoteWipe */
39
+    private $remoteWipe;
40
+
41
+    /**
42
+     * @param string $appName
43
+     * @param IRequest $request
44
+     * @param IProvider $tokenProvider
45
+     * @param ISession $session
46
+     * @param ISecureRandom $random
47
+     * @param string|null $userId
48
+     * @param IUserSession $userSession
49
+     * @param IManager $activityManager
50
+     * @param RemoteWipe $remoteWipe
51
+     * @param LoggerInterface $logger
52
+     */
53
+    public function __construct(
54
+        string $appName,
55
+        IRequest $request,
56
+        IProvider $tokenProvider,
57
+        private ISession $session,
58
+        private ISecureRandom $random,
59
+        private ?string $userId,
60
+        private IUserSession $userSession,
61
+        private IManager $activityManager,
62
+        RemoteWipe $remoteWipe,
63
+        private LoggerInterface $logger,
64
+    ) {
65
+        parent::__construct($appName, $request);
66
+        $this->tokenProvider = $tokenProvider;
67
+        $this->remoteWipe = $remoteWipe;
68
+    }
69
+
70
+    /**
71
+     * @NoSubAdminRequired
72
+     *
73
+     * @param string $name
74
+     * @return JSONResponse
75
+     */
76
+    #[NoAdminRequired]
77
+    #[PasswordConfirmationRequired]
78
+    public function create($name) {
79
+        if ($this->checkAppToken()) {
80
+            return $this->getServiceNotAvailableResponse();
81
+        }
82
+
83
+        try {
84
+            $sessionId = $this->session->getId();
85
+        } catch (SessionNotAvailableException $ex) {
86
+            return $this->getServiceNotAvailableResponse();
87
+        }
88
+        if ($this->userSession->getImpersonatingUserID() !== null) {
89
+            return $this->getServiceNotAvailableResponse();
90
+        }
91
+
92
+        try {
93
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
94
+            $loginName = $sessionToken->getLoginName();
95
+            try {
96
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
97
+            } catch (PasswordlessTokenException $ex) {
98
+                $password = null;
99
+            }
100
+        } catch (InvalidTokenException $ex) {
101
+            return $this->getServiceNotAvailableResponse();
102
+        }
103
+
104
+        if (mb_strlen($name) > 128) {
105
+            $name = mb_substr($name, 0, 120) . '…';
106
+        }
107
+
108
+        $token = $this->generateRandomDeviceToken();
109
+        $deviceToken = $this->tokenProvider->generateToken($token, $this->userId, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
110
+        $tokenData = $deviceToken->jsonSerialize();
111
+        $tokenData['canDelete'] = true;
112
+        $tokenData['canRename'] = true;
113
+
114
+        $this->publishActivity(Provider::APP_TOKEN_CREATED, $deviceToken->getId(), ['name' => $deviceToken->getName()]);
115
+
116
+        return new JSONResponse([
117
+            'token' => $token,
118
+            'loginName' => $loginName,
119
+            'deviceToken' => $tokenData,
120
+        ]);
121
+    }
122
+
123
+    /**
124
+     * @return JSONResponse
125
+     */
126
+    private function getServiceNotAvailableResponse() {
127
+        $resp = new JSONResponse();
128
+        $resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
129
+        return $resp;
130
+    }
131
+
132
+    /**
133
+     * Return a 25 digit device password
134
+     *
135
+     * Example: AbCdE-fGhJk-MnPqR-sTwXy-23456
136
+     *
137
+     * @return string
138
+     */
139
+    private function generateRandomDeviceToken() {
140
+        $groups = [];
141
+        for ($i = 0; $i < 5; $i++) {
142
+            $groups[] = $this->random->generate(5, ISecureRandom::CHAR_HUMAN_READABLE);
143
+        }
144
+        return implode('-', $groups);
145
+    }
146
+
147
+    private function checkAppToken(): bool {
148
+        return $this->session->exists('app_password');
149
+    }
150
+
151
+    /**
152
+     * @NoSubAdminRequired
153
+     *
154
+     * @param int $id
155
+     * @return array|JSONResponse
156
+     */
157
+    #[NoAdminRequired]
158
+    public function destroy($id) {
159
+        if ($this->checkAppToken()) {
160
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
161
+        }
162
+
163
+        try {
164
+            $token = $this->findTokenByIdAndUser($id);
165
+        } catch (WipeTokenException $e) {
166
+            //continue as we can destroy tokens in wipe
167
+            $token = $e->getToken();
168
+        } catch (InvalidTokenException $e) {
169
+            return new JSONResponse([], Http::STATUS_NOT_FOUND);
170
+        }
171
+
172
+        $this->tokenProvider->invalidateTokenById($this->userId, $token->getId());
173
+        $this->publishActivity(Provider::APP_TOKEN_DELETED, $token->getId(), ['name' => $token->getName()]);
174
+        return [];
175
+    }
176
+
177
+    /**
178
+     * @NoSubAdminRequired
179
+     *
180
+     * @param int $id
181
+     * @param array $scope
182
+     * @param string $name
183
+     * @return array|JSONResponse
184
+     */
185
+    #[NoAdminRequired]
186
+    public function update($id, array $scope, string $name) {
187
+        if ($this->checkAppToken()) {
188
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
189
+        }
190
+
191
+        try {
192
+            $token = $this->findTokenByIdAndUser($id);
193
+        } catch (InvalidTokenException $e) {
194
+            return new JSONResponse([], Http::STATUS_NOT_FOUND);
195
+        }
196
+
197
+        $currentName = $token->getName();
198
+
199
+        if ($scope !== $token->getScopeAsArray()) {
200
+            $token->setScope([IToken::SCOPE_FILESYSTEM => $scope[IToken::SCOPE_FILESYSTEM]]);
201
+            $this->publishActivity($scope[IToken::SCOPE_FILESYSTEM] ? Provider::APP_TOKEN_FILESYSTEM_GRANTED : Provider::APP_TOKEN_FILESYSTEM_REVOKED, $token->getId(), ['name' => $currentName]);
202
+        }
203
+
204
+        if (mb_strlen($name) > 128) {
205
+            $name = mb_substr($name, 0, 120) . '…';
206
+        }
207
+
208
+        if ($token instanceof INamedToken && $name !== $currentName) {
209
+            $token->setName($name);
210
+            $this->publishActivity(Provider::APP_TOKEN_RENAMED, $token->getId(), ['name' => $currentName, 'newName' => $name]);
211
+        }
212
+
213
+        $this->tokenProvider->updateToken($token);
214
+        return [];
215
+    }
216
+
217
+    /**
218
+     * @param string $subject
219
+     * @param int $id
220
+     * @param array $parameters
221
+     */
222
+    private function publishActivity(string $subject, int $id, array $parameters = []): void {
223
+        $event = $this->activityManager->generateEvent();
224
+        $event->setApp('settings')
225
+            ->setType('security')
226
+            ->setAffectedUser($this->userId)
227
+            ->setAuthor($this->userId)
228
+            ->setSubject($subject, $parameters)
229
+            ->setObject('app_token', $id, 'App Password');
230
+
231
+        try {
232
+            $this->activityManager->publish($event);
233
+        } catch (BadMethodCallException $e) {
234
+            $this->logger->warning('could not publish activity', ['exception' => $e]);
235
+        }
236
+    }
237
+
238
+    /**
239
+     * Find a token by given id and check if uid for current session belongs to this token
240
+     *
241
+     * @param int $id
242
+     * @return IToken
243
+     * @throws InvalidTokenException
244
+     */
245
+    private function findTokenByIdAndUser(int $id): IToken {
246
+        try {
247
+            $token = $this->tokenProvider->getTokenById($id);
248
+        } catch (ExpiredTokenException $e) {
249
+            $token = $e->getToken();
250
+        }
251
+        if ($token->getUID() !== $this->userId) {
252
+            /** @psalm-suppress DeprecatedClass We have to throw the OC version so both OC and OCP catches catch it */
253
+            throw new OcInvalidTokenException('This token does not belong to you!');
254
+        }
255
+        return $token;
256
+    }
257
+
258
+    /**
259
+     * @NoSubAdminRequired
260
+     *
261
+     * @param int $id
262
+     * @return JSONResponse
263
+     * @throws InvalidTokenException
264
+     * @throws ExpiredTokenException
265
+     */
266
+    #[NoAdminRequired]
267
+    #[PasswordConfirmationRequired]
268
+    public function wipe(int $id): JSONResponse {
269
+        if ($this->checkAppToken()) {
270
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
271
+        }
272
+
273
+        try {
274
+            $token = $this->findTokenByIdAndUser($id);
275
+        } catch (InvalidTokenException $e) {
276
+            return new JSONResponse([], Http::STATUS_NOT_FOUND);
277
+        }
278
+
279
+        if (!$this->remoteWipe->markTokenForWipe($token)) {
280
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
281
+        }
282
+
283
+        return new JSONResponse([]);
284
+    }
285 285
 }
Please login to merge, or discard this patch.
lib/public/Files/Events/InvalidateMountCacheEvent.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -32,24 +32,24 @@
 block discarded – undo
32 32
  * @since 24.0.0
33 33
  */
34 34
 class InvalidateMountCacheEvent extends Event {
35
-	private ?IUser $user;
35
+    private ?IUser $user;
36 36
 
37
-	/**
38
-	 * @param IUser|null $user user
39
-	 *
40
-	 * @since 24.0.0
41
-	 */
42
-	public function __construct(?IUser $user) {
43
-		parent::__construct();
44
-		$this->user = $user;
45
-	}
37
+    /**
38
+     * @param IUser|null $user user
39
+     *
40
+     * @since 24.0.0
41
+     */
42
+    public function __construct(?IUser $user) {
43
+        parent::__construct();
44
+        $this->user = $user;
45
+    }
46 46
 
47
-	/**
48
-	 * @return IUser|null user
49
-	 *
50
-	 * @since 24.0.0
51
-	 */
52
-	public function getUser(): ?IUser {
53
-		return $this->user;
54
-	}
47
+    /**
48
+     * @return IUser|null user
49
+     *
50
+     * @since 24.0.0
51
+     */
52
+    public function getUser(): ?IUser {
53
+        return $this->user;
54
+    }
55 55
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Migration/Version010402Date20190107124745.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -32,22 +32,22 @@
 block discarded – undo
32 32
 
33 33
 class Version010402Date20190107124745 extends SimpleMigrationStep {
34 34
 
35
-	/**
36
-	 * @param IOutput $output
37
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
-	 * @param array $options
39
-	 * @return null|ISchemaWrapper
40
-	 */
41
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
42
-		/** @var ISchemaWrapper $schema */
43
-		$schema = $schemaClosure();
35
+    /**
36
+     * @param IOutput $output
37
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
+     * @param array $options
39
+     * @return null|ISchemaWrapper
40
+     */
41
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
42
+        /** @var ISchemaWrapper $schema */
43
+        $schema = $schemaClosure();
44 44
 
45
-		// During an ownCloud migration, the client_identifier column identifier might not exist yet.
46
-		if ($schema->getTable('oauth2_clients')->hasColumn('client_identifier')) {
47
-			$table = $schema->getTable('oauth2_clients');
48
-			$table->dropIndex('oauth2_client_id_idx');
49
-			$table->addUniqueIndex(['client_identifier'], 'oauth2_client_id_idx');
50
-			return $schema;
51
-		}
52
-	}
45
+        // During an ownCloud migration, the client_identifier column identifier might not exist yet.
46
+        if ($schema->getTable('oauth2_clients')->hasColumn('client_identifier')) {
47
+            $table = $schema->getTable('oauth2_clients');
48
+            $table->dropIndex('oauth2_client_id_idx');
49
+            $table->addUniqueIndex(['client_identifier'], 'oauth2_client_id_idx');
50
+            return $schema;
51
+        }
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/public/DB/QueryBuilder/IFunctionBuilder.php 1 patch
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -30,162 +30,162 @@
 block discarded – undo
30 30
  * @since 12.0.0
31 31
  */
32 32
 interface IFunctionBuilder {
33
-	/**
34
-	 * Calculates the MD5 hash of a given input
35
-	 *
36
-	 * @param string|ILiteral|IParameter|IQueryFunction $input The input to be hashed
37
-	 *
38
-	 * @return IQueryFunction
39
-	 * @since 12.0.0
40
-	 */
41
-	public function md5($input): IQueryFunction;
33
+    /**
34
+     * Calculates the MD5 hash of a given input
35
+     *
36
+     * @param string|ILiteral|IParameter|IQueryFunction $input The input to be hashed
37
+     *
38
+     * @return IQueryFunction
39
+     * @since 12.0.0
40
+     */
41
+    public function md5($input): IQueryFunction;
42 42
 
43
-	/**
44
-	 * Combines two input strings
45
-	 *
46
-	 * @param string|ILiteral|IParameter|IQueryFunction $x Expressions or literal strings
47
-	 * @param string|ILiteral|IParameter|IQueryFunction ...$exprs Expressions or literal strings
48
-	 *
49
-	 * @return IQueryFunction
50
-	 * @since 12.0.0
51
-	 */
52
-	public function concat($x, ...$expr): IQueryFunction;
43
+    /**
44
+     * Combines two input strings
45
+     *
46
+     * @param string|ILiteral|IParameter|IQueryFunction $x Expressions or literal strings
47
+     * @param string|ILiteral|IParameter|IQueryFunction ...$exprs Expressions or literal strings
48
+     *
49
+     * @return IQueryFunction
50
+     * @since 12.0.0
51
+     */
52
+    public function concat($x, ...$expr): IQueryFunction;
53 53
 
54
-	/**
55
-	 * Returns a string which is the concatenation of all non-NULL values of X
56
-	 *
57
-	 * Usage examples:
58
-	 *
59
-	 * groupConcat('column') -- with comma as separator (default separator)
60
-	 *
61
-	 * groupConcat('column', ';') -- with different separator
62
-	 *
63
-	 * @param string|IQueryFunction $expr The expression to group
64
-	 * @param string|null $separator The separator
65
-	 * @return IQueryFunction
66
-	 * @since 24.0.0
67
-	 */
68
-	public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
54
+    /**
55
+     * Returns a string which is the concatenation of all non-NULL values of X
56
+     *
57
+     * Usage examples:
58
+     *
59
+     * groupConcat('column') -- with comma as separator (default separator)
60
+     *
61
+     * groupConcat('column', ';') -- with different separator
62
+     *
63
+     * @param string|IQueryFunction $expr The expression to group
64
+     * @param string|null $separator The separator
65
+     * @return IQueryFunction
66
+     * @since 24.0.0
67
+     */
68
+    public function groupConcat($expr, ?string $separator = ','): IQueryFunction;
69 69
 
70
-	/**
71
-	 * Takes a substring from the input string
72
-	 *
73
-	 * @param string|ILiteral|IParameter|IQueryFunction $input The input string
74
-	 * @param string|ILiteral|IParameter|IQueryFunction $start The start of the substring, note that counting starts at 1
75
-	 * @param null|ILiteral|IParameter|IQueryFunction $length The length of the substring
76
-	 *
77
-	 * @return IQueryFunction
78
-	 * @since 12.0.0
79
-	 */
80
-	public function substring($input, $start, $length = null): IQueryFunction;
70
+    /**
71
+     * Takes a substring from the input string
72
+     *
73
+     * @param string|ILiteral|IParameter|IQueryFunction $input The input string
74
+     * @param string|ILiteral|IParameter|IQueryFunction $start The start of the substring, note that counting starts at 1
75
+     * @param null|ILiteral|IParameter|IQueryFunction $length The length of the substring
76
+     *
77
+     * @return IQueryFunction
78
+     * @since 12.0.0
79
+     */
80
+    public function substring($input, $start, $length = null): IQueryFunction;
81 81
 
82
-	/**
83
-	 * Takes the sum of all rows in a column
84
-	 *
85
-	 * @param string|ILiteral|IParameter|IQueryFunction $field the column to sum
86
-	 *
87
-	 * @return IQueryFunction
88
-	 * @since 12.0.0
89
-	 */
90
-	public function sum($field): IQueryFunction;
82
+    /**
83
+     * Takes the sum of all rows in a column
84
+     *
85
+     * @param string|ILiteral|IParameter|IQueryFunction $field the column to sum
86
+     *
87
+     * @return IQueryFunction
88
+     * @since 12.0.0
89
+     */
90
+    public function sum($field): IQueryFunction;
91 91
 
92
-	/**
93
-	 * Transforms a string field or value to lower case
94
-	 *
95
-	 * @param string|ILiteral|IParameter|IQueryFunction $field
96
-	 * @return IQueryFunction
97
-	 * @since 14.0.0
98
-	 */
99
-	public function lower($field): IQueryFunction;
92
+    /**
93
+     * Transforms a string field or value to lower case
94
+     *
95
+     * @param string|ILiteral|IParameter|IQueryFunction $field
96
+     * @return IQueryFunction
97
+     * @since 14.0.0
98
+     */
99
+    public function lower($field): IQueryFunction;
100 100
 
101
-	/**
102
-	 * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
103
-	 * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
104
-	 * @return IQueryFunction
105
-	 * @since 14.0.0
106
-	 */
107
-	public function add($x, $y): IQueryFunction;
101
+    /**
102
+     * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
103
+     * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
104
+     * @return IQueryFunction
105
+     * @since 14.0.0
106
+     */
107
+    public function add($x, $y): IQueryFunction;
108 108
 
109
-	/**
110
-	 * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
111
-	 * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
112
-	 * @return IQueryFunction
113
-	 * @since 14.0.0
114
-	 */
115
-	public function subtract($x, $y): IQueryFunction;
109
+    /**
110
+     * @param string|ILiteral|IParameter|IQueryFunction $x The first input field or number
111
+     * @param string|ILiteral|IParameter|IQueryFunction $y The second input field or number
112
+     * @return IQueryFunction
113
+     * @since 14.0.0
114
+     */
115
+    public function subtract($x, $y): IQueryFunction;
116 116
 
117
-	/**
118
-	 * @param string|ILiteral|IParameter|IQueryFunction $count The input to be counted
119
-	 * @param string $alias Alias for the counter
120
-	 *
121
-	 * @return IQueryFunction
122
-	 * @since 14.0.0
123
-	 */
124
-	public function count($count = '', $alias = ''): IQueryFunction;
117
+    /**
118
+     * @param string|ILiteral|IParameter|IQueryFunction $count The input to be counted
119
+     * @param string $alias Alias for the counter
120
+     *
121
+     * @return IQueryFunction
122
+     * @since 14.0.0
123
+     */
124
+    public function count($count = '', $alias = ''): IQueryFunction;
125 125
 
126
-	/**
127
-	 * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
128
-	 * @param string $alias Alias for the length
129
-	 *
130
-	 * @return IQueryFunction
131
-	 * @since 24.0.0
132
-	 */
133
-	public function octetLength($field, $alias = ''): IQueryFunction;
126
+    /**
127
+     * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
128
+     * @param string $alias Alias for the length
129
+     *
130
+     * @return IQueryFunction
131
+     * @since 24.0.0
132
+     */
133
+    public function octetLength($field, $alias = ''): IQueryFunction;
134 134
 
135
-	/**
136
-	 * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
137
-	 * @param string $alias Alias for the length
138
-	 *
139
-	 * @return IQueryFunction
140
-	 * @since 24.0.0
141
-	 */
142
-	public function charLength($field, $alias = ''): IQueryFunction;
135
+    /**
136
+     * @param string|ILiteral|IParameter|IQueryFunction $field The input to be measured
137
+     * @param string $alias Alias for the length
138
+     *
139
+     * @return IQueryFunction
140
+     * @since 24.0.0
141
+     */
142
+    public function charLength($field, $alias = ''): IQueryFunction;
143 143
 
144
-	/**
145
-	 * Takes the maximum of all rows in a column
146
-	 *
147
-	 * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead
148
-	 *
149
-	 * @param string|ILiteral|IParameter|IQueryFunction $field the column to maximum
150
-	 *
151
-	 * @return IQueryFunction
152
-	 * @since 18.0.0
153
-	 */
154
-	public function max($field): IQueryFunction;
144
+    /**
145
+     * Takes the maximum of all rows in a column
146
+     *
147
+     * If you want to get the maximum value of multiple columns in the same row, use `greatest` instead
148
+     *
149
+     * @param string|ILiteral|IParameter|IQueryFunction $field the column to maximum
150
+     *
151
+     * @return IQueryFunction
152
+     * @since 18.0.0
153
+     */
154
+    public function max($field): IQueryFunction;
155 155
 
156
-	/**
157
-	 * Takes the minimum of all rows in a column
158
-	 *
159
-	 * If you want to get the minimum value of multiple columns in the same row, use `least` instead
160
-	 *
161
-	 * @param string|ILiteral|IParameter|IQueryFunction $field the column to minimum
162
-	 *
163
-	 * @return IQueryFunction
164
-	 * @since 18.0.0
165
-	 */
166
-	public function min($field): IQueryFunction;
156
+    /**
157
+     * Takes the minimum of all rows in a column
158
+     *
159
+     * If you want to get the minimum value of multiple columns in the same row, use `least` instead
160
+     *
161
+     * @param string|ILiteral|IParameter|IQueryFunction $field the column to minimum
162
+     *
163
+     * @return IQueryFunction
164
+     * @since 18.0.0
165
+     */
166
+    public function min($field): IQueryFunction;
167 167
 
168
-	/**
169
-	 * Takes the maximum of multiple values
170
-	 *
171
-	 * If you want to get the maximum value of all rows in a column, use `max` instead
172
-	 *
173
-	 * @param string|ILiteral|IParameter|IQueryFunction $x
174
-	 * @param string|ILiteral|IParameter|IQueryFunction $y
175
-	 * @return IQueryFunction
176
-	 * @since 18.0.0
177
-	 */
178
-	public function greatest($x, $y): IQueryFunction;
168
+    /**
169
+     * Takes the maximum of multiple values
170
+     *
171
+     * If you want to get the maximum value of all rows in a column, use `max` instead
172
+     *
173
+     * @param string|ILiteral|IParameter|IQueryFunction $x
174
+     * @param string|ILiteral|IParameter|IQueryFunction $y
175
+     * @return IQueryFunction
176
+     * @since 18.0.0
177
+     */
178
+    public function greatest($x, $y): IQueryFunction;
179 179
 
180
-	/**
181
-	 * Takes the minimum of multiple values
182
-	 *
183
-	 * If you want to get the minimum value of all rows in a column, use `min` instead
184
-	 *
185
-	 * @param string|ILiteral|IParameter|IQueryFunction $x
186
-	 * @param string|ILiteral|IParameter|IQueryFunction $y
187
-	 * @return IQueryFunction
188
-	 * @since 18.0.0
189
-	 */
190
-	public function least($x, $y): IQueryFunction;
180
+    /**
181
+     * Takes the minimum of multiple values
182
+     *
183
+     * If you want to get the minimum value of all rows in a column, use `min` instead
184
+     *
185
+     * @param string|ILiteral|IParameter|IQueryFunction $x
186
+     * @param string|ILiteral|IParameter|IQueryFunction $y
187
+     * @return IQueryFunction
188
+     * @since 18.0.0
189
+     */
190
+    public function least($x, $y): IQueryFunction;
191 191
 }
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	}
48 48
 
49 49
 	public function md5($input): IQueryFunction {
50
-		return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')');
50
+		return new QueryFunction('MD5('.$this->helper->quoteColumnName($input).')');
51 51
 	}
52 52
 
53 53
 	public function concat($x, ...$expr): IQueryFunction {
@@ -61,64 +61,64 @@  discard block
 block discarded – undo
61 61
 
62 62
 	public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
63 63
 		$separator = $this->connection->quote($separator);
64
-		return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
64
+		return new QueryFunction('GROUP_CONCAT('.$this->helper->quoteColumnName($expr).' SEPARATOR '.$separator.')');
65 65
 	}
66 66
 
67 67
 	public function substring($input, $start, $length = null): IQueryFunction {
68 68
 		if ($length) {
69
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
69
+			return new QueryFunction('SUBSTR('.$this->helper->quoteColumnName($input).', '.$this->helper->quoteColumnName($start).', '.$this->helper->quoteColumnName($length).')');
70 70
 		} else {
71
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
71
+			return new QueryFunction('SUBSTR('.$this->helper->quoteColumnName($input).', '.$this->helper->quoteColumnName($start).')');
72 72
 		}
73 73
 	}
74 74
 
75 75
 	public function sum($field): IQueryFunction {
76
-		return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
76
+		return new QueryFunction('SUM('.$this->helper->quoteColumnName($field).')');
77 77
 	}
78 78
 
79 79
 	public function lower($field): IQueryFunction {
80
-		return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')');
80
+		return new QueryFunction('LOWER('.$this->helper->quoteColumnName($field).')');
81 81
 	}
82 82
 
83 83
 	public function add($x, $y): IQueryFunction {
84
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y));
84
+		return new QueryFunction($this->helper->quoteColumnName($x).' + '.$this->helper->quoteColumnName($y));
85 85
 	}
86 86
 
87 87
 	public function subtract($x, $y): IQueryFunction {
88
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
88
+		return new QueryFunction($this->helper->quoteColumnName($x).' - '.$this->helper->quoteColumnName($y));
89 89
 	}
90 90
 
91 91
 	public function count($count = '', $alias = ''): IQueryFunction {
92
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
92
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
93 93
 		$quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
94
-		return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
94
+		return new QueryFunction('COUNT('.$quotedName.')'.$alias);
95 95
 	}
96 96
 
97 97
 	public function octetLength($field, $alias = ''): IQueryFunction {
98
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
98
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
99 99
 		$quotedName = $this->helper->quoteColumnName($field);
100
-		return new QueryFunction('OCTET_LENGTH(' . $quotedName . ')' . $alias);
100
+		return new QueryFunction('OCTET_LENGTH('.$quotedName.')'.$alias);
101 101
 	}
102 102
 
103 103
 	public function charLength($field, $alias = ''): IQueryFunction {
104
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
104
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
105 105
 		$quotedName = $this->helper->quoteColumnName($field);
106
-		return new QueryFunction('CHAR_LENGTH(' . $quotedName . ')' . $alias);
106
+		return new QueryFunction('CHAR_LENGTH('.$quotedName.')'.$alias);
107 107
 	}
108 108
 
109 109
 	public function max($field): IQueryFunction {
110
-		return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
110
+		return new QueryFunction('MAX('.$this->helper->quoteColumnName($field).')');
111 111
 	}
112 112
 
113 113
 	public function min($field): IQueryFunction {
114
-		return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')');
114
+		return new QueryFunction('MIN('.$this->helper->quoteColumnName($field).')');
115 115
 	}
116 116
 
117 117
 	public function greatest($x, $y): IQueryFunction {
118
-		return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
118
+		return new QueryFunction('GREATEST('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')');
119 119
 	}
120 120
 
121 121
 	public function least($x, $y): IQueryFunction {
122
-		return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
122
+		return new QueryFunction('LEAST('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')');
123 123
 	}
124 124
 }
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -14,94 +14,94 @@
 block discarded – undo
14 14
 use OCP\IDBConnection;
15 15
 
16 16
 class FunctionBuilder implements IFunctionBuilder {
17
-	/** @var IDBConnection|Connection */
18
-	protected $connection;
19
-
20
-	/** @var IQueryBuilder */
21
-	protected $queryBuilder;
22
-
23
-	/** @var QuoteHelper */
24
-	protected $helper;
25
-
26
-	public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder, QuoteHelper $helper) {
27
-		$this->connection = $connection;
28
-		$this->queryBuilder = $queryBuilder;
29
-		$this->helper = $helper;
30
-	}
31
-
32
-	public function md5($input): IQueryFunction {
33
-		return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')');
34
-	}
35
-
36
-	public function concat($x, ...$expr): IQueryFunction {
37
-		$args = func_get_args();
38
-		$list = [];
39
-		foreach ($args as $item) {
40
-			$list[] = $this->helper->quoteColumnName($item);
41
-		}
42
-		return new QueryFunction(sprintf('CONCAT(%s)', implode(', ', $list)));
43
-	}
44
-
45
-	public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
46
-		$separator = $this->connection->quote($separator);
47
-		return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
48
-	}
49
-
50
-	public function substring($input, $start, $length = null): IQueryFunction {
51
-		if ($length) {
52
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
53
-		} else {
54
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
55
-		}
56
-	}
57
-
58
-	public function sum($field): IQueryFunction {
59
-		return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
60
-	}
61
-
62
-	public function lower($field): IQueryFunction {
63
-		return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')');
64
-	}
65
-
66
-	public function add($x, $y): IQueryFunction {
67
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y));
68
-	}
69
-
70
-	public function subtract($x, $y): IQueryFunction {
71
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
72
-	}
73
-
74
-	public function count($count = '', $alias = ''): IQueryFunction {
75
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
76
-		$quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
77
-		return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
78
-	}
79
-
80
-	public function octetLength($field, $alias = ''): IQueryFunction {
81
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
82
-		$quotedName = $this->helper->quoteColumnName($field);
83
-		return new QueryFunction('OCTET_LENGTH(' . $quotedName . ')' . $alias);
84
-	}
85
-
86
-	public function charLength($field, $alias = ''): IQueryFunction {
87
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
88
-		$quotedName = $this->helper->quoteColumnName($field);
89
-		return new QueryFunction('CHAR_LENGTH(' . $quotedName . ')' . $alias);
90
-	}
91
-
92
-	public function max($field): IQueryFunction {
93
-		return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
94
-	}
95
-
96
-	public function min($field): IQueryFunction {
97
-		return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')');
98
-	}
99
-
100
-	public function greatest($x, $y): IQueryFunction {
101
-		return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
102
-	}
103
-
104
-	public function least($x, $y): IQueryFunction {
105
-		return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
106
-	}
17
+    /** @var IDBConnection|Connection */
18
+    protected $connection;
19
+
20
+    /** @var IQueryBuilder */
21
+    protected $queryBuilder;
22
+
23
+    /** @var QuoteHelper */
24
+    protected $helper;
25
+
26
+    public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder, QuoteHelper $helper) {
27
+        $this->connection = $connection;
28
+        $this->queryBuilder = $queryBuilder;
29
+        $this->helper = $helper;
30
+    }
31
+
32
+    public function md5($input): IQueryFunction {
33
+        return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')');
34
+    }
35
+
36
+    public function concat($x, ...$expr): IQueryFunction {
37
+        $args = func_get_args();
38
+        $list = [];
39
+        foreach ($args as $item) {
40
+            $list[] = $this->helper->quoteColumnName($item);
41
+        }
42
+        return new QueryFunction(sprintf('CONCAT(%s)', implode(', ', $list)));
43
+    }
44
+
45
+    public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
46
+        $separator = $this->connection->quote($separator);
47
+        return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
48
+    }
49
+
50
+    public function substring($input, $start, $length = null): IQueryFunction {
51
+        if ($length) {
52
+            return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
53
+        } else {
54
+            return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
55
+        }
56
+    }
57
+
58
+    public function sum($field): IQueryFunction {
59
+        return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
60
+    }
61
+
62
+    public function lower($field): IQueryFunction {
63
+        return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')');
64
+    }
65
+
66
+    public function add($x, $y): IQueryFunction {
67
+        return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y));
68
+    }
69
+
70
+    public function subtract($x, $y): IQueryFunction {
71
+        return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
72
+    }
73
+
74
+    public function count($count = '', $alias = ''): IQueryFunction {
75
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
76
+        $quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
77
+        return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
78
+    }
79
+
80
+    public function octetLength($field, $alias = ''): IQueryFunction {
81
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
82
+        $quotedName = $this->helper->quoteColumnName($field);
83
+        return new QueryFunction('OCTET_LENGTH(' . $quotedName . ')' . $alias);
84
+    }
85
+
86
+    public function charLength($field, $alias = ''): IQueryFunction {
87
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
88
+        $quotedName = $this->helper->quoteColumnName($field);
89
+        return new QueryFunction('CHAR_LENGTH(' . $quotedName . ')' . $alias);
90
+    }
91
+
92
+    public function max($field): IQueryFunction {
93
+        return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
94
+    }
95
+
96
+    public function min($field): IQueryFunction {
97
+        return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')');
98
+    }
99
+
100
+    public function greatest($x, $y): IQueryFunction {
101
+        return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
102
+    }
103
+
104
+    public function least($x, $y): IQueryFunction {
105
+        return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
106
+    }
107 107
 }
Please login to merge, or discard this patch.