Test Failed
Push — master ( e34111...40eb7a )
by Daniel
21:12
created

Application   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 22.22%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 8
eloc 22
c 7
b 0
f 0
dl 0
loc 70
ccs 6
cts 27
cp 0.2222
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerHooks() 0 3 1
A __construct() 0 3 1
A getAppPath() 0 8 2
A registerExternalStorage() 0 12 2
A getAppWebPath() 0 8 2
1
<?php
2
/**
3
 * CMS Pico - Create websites using Pico CMS for Nextcloud.
4
 *
5
 * @copyright Copyright (c) 2017, Maxence Lange (<[email protected]>)
6
 * @copyright Copyright (c) 2019, Daniel Rudolf (<[email protected]>)
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 */
23
24
declare(strict_types=1);
25
26
namespace OCA\CMSPico\AppInfo;
27
28
use OCA\CMSPico\ExternalStorage\BackendProvider;
29
use OCA\Files_External\Service\BackendService;
30
use OCP\App\AppPathNotFoundException;
31
use OCP\App\IAppManager;
32
use OCP\AppFramework\App;
33
use OCP\EventDispatcher\Event;
34
use OCP\EventDispatcher\IEventDispatcher;
35
use OCP\Util;
36
37
class Application extends App
38
{
39
	/** @var string */
40
	public const APP_NAME = 'cms_pico';
41
42
	/**
43
	 * @param array $params
44
	 */
45 12
	public function __construct(array $params = [])
46
	{
47 12
		parent::__construct(self::APP_NAME, $params);
48 12
	}
49
50
	/**
51
	 * Register hooks.
52
	 */
53
	public function registerHooks(): void
54
	{
55
		Util::connectHook('OC_User', 'post_deleteUser', '\OCA\CMSPico\Hooks\UserHooks', 'onUserDeleted');
56
	}
57
58
	/**
59
	 * Registers a unencrypted storage backend.
60
	 */
61
	public function registerExternalStorage(): void
62
	{
63
		/** @var IEventDispatcher $eventDispatcher */
64
		$eventDispatcher = \OC::$server->query(IEventDispatcher::class);
65
		$eventDispatcher->addListener(
66
			'OCA\\Files_External::loadAdditionalBackends',
67
			function (Event $event) {
68
				$encryptionManager = \OC::$server->getEncryptionManager();
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getEncryptionManager() 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
				$encryptionManager = /** @scrutinizer ignore-deprecated */ \OC::$server->getEncryptionManager();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
69
				if ($encryptionManager->isEnabled()) {
70
					/** @var BackendService $backendService */
71
					$backendService = \OC::$server->query(BackendService::class);
72
					$backendService->registerBackendProvider(new BackendProvider());
73
				}
74
			}
75
		);
76
	}
77
78
	/**
79
	 * Returns the absolute path to this app.
80
	 *
81
	 * @return string
82
	 */
83 2
	public static function getAppPath(): string
84
	{
85
		try {
86
			/** @var IAppManager $appManager */
87 2
			$appManager = \OC::$server->getAppManager();
88 2
			return $appManager->getAppPath(self::APP_NAME);
89
		} catch (AppPathNotFoundException $e) {
90
			return '';
91
		}
92
	}
93
94
	/**
95
	 * Returns the absolute web path to this app.
96
	 *
97
	 * @return string
98
	 */
99
	public static function getAppWebPath(): string
100
	{
101
		try {
102
			/** @var IAppManager $appManager */
103
			$appManager = \OC::$server->getAppManager();
104
			return $appManager->getAppWebPath(self::APP_NAME);
105
		} catch (AppPathNotFoundException $e) {
106
			return '';
107
		}
108
	}
109
}
110