Completed
Push — master ( 8a6dbe...c3633d )
by Julius
05:45 queued 01:56
created

DefaultBoardMiddleware   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A beforeController() 0 9 5
1
<?php
2
/**
3
 * @copyright Copyright (c) 2020 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Deck\Middleware;
25
26
use OCA\Deck\Service\DefaultBoardService;
27
use OCA\Deck\Service\PermissionService;
28
use OCP\AppFramework\Middleware;
29
use OCP\IL10N;
30
use OCP\ILogger;
31
32
class DefaultBoardMiddleware extends Middleware {
33
34
	/** @var ILogger */
35
	private $logger;
36
	/** @var IL10N */
37
	private $l10n;
38
	/** @var DefaultBoardService */
39
	private $defaultBoardService;
40
	/** @var PermissionService */
41
	private $permissionService;
42
	/** @var string|null */
43
	private $userId;
44
45
	public function __construct(ILogger $logger, IL10N $l10n, DefaultBoardService $defaultBoardService, PermissionService $permissionService, $userId) {
46
		$this->logger = $logger;
47
		$this->l10n = $l10n;
48
		$this->defaultBoardService = $defaultBoardService;
49
		$this->permissionService = $permissionService;
50
		$this->userId = $userId;
51
	}
52
53
	public function beforeController($controller, $methodName) {
54
		try {
55
			if ($this->userId !== null && $this->defaultBoardService->checkFirstRun($this->userId) && $this->permissionService->canCreate()) {
56
				$this->defaultBoardService->createDefaultBoard($this->l10n->t('Personal'), $this->userId, '0087C5');
57
			}
58
		} catch (\Throwable $e) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
59
			$this->logger->logException($e);
60
		}
61
	}
62
63
}
64