Test Setup Failed
Push — master ( ad840f...924e3b )
by Daniel
22:19 queued 10s
created

Application   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 34.78%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 8
eloc 17
c 5
b 0
f 0
dl 0
loc 62
ccs 8
cts 23
cp 0.3478
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAppPath() 0 8 2
A registerExternalStorage() 0 9 2
A getAppWebPath() 0 3 2
A registerHooks() 0 3 1
A __construct() 0 3 1
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\Util;
34
use Symfony\Component\EventDispatcher\Event;
35
36
class Application extends App
37
{
38
	/** @var string */
39
	const APP_NAME = 'cms_pico';
40
41
	/**
42
	 * @param array $params
43
	 */
44 12
	public function __construct(array $params = [])
45
	{
46 12
		parent::__construct(self::APP_NAME, $params);
47 12
	}
48
49
	/**
50
	 * Register hooks.
51
	 */
52
	public function registerHooks()
53
	{
54
		Util::connectHook('OC_User', 'post_deleteUser', '\OCA\CMSPico\Hooks\UserHooks', 'onUserDeleted');
55
	}
56
57
	/**
58
	 * Registers a unencrypted storage backend.
59
	 */
60
	public function registerExternalStorage()
61
	{
62
		\OC::$server->getEventDispatcher()->addListener(
63
			'OCA\\Files_External::loadAdditionalBackends',
64
			function (Event $event) {
65
				$encryptionManager = \OC::$server->getEncryptionManager();
66
				if ($encryptionManager->isEnabled()) {
67
					$backendService = \OC::$server->query(BackendService::class);
68
					$backendService->registerBackendProvider(new BackendProvider());
69
				}
70
			}
71
		);
72
	}
73
74
	/**
75
	 * Returns the absolute path to this app.
76
	 *
77
	 * @return string
78
	 */
79 3
	public static function getAppPath(): string
80
	{
81
		try {
82
			/** @var IAppManager $appManager */
83 3
			$appManager = \OC::$server->getAppManager();
84 3
			return $appManager->getAppPath(self::APP_NAME);
85
		} catch (AppPathNotFoundException $e) {
86
			return '';
87
		}
88
	}
89
90
	/**
91
	 * Returns the absolute web path to this app.
92
	 *
93
	 * @return string
94
	 */
95 2
	public static function getAppWebPath(): string
96
	{
97 2
		return \OC_App::getAppWebPath(self::APP_NAME) ?: '';
98
	}
99
}
100