Completed
Pull Request — master (#551)
by Maxence
01:55
created

MemberAdd::sendPasswordExistingShares()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 8.5178
c 0
b 0
f 0
cc 5
nc 9
nop 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles\RemoteEvents;
33
34
35
use daita\MySmallPhpTools\Model\SimpleDataStore;
36
use Exception;
37
use OC\User\NoUserException;
38
use OCA\Circles\Exceptions\CircleDoesNotExistException;
39
use OCA\Circles\Exceptions\CircleTypeNotValidException;
40
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
41
use OCA\Circles\Exceptions\EmailAccountInvalidFormatException;
42
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
43
use OCA\Circles\Exceptions\GlobalScaleEventException;
44
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
45
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
46
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
47
use OCA\Circles\Exceptions\MembersLimitException;
48
use OCA\Circles\Exceptions\RemoteEventException;
49
use OCA\Circles\Exceptions\TokenDoesNotExistException;
50
use OCA\Circles\IRemoteEvent;
51
use OCA\Circles\Model\DeprecatedCircle;
52
use OCA\Circles\Model\GlobalScale\GSEvent;
53
use OCA\Circles\Model\DeprecatedMember;
54
use OCA\Circles\Model\SharesToken;
55
use OCP\IUser;
56
use OCP\Mail\IEMailTemplate;
57
use OCP\Util;
58
59
60
/**
61
 * Class MemberAdd
62
 *
63
 * @package OCA\Circles\GlobalScale
64
 */
65
class MemberAdd implements IRemoteEvent {
66
67
68
	/**
69
	 * @param GSEvent $event
70
	 * @param bool $localCheck
0 ignored issues
show
Bug introduced by
There is no parameter named $localCheck. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
71
	 * @param bool $mustBeChecked
0 ignored issues
show
Bug introduced by
There is no parameter named $mustBeChecked. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

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

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

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

Loading history...
72
	 *
73
	 * @throws CircleDoesNotExistException
74
	 * @throws ConfigNoCircleAvailableException
75
	 * @throws EmailAccountInvalidFormatException
76
	 * @throws GlobalScaleDSyncException
77
	 * @throws GlobalScaleEventException
78
	 * @throws MemberAlreadyExistsException
79
	 * @throws MemberCantJoinCircleException
80
	 * @throws MembersLimitException
81
	 * @throws NoUserException
82
	 * @throws CircleTypeNotValidException
83
	 * @throws MemberIsNotModeratorException
84
	 * @throws RemoteEventException
85
	 */
86
	public function verify(GSEvent $event): void {
87
		if ($event->hasMember())
88
			throw new RemoteEventException('event have no member linked');
89
90
		$eventMember = $event->getMember();
91
92
//		if ($eventMember->getInstance() === '') {
93
//			$eventMember->setInstance($event->getSource());
94
//		}
95
96
		echo json_encode($eventMember) . "\n";
97
		return;
98
		$ident = $eventMember->getUserId();
0 ignored issues
show
Unused Code introduced by
$ident = $eventMember->getUserId(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
99
		$this->membersService->verifyIdentBasedOnItsType(
100
			$ident, $eventMember->getType(), $eventMember->getInstance()
101
		);
102
103
		$circle = $event->getDeprecatedCircle();
104
105
		if (!$event->isForced()) {
106
			$circle->getHigherViewer()
107
				   ->hasToBeModerator();
108
		}
109
110
		$member = $this->membersRequest->getFreshNewMember(
0 ignored issues
show
Bug introduced by
The property membersRequest does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
111
			$circle->getUniqueId(), $ident, $eventMember->getType(), $eventMember->getInstance()
112
		);
113
		$member->hasToBeInviteAble();
114
		$member->setCachedName($eventMember->getCachedName());
115
116
		$this->circlesService->checkThatCircleIsNotFull($circle);
0 ignored issues
show
Bug introduced by
The property circlesService does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
117
		$this->membersService->addMemberBasedOnItsType($circle, $member);
0 ignored issues
show
Bug introduced by
The property membersService does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
118
119
		$password = '';
120
		$sendPasswordByMail = false;
121 View Code Duplication
		if ($this->configService->enforcePasswordProtection($circle)) {
0 ignored issues
show
Bug introduced by
The property configService does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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...
122
			if ($circle->getSetting('password_single_enabled') === 'true') {
123
				$password = $circle->getPasswordSingle();
124
			} else {
125
				$sendPasswordByMail = true;
126
				$password = $this->miscService->token(15);
0 ignored issues
show
Bug introduced by
The property miscService does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
127
			}
128
		}
129
130
		$event->setData(
131
			new SimpleDataStore(
132
				[
133
					'password'       => $password,
134
					'passwordByMail' => $sendPasswordByMail
135
				]
136
			)
137
		);
138
		$event->setMember($member);
139
	}
140
141
142
	/**
143
	 * @param GSEvent $event
144
	 *
145
	 * @throws MemberAlreadyExistsException
146
	 */
147
	public function manage(GSEvent $event): void {
148
//		$circle = $event->getDeprecatedCircle();
149
//		$member = $event->getMember();
150
//		if ($member->getJoined() === '') {
151
//			$this->membersRequest->createMember($member);
152
//		} else {
153
//			$this->membersRequest->updateMemberLevel($member);
154
//		}
155
//
156
//
157
//		//
158
//		// TODO: verifiez comment se passe le cached name sur un member_add
159
//		//
160
//		$cachedName = $member->getCachedName();
161
//		$password = $event->getData()
162
//						  ->g('password');
163
//
164
//		$shares = $this->generateUnknownSharesLinks($circle, $member, $password);
165
//		$result = [
166
//			'unknownShares' => $shares,
167
//			'cachedName'    => $cachedName
168
//		];
169
//
170
//		if ($member->getType() === DeprecatedMember::TYPE_CONTACT
171
//			&& $this->configService->isLocalInstance($member->getInstance())) {
172
//			$result['contact'] = $this->miscService->getInfosFromContact($member);
173
//		}
174
//
175
//		$event->setResult(new SimpleDataStore($result));
176
//		$this->eventsService->onMemberNew($circle, $member);
177
	}
178
179
180
	/**
181
	 * @param GSEvent[] $events
182
	 *
183
	 * @throws Exception
184
	 */
185
	public function result(array $events): void {
186
//		$password = $cachedName = '';
187
//		$circle = $member = null;
188
//		$links = [];
189
//		$recipients = [];
190
//		foreach ($events as $event) {
191
//			$data = $event->getData();
192
//			if ($data->gBool('passwordByMail') !== false) {
193
//				$password = $data->g('password');
194
//			}
195
//			$circle = $event->getDeprecatedCircle();
196
//			$member = $event->getMember();
197
//			$result = $event->getResult();
198
//			if ($result->g('cachedName') !== '') {
199
//				$cachedName = $result->g('cachedName');
200
//			}
201
//
202
//			$links = array_merge($links, $result->gArray('unknownShares'));
203
//			$contact = $result->gArray('contact');
204
//			if (!empty($contact)) {
205
//				$recipients = $contact['emails'];
206
//			}
207
//		}
208
//
209
//		if (empty($links) || $circle === null || $member === null) {
210
//			return;
211
//		}
212
//
213
//		if ($cachedName !== '') {
214
//			$member->setCachedName($cachedName);
215
//			$this->membersService->updateMember($member);
216
//		}
217
//
218
//		if ($member->getType() === DeprecatedMember::TYPE_MAIL
219
//			|| $member->getType() === DeprecatedMember::TYPE_CONTACT) {
220
//			if ($member->getType() === DeprecatedMember::TYPE_MAIL) {
221
//				$recipients = [$member->getUserId()];
222
//			}
223
//
224
//			foreach ($recipients as $recipient) {
225
//				$this->memberIsMailbox($circle, $recipient, $links, $password);
226
//			}
227
//		}
228
	}
229
230
231
	/**
232
	 * @param DeprecatedCircle $circle
233
	 * @param string $recipient
234
	 * @param array $links
235
	 * @param string $password
236
	 */
237 View Code Duplication
	private function memberIsMailbox(DeprecatedCircle $circle, string $recipient, array $links, string $password) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
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...
238
		if ($circle->getViewer() === null) {
239
			$author = $circle->getOwner()
240
							 ->getUserId();
241
		} else {
242
			$author = $circle->getViewer()
243
							 ->getUserId();
244
		}
245
246
		try {
247
			$template = $this->generateMailExitingShares($author, $circle->getName());
248
			$this->fillMailExistingShares($template, $links);
249
			$this->sendMailExistingShares($template, $author, $recipient);
250
			$this->sendPasswordExistingShares($author, $recipient, $password);
251
		} catch (Exception $e) {
252
			$this->miscService->log('Failed to send mail about existing share ' . $e->getMessage());
253
		}
254
	}
255
256
257
	/**
258
	 * @param DeprecatedCircle $circle
259
	 * @param DeprecatedMember $member
260
	 * @param string $password
261
	 *
262
	 * @return array
263
	 */
264 View Code Duplication
	private function generateUnknownSharesLinks(DeprecatedCircle $circle, DeprecatedMember $member, string $password): array {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Unused Code introduced by
The parameter $circle is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
265
		$unknownShares = $this->getUnknownShares($member);
266
267
		$data = [];
268
		foreach ($unknownShares as $share) {
269
			try {
270
				$data[] = $this->getMailLinkFromShare($share, $member, $password);
271
			} catch (TokenDoesNotExistException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
272
			}
273
		}
274
275
		return $data;
276
	}
277
278
279
	/**
280
	 * @param DeprecatedMember $member
281
	 *
282
	 * @return array
283
	 */
284 View Code Duplication
	private function getUnknownShares(DeprecatedMember $member): array {
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...
285
		$allShares = $this->sharesRequest->getSharesForCircle($member->getCircleId());
0 ignored issues
show
Bug introduced by
The property sharesRequest does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
286
		$knownShares = array_map(
287
			function(SharesToken $shareToken) {
288
				return $shareToken->getShareId();
289
			},
290
			$this->tokensRequest->getTokensFromMember($member)
0 ignored issues
show
Bug introduced by
The property tokensRequest does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
291
		);
292
293
		$unknownShares = [];
294
		foreach ($allShares as $share) {
295
			if (!in_array($share['id'], $knownShares)) {
296
				$unknownShares[] = $share;
297
			}
298
		}
299
300
		return $unknownShares;
301
	}
302
303
304
	/**
305
	 * @param array $share
306
	 * @param DeprecatedMember $member
307
	 * @param string $password
308
	 *
309
	 * @return array
310
	 * @throws TokenDoesNotExistException
311
	 */
312 View Code Duplication
	private function getMailLinkFromShare(array $share, DeprecatedMember $member, string $password = '') {
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...
313
		$sharesToken = $this->tokensRequest->generateTokenForMember($member, (int)$share['id'], $password);
314
		$link = $this->urlGenerator->linkToRouteAbsolute(
0 ignored issues
show
Bug introduced by
The property urlGenerator does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
315
			'files_sharing.sharecontroller.showShare',
316
			['token' => $sharesToken->getToken()]
317
		);
318
		$author = $share['uid_initiator'];
319
		$filename = basename($share['file_target']);
320
321
		return [
322
			'author'   => $author,
323
			'link'     => $link,
324
			'filename' => $filename
325
		];
326
	}
327
328
329
	/**
330
	 * @param string $author
331
	 * @param string $circleName
332
	 *
333
	 * @return IEMailTemplate
334
	 */
335 View Code Duplication
	private function generateMailExitingShares(string $author, string $circleName): IEMailTemplate {
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...
336
		$emailTemplate = $this->mailer->createEMailTemplate('circles.ExistingShareNotification', []);
0 ignored issues
show
Bug introduced by
The property mailer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
337
		$emailTemplate->addHeader();
338
339
		$text = $this->l10n->t('%s shared multiple files with \'%s\'.', [$author, $circleName]);
0 ignored issues
show
Bug introduced by
The property l10n does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
340
		$emailTemplate->addBodyText(htmlspecialchars($text), $text);
341
342
		return $emailTemplate;
343
	}
344
345
	/**
346
	 * @param IEMailTemplate $emailTemplate
347
	 * @param array $links
348
	 */
349 View Code Duplication
	private function fillMailExistingShares(IEMailTemplate $emailTemplate, array $links) {
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...
350
		foreach ($links as $item) {
351
			$emailTemplate->addBodyButton(
352
				$this->l10n->t('Open »%s«', [htmlspecialchars($item['filename'])]), $item['link']
353
			);
354
		}
355
	}
356
357
358
	/**
359
	 * @param IEMailTemplate $emailTemplate
360
	 * @param string $author
361
	 * @param string $recipient
362
	 *
363
	 * @throws Exception
364
	 */
365 View Code Duplication
	private function sendMailExistingShares(IEMailTemplate $emailTemplate, string $author, string $recipient
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...
366
	) {
367
		$subject = $this->l10n->t('%s shared multiple files with you.', [$author]);
368
369
		$instanceName = $this->defaults->getName();
0 ignored issues
show
Bug introduced by
The property defaults does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
370
		$senderName = $this->l10n->t('%s on %s', [$author, $instanceName]);
371
372
		$message = $this->mailer->createMessage();
373
374
		$message->setFrom([Util::getDefaultEmailAddress($instanceName) => $senderName]);
375
		$message->setSubject($subject);
376
		$message->setPlainBody($emailTemplate->renderText());
377
		$message->setHtmlBody($emailTemplate->renderHtml());
378
		$message->setTo([$recipient]);
379
380
		$this->mailer->send($message);
381
	}
382
383
384
	/**
385
	 * @param string $author
386
	 * @param string $email
387
	 * @param string $password
388
	 *
389
	 * @throws Exception
390
	 */
391
	protected function sendPasswordExistingShares(string $author, string $email, string $password) {
392
		if ($password === '') {
393
			return;
394
		}
395
396
		$message = $this->mailer->createMessage();
397
398
		$authorUser = $this->userManager->get($author);
0 ignored issues
show
Bug introduced by
The property userManager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
399
		$authorName = ($authorUser instanceof IUser) ? $authorUser->getDisplayName() : $author;
0 ignored issues
show
Bug introduced by
The class OCP\IUser 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...
400
		$authorEmail = ($authorUser instanceof IUser) ? $authorUser->getEMailAddress() : null;
0 ignored issues
show
Bug introduced by
The class OCP\IUser 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...
401
402
		$this->miscService->log("Sending password mail about existing files to '" . $email . "'", 0);
403
404
		$plainBodyPart = $this->l10n->t(
405
			"%1\$s shared multiple files with you.\nYou should have already received a separate mail with a link to access them.\n",
406
			[$authorName]
407
		);
408
		$htmlBodyPart = $this->l10n->t(
409
			'%1$s shared multiple files with you. You should have already received a separate mail with a link to access them.',
410
			[$authorName]
411
		);
412
413
		$emailTemplate = $this->mailer->createEMailTemplate(
414
			'sharebymail.RecipientPasswordNotification', [
415
														   'password' => $password,
416
														   'author'   => $author
417
													   ]
418
		);
419
420
		$emailTemplate->setSubject(
421
			$this->l10n->t(
422
				'Password to access files shared to you by %1$s', [$authorName]
423
			)
424
		);
425
		$emailTemplate->addHeader();
426
		$emailTemplate->addHeading($this->l10n->t('Password to access files'), false);
427
		$emailTemplate->addBodyText(htmlspecialchars($htmlBodyPart), $plainBodyPart);
428
		$emailTemplate->addBodyText($this->l10n->t('It is protected with the following password:'));
429
		$emailTemplate->addBodyText($password);
430
431
		// The "From" contains the sharers name
432
		$instanceName = $this->defaults->getName();
433
		$senderName = $this->l10n->t(
434
			'%1$s via %2$s',
435
			[
436
				$authorName,
437
				$instanceName
438
			]
439
		);
440
441
		$message->setFrom([\OCP\Util::getDefaultEmailAddress($instanceName) => $senderName]);
442
		if ($authorEmail !== null) {
443
			$message->setReplyTo([$authorEmail => $authorName]);
444
			$emailTemplate->addFooter($instanceName . ' - ' . $this->defaults->getSlogan());
445
		} else {
446
			$emailTemplate->addFooter();
447
		}
448
449
		$message->setTo([$email]);
450
		$message->useTemplate($emailTemplate);
451
		$this->mailer->send($message);
452
	}
453
454
}
455