1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Activity\Parameter; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
use OCA\Activity\CurrentUser; |
27
|
|
|
use OCA\Activity\Formatter\IFormatter; |
28
|
|
|
use OCA\Activity\Formatter\BaseFormatter; |
29
|
|
|
use OCA\Activity\Formatter\CloudIDFormatter; |
30
|
|
|
use OCA\Activity\Formatter\FileFormatter; |
31
|
|
|
use OCA\Activity\Formatter\UserFormatter; |
32
|
|
|
use OCA\Activity\ViewInfoCache; |
33
|
|
|
use OCP\Activity\IEvent; |
34
|
|
|
use OCP\Activity\IManager; |
35
|
|
|
use OCP\Contacts\IManager as IContactsManager; |
36
|
|
|
use OCP\IL10N; |
37
|
|
|
use OCP\IURLGenerator; |
38
|
|
|
use OCP\IUserManager; |
39
|
|
|
|
40
|
|
|
class Factory { |
41
|
|
|
/** @var IManager */ |
42
|
|
|
protected $activityManager; |
43
|
|
|
|
44
|
|
|
/** @var IUserManager */ |
45
|
|
|
protected $userManager; |
46
|
|
|
|
47
|
|
|
/** @var IContactsManager */ |
48
|
|
|
protected $contactsManager; |
49
|
|
|
|
50
|
|
|
/** @var IL10N */ |
51
|
|
|
protected $l; |
52
|
|
|
|
53
|
|
|
/** @var ViewInfoCache */ |
54
|
|
|
protected $infoCache; |
55
|
|
|
|
56
|
|
|
/** @var string */ |
57
|
|
|
protected $user; |
58
|
|
|
|
59
|
|
|
/** @var IURLGenerator */ |
60
|
|
|
protected $urlGenerator; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param IManager $activityManager |
64
|
|
|
* @param IUserManager $userManager |
65
|
|
|
* @param IURLGenerator $urlGenerator |
66
|
|
|
* @param IContactsManager $contactsManager |
67
|
|
|
* @param ViewInfoCache $infoCache, |
|
|
|
|
68
|
|
|
* @param IL10N $l |
69
|
|
|
* @param CurrentUser $currentUser |
70
|
|
|
*/ |
71
|
27 |
View Code Duplication |
public function __construct(IManager $activityManager, |
|
|
|
|
72
|
|
|
IUserManager $userManager, |
73
|
|
|
IURLGenerator $urlGenerator, |
74
|
|
|
IContactsManager $contactsManager, |
75
|
|
|
ViewInfoCache $infoCache, |
76
|
|
|
IL10N $l, |
77
|
|
|
CurrentUser $currentUser) { |
78
|
27 |
|
$this->activityManager = $activityManager; |
79
|
27 |
|
$this->userManager = $userManager; |
80
|
27 |
|
$this->urlGenerator = $urlGenerator; |
81
|
27 |
|
$this->contactsManager = $contactsManager; |
82
|
27 |
|
$this->infoCache = $infoCache; |
83
|
27 |
|
$this->l = $l; |
84
|
27 |
|
$this->user = (string) $currentUser->getUID(); |
85
|
27 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $user |
89
|
|
|
*/ |
90
|
7 |
|
public function setUser($user) { |
91
|
7 |
|
$this->user = (string) $user; |
92
|
7 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param IL10N $l |
96
|
|
|
*/ |
97
|
5 |
|
public function setL10n(IL10N $l) { |
98
|
5 |
|
$this->l = $l; |
99
|
5 |
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $parameter |
103
|
|
|
* @param IEvent $event |
104
|
|
|
* @param string $formatter |
105
|
|
|
* @return IParameter |
106
|
|
|
*/ |
107
|
6 |
|
public function get($parameter, IEvent $event, $formatter) { |
108
|
6 |
|
return new Parameter( |
109
|
6 |
|
$parameter, |
110
|
|
|
$event, |
111
|
6 |
|
$this->getFormatter($formatter), |
112
|
|
|
$formatter |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return Collection |
118
|
|
|
*/ |
119
|
1 |
|
public function createCollection() { |
120
|
1 |
|
return new Collection($this->l, sha1(microtime() . mt_rand())); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param string $formatter |
125
|
|
|
* @return IFormatter |
126
|
|
|
*/ |
127
|
8 |
|
protected function getFormatter($formatter) { |
128
|
8 |
|
switch ($formatter) { |
129
|
8 |
|
case 'file': |
130
|
|
|
/** @var \OCA\Activity\Formatter\FileFormatter $fileFormatter */ |
131
|
5 |
|
$fileFormatter = \OC::$server->query(FileFormatter::class); |
132
|
5 |
|
$fileFormatter->setUser($this->user); |
133
|
5 |
|
return $fileFormatter; |
134
|
6 |
|
case 'username': |
135
|
|
|
/** @var \OCA\Activity\Formatter\UserFormatter */ |
136
|
4 |
|
return \OC::$server->query(UserFormatter::class); |
137
|
2 |
|
case 'federated_cloud_id': |
138
|
|
|
/** @var \OCA\Activity\Formatter\CloudIDFormatter */ |
139
|
1 |
|
return \OC::$server->query(CloudIDFormatter::class); |
140
|
|
|
default: |
141
|
|
|
/** @var \OCA\Activity\Formatter\BaseFormatter */ |
142
|
1 |
|
return \OC::$server->query(BaseFormatter::class); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
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 methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.