Failed Conditions
Push — master ( a9bae3...93cd59 )
by Marcos
08:39 queued 11s
created

lib/AppInfo/Application.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
6
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Passman\AppInfo;
25
26
use OC\Files\View;
27
use OC\ServerContainer;
28
use OCA\Passman\Controller\ShareController;
29
use OCA\Passman\Middleware\APIMiddleware;
30
use OCA\Passman\Middleware\ShareMiddleware;
31
use OCA\Passman\Notifier;
32
use OCA\Passman\Search\Provider;
33
use OCA\Passman\Service\ActivityService;
34
use OCA\Passman\Service\CredentialService;
35
use OCA\Passman\Service\CronService;
36
use OCA\Passman\Service\FileService;
37
use OCA\Passman\Service\NotificationService;
38
use OCA\Passman\Service\SettingsService;
39
use OCA\Passman\Service\ShareService;
40
use OCA\Passman\Service\VaultService;
41
use OCA\Passman\Utility\Utils;
42
use OCP\AppFramework\App;
43
use OCP\AppFramework\Bootstrap\IBootContext;
44
use OCP\AppFramework\Bootstrap\IBootstrap;
45
use OCP\AppFramework\Bootstrap\IRegistrationContext;
46
use OCP\IDBConnection;
47
use OCP\IL10N;
48
use OCP\ILogger;
49
use OCP\Notification\IManager;
50
use OCP\Util;
51
use Psr\Container\ContainerInterface;
52
53
class Application extends App implements IBootstrap {
54
	public const APP_ID = 'passman';
55
56
	public function __construct() {
57
		parent::__construct(self::APP_ID);
58
	}
59
60
	public function register(IRegistrationContext $context): void {
61
		$this->registerNavigationEntry();
62
		// $this->registerPersonalPage();
63
64
		$context->registerEventListener(
65
			BeforeUserDeletedEvent::class,
66
			UserDeletedListener::class
67
		);
68
69
		$context->registerSearchProvider(Provider::class);
70
71
		$context->registerService(View::class, function () {
72
			return new View('');
73
		}, false);
74
75
		$context->registerService('isCLI', function () {
76
			return \OC::$CLI;
77
		});
78
79
		$context->registerMiddleware(ShareMiddleware::class);
80
		$context->registerMiddleware(APIMiddleware::class);
81
82
		$context->registerService('ShareController', function (ContainerInterface $c) {
83
			$server = $this->getContainer()->getServer();
84
			return new ShareController(
85
				$c->get('AppName'),
86
				$c->get('Request'),
87
				$server->getUserSession()->getUser(),
88
				$server->getGroupManager(),
89
				$server->getUserManager(),
90
				$c->get(ActivityService::class),
91
				$c->get(VaultService::class),
92
				$c->get(ShareService::class),
93
				$c->get(CredentialService::class),
94
				$c->get(NotificationService::class),
95
				$c->get(FileService::class),
96
				$c->get(SettingsService::class)
97
			);
98
		});
99
100
101
		$context->registerService('CronService', function (ContainerInterface $c) {
102
			return new CronService(
103
				$c->get(CredentialService::class),
104
				$c->get(ILogger::class),
105
				$c->get(Utils::class),
106
				$c->get(NotificationService::class),
107
				$c->get(ActivityService::class),
108
				$c->get(IDBConnection::class)
109
			);
110
		});
111
112
		$context->registerService('Logger', function (ContainerInterface $c) {
113
			return $c->get(ServerContainer::class)->getLogger();
114
		});
115
	}
116
117
	public function boot(IBootContext $context): void {
118
		$l = \OC::$server->getL10N(self::APP_ID);
0 ignored issues
show
$l is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
119
120
		/** @var IManager $manager */
121
		$manager = $context->getAppContainer()->get(IManager::class);
122
		$manager->registerNotifierService(Notifier::class);
123
124
		Util::addTranslations(self::APP_ID);
125
		\OCP\App::registerAdmin(self::APP_ID, 'templates/admin.settings');
126
	}
127
128
	/**
129
	 * Register the navigation entry
130
	 */
131
	public function registerNavigationEntry() {
132
		$c = $this->getContainer();
133
		$server = $c->getServer();
134
		$navigationEntry = function () use ($c, $server) {
135
			return [
136
				'id' => $c->getAppName(),
137
				'order' => 10,
138
				'name' => $c->query(IL10N::class)->t('Passwords'),
139
				'href' => $server->getURLGenerator()->linkToRoute('passman.page.index'),
140
				'icon' => $server->getURLGenerator()->imagePath($c->getAppName(), 'app.svg'),
141
			];
142
		};
143
		$server->getNavigationManager()->add($navigationEntry);
144
	}
145
146
	/**
147
	 * Register personal settings for notifications and emails
148
	 */
149
	public function registerPersonalPage() {
150
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
151
	}
152
}
153