Test Failed
Push — master ( 0a4ed8...258650 )
by Daniel
23:49
created

Application   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 8
eloc 24
c 7
b 0
f 0
dl 0
loc 74
rs 10
ccs 6
cts 21
cp 0.2857

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAppPath() 0 8 2
A registerEventListener() 0 10 1
A getAppWebPath() 0 8 2
A __construct() 0 3 1
A getAppVersion() 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\Listener\ExternalStorageBackendEventListener;
29
use OCA\CMSPico\Listener\GroupDeletedEventListener;
30
use OCA\CMSPico\Listener\UserDeletedEventListener;
31
use OCP\App\AppPathNotFoundException;
32
use OCP\App\IAppManager;
33
use OCP\AppFramework\App;
34
use OCP\EventDispatcher\IEventDispatcher;
35
use OCP\Group\Events\GroupDeletedEvent;
36
use OCP\User\Events\UserDeletedEvent;
37
38
class Application extends App
39
{
40
	/** @var string */
41
	public const APP_NAME = 'cms_pico';
42
43
	/**
44
	 * @param array $params
45
	 */
46 12
	public function __construct(array $params = [])
47
	{
48 12
		parent::__construct(self::APP_NAME, $params);
49 12
	}
50
51
	/**
52
	 * Registers event listeners.
53
	 */
54
	public function registerEventListener(): void
55
	{
56
		/** @var IEventDispatcher $eventDispatcher */
57
		$eventDispatcher = \OC::$server->query(IEventDispatcher::class);
58
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedEventListener::class);
59
		$eventDispatcher->addServiceListener(GroupDeletedEvent::class, GroupDeletedEventListener::class);
60
61
		$eventDispatcher->addServiceListener(
62
			'OCA\\Files_External::loadAdditionalBackends',
63
			ExternalStorageBackendEventListener::class
64
		);
65
	}
66
67
	/**
68
	 * Returns the absolute path to this app.
69
	 *
70
	 * @return string
71
	 */
72 2
	public static function getAppPath(): string
73
	{
74
		try {
75
			/** @var IAppManager $appManager */
76 2
			$appManager = \OC::$server->getAppManager();
77 2
			return $appManager->getAppPath(self::APP_NAME);
78
		} catch (AppPathNotFoundException $e) {
79
			return '';
80
		}
81
	}
82
83
	/**
84
	 * Returns the absolute web path to this app.
85
	 *
86
	 * @return string
87
	 */
88
	public static function getAppWebPath(): string
89
	{
90
		try {
91
			/** @var IAppManager $appManager */
92
			$appManager = \OC::$server->getAppManager();
93
			return $appManager->getAppWebPath(self::APP_NAME);
94
		} catch (AppPathNotFoundException $e) {
95
			return '';
96
		}
97
	}
98
99
	/**
100
	 * Returns the installed version of this app.
101
	 *
102
	 * @return string
103
	 */
104
	public static function getAppVersion(): string
105
	{
106
		try {
107
			/** @var IAppManager $appManager */
108
			$appManager = \OC::$server->getAppManager();
109
			return $appManager->getAppVersion(self::APP_NAME);
110
		} catch (AppPathNotFoundException $e) {
111
			return '';
112
		}
113
	}
114
}
115