Completed
Push — master ( 26f174...a0e62f )
by Joas
14:52 queued 05:17
created

Application::getSyncService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Georg Ehrke <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 *
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
namespace OCA\DAV\AppInfo;
26
27
use OCA\DAV\CalDAV\BirthdayService;
28
use OCA\DAV\CardDAV\ContactsManager;
29
use OCA\DAV\CardDAV\SyncService;
30
use OCA\DAV\HookManager;
31
use \OCP\AppFramework\App;
32
use OCP\Contacts\IManager;
33
use Symfony\Component\EventDispatcher\GenericEvent;
34
35
class Application extends App {
36
37
	/**
38
	 * Application constructor.
39
	 */
40
	public function __construct() {
41
		parent::__construct('dav');
42
	}
43
44
	/**
45
	 * @param IManager $contactsManager
46
	 * @param string $userID
47
	 */
48
	public function setupContactsProvider(IManager $contactsManager, $userID) {
49
		/** @var ContactsManager $cm */
50
		$cm = $this->getContainer()->query(ContactsManager::class);
51
		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
52
		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
53
	}
54
55
	public function registerHooks() {
56
		/** @var HookManager $hm */
57
		$hm = $this->getContainer()->query(HookManager::class);
58
		$hm->setup();
59
60 View Code Duplication
		$listener = function($event) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
			if ($event instanceof GenericEvent) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\EventDispatcher\GenericEvent does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
62
				/** @var BirthdayService $b */
63
				$b = $this->getContainer()->query(BirthdayService::class);
64
				$b->onCardChanged(
65
					$event->getArgument('addressBookId'),
66
					$event->getArgument('cardUri'),
67
					$event->getArgument('cardData')
68
				);
69
			}
70
		};
71
72
		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
73
		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
74
		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
75 View Code Duplication
		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
			if ($event instanceof GenericEvent) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\EventDispatcher\GenericEvent does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
77
				/** @var BirthdayService $b */
78
				$b = $this->getContainer()->query(BirthdayService::class);
79
				$b->onCardDeleted(
80
					$event->getArgument('addressBookId'),
81
					$event->getArgument('cardUri')
82
				);
83
			}
84
		});
85
	}
86
87
	public function getSyncService() {
88
		return $this->getContainer()->query(SyncService::class);
89
	}
90
91
}
92