Completed
Pull Request — master (#582)
by
unknown
126:36 queued 124:53
created

Factory::getFormatter()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 5
nop 1
crap 5
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Activity\Parameter;
23
24
25
use OCA\Activity\Formatter\BaseFormatter;
26
use OCA\Activity\Formatter\GroupFormatter;
27
use OCA\Activity\Formatter\IFormatter;
28
use OCA\Activity\Formatter\CloudIDFormatter;
29
use OCA\Activity\Formatter\FileFormatter;
30
use OCA\Activity\Formatter\UserFormatter;
31
use OCA\Activity\ViewInfoCache;
32
use OCP\Activity\IEvent;
33
use OCP\Activity\IManager;
34
use OCP\Contacts\IManager as IContactsManager;
35
use OCP\IConfig;
36
use OCP\IGroupManager;
37
use OCP\IL10N;
38
use OCP\IURLGenerator;
39
use OCP\IUserManager;
40
41
class Factory {
42
	/** @var IManager */
43
	protected $activityManager;
44
45
	/** @var IUserManager */
46
	protected $userManager;
47
48
	/** @var IContactsManager */
49
	protected $contactsManager;
50
51
	/** @var IL10N */
52
	protected $l;
53
54
	/** @var IGroupManager  */
55
	protected $groupManager;
56
57
	/** @var ViewInfoCache */
58
	protected $infoCache;
59
60
	/** @var string */
61
	protected $user;
62
63
	/** @var IURLGenerator */
64
	protected $urlGenerator;
65
66
	/**
67
	 * @param IManager $activityManager
68
	 * @param IUserManager $userManager
69
	 * @param IURLGenerator $urlGenerator
70
	 * @param IContactsManager $contactsManager
71
	 * @param ViewInfoCache $infoCache,
0 ignored issues
show
Documentation introduced by
There is no parameter named $infoCache,. Did you maybe mean $infoCache?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
72
	 * @param IL10N $l
73
	 * @param string $user
74
	 */
75 21 View Code Duplication
	public function __construct(IManager $activityManager,
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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
								IUserManager $userManager,
77
								IURLGenerator $urlGenerator,
78
								IContactsManager $contactsManager,
79
								ViewInfoCache $infoCache,
80
								IL10N $l,
81
								IGroupManager $groupManager,
82
								$user) {
83 21
		$this->activityManager = $activityManager;
84 21
		$this->userManager = $userManager;
85 21
		$this->urlGenerator = $urlGenerator;
86 21
		$this->contactsManager = $contactsManager;
87 21
		$this->infoCache = $infoCache;
88 21
		$this->l = $l;
89 21
		$this->groupManager = $groupManager;
90 21
		$this->user = $user;
91 21
	}
92
93
	/**
94
	 * @param string $user
95
	 */
96 7
	public function setUser($user) {
97 7
		$this->user = (string) $user;
98 7
	}
99
100
	/**
101
	 * @param IL10N $l
102
	 */
103 1
	public function setL10n(IL10N $l) {
104 1
		$this->l = $l;
105 1
	}
106
107
	/**
108
	 * @param string $parameter
109
	 * @param IEvent $event
110
	 * @param string $formatter
111
	 * @return IParameter
112
	 */
113 6
	public function get($parameter, IEvent $event, $formatter) {
114 6
		return new Parameter(
115 6
			$parameter,
116 6
			$event,
117 6
			$this->getFormatter($formatter),
118
			$formatter
119 6
		);
120
	}
121
122
	/**
123
	 * @return Collection
124
	 */
125 1
	public function createCollection() {
126 1
		return new Collection($this->l, sha1(microtime() . mt_rand()));
127
	}
128
129
	/**
130
	 * @param string $formatter
131
	 * @return IFormatter
132
	 */
133 9
	protected function getFormatter($formatter) {
134 9
		if ($formatter === 'file') {
135 5
			return new FileFormatter($this->infoCache, $this->urlGenerator, $this->l, $this->user);
136 7
		} else if ($formatter === 'username') {
137 4
			return new UserFormatter($this->userManager, $this->l);
138 3
		} else if ($formatter === 'federated_cloud_id') {
139 1
			return new CloudIDFormatter($this->contactsManager);
140 2
		} else if ($formatter === 'group') {
141 1
			return new GroupFormatter($this->groupManager);
142
		} else {
143 1
			return new BaseFormatter();
144
		}
145
	}
146
}
147