Passed
Push — master ( 24ec4a...f04f93 )
by Roeland
13:26 queued 11s
created

DashboardController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2020 Julius Härtl <[email protected]>
7
 *
8
 * @author Julius Härtl <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Dashboard\Controller;
28
29
use OCA\Viewer\Event\LoadViewer;
0 ignored issues
show
Bug introduced by
The type OCA\Viewer\Event\LoadViewer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use OCP\AppFramework\Controller;
31
use OCP\AppFramework\Http\TemplateResponse;
32
use OCP\Dashboard\IManager;
33
use OCP\Dashboard\IPanel;
34
use OCP\Dashboard\RegisterPanelEvent;
35
use OCP\EventDispatcher\IEventDispatcher;
36
use OCP\IInitialStateService;
37
use OCP\IRequest;
38
39
class DashboardController extends Controller {
40
41
	/** @var IInitialStateService */
42
	private $inititalStateService;
43
	/** @var IEventDispatcher */
44
	private $eventDispatcher;
45
	/** @var IManager */
46
	private $dashboardManager;
47
48
	public function __construct(
49
		string $appName,
50
		IRequest $request,
51
		IInitialStateService $initialStateService,
52
		IEventDispatcher $eventDispatcher,
53
		IManager $dashboardManager
54
	) {
55
		parent::__construct($appName, $request);
56
57
		$this->inititalStateService = $initialStateService;
58
		$this->eventDispatcher = $eventDispatcher;
59
		$this->dashboardManager = $dashboardManager;
60
	}
61
62
	/**
63
	 * @NoCSRFRequired
64
	 * @NoAdminRequired
65
	 * @return TemplateResponse
66
	 */
67
	public function index(): TemplateResponse {
68
		$this->eventDispatcher->dispatchTyped(new RegisterPanelEvent($this->dashboardManager));
0 ignored issues
show
Deprecated Code introduced by
The class OCP\Dashboard\RegisterPanelEvent has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
		$this->eventDispatcher->dispatchTyped(/** @scrutinizer ignore-deprecated */ new RegisterPanelEvent($this->dashboardManager));
Loading history...
69
70
		$dashboardManager = $this->dashboardManager;
71
		$panels = array_map(function (IPanel $panel) {
72
			return [
73
				'id' => $panel->getId(),
74
				'title' => $panel->getTitle(),
75
				'iconClass' => $panel->getIconClass(),
76
				'url' => $panel->getUrl()
77
			];
78
		}, $dashboardManager->getPanels());
79
		$this->inititalStateService->provideInitialState('dashboard', 'panels', $panels);
80
81
		if (class_exists(LoadViewer::class)) {
82
			$this->eventDispatcher->dispatchTyped(new LoadViewer());
83
		}
84
85
		return new TemplateResponse('dashboard', 'index');
86
	}
87
}
88