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

Application::getAppPath()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
ccs 3
cts 5
cp 0.6
rs 10
cc 2
nc 3
nop 0
crap 2.2559
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