Completed
Push — master ( e8d0e9...6ce943 )
by Maxence
05:05 queued 02:32
created

SharesService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Service;
28
29
30
use OCA\Circles\Db\CirclesRequest;
31
use OCA\Circles\Exceptions\BroadcasterIsNotCompatible;
32
use OCA\Circles\IBroadcaster;
33
use OCA\Circles\Model\Share;
34
35
36
class SharesService {
37
38
	/** @var string */
39
	private $userId;
40
41
	/** @var CirclesRequest */
42
	private $circlesRequest;
43
44
	/** @var MiscService */
45
	private $miscService;
46
47
48
	/**
49
	 * SharesService constructor.
50
	 *
51
	 * @param string $userId
52
	 * @param CirclesRequest $circlesRequest
53
	 * @param MiscService $miscService
54
	 */
55
	public function __construct(
56
		string $userId,
57
		CirclesRequest $circlesRequest,
58
		MiscService $miscService
59
	) {
60
		$this->userId = $userId;
61
		$this->circlesRequest = $circlesRequest;
62
		$this->miscService = $miscService;
63
	}
64
65
	public function new(
66
		int $circleId, string $source, string $type, array $item, string $broadcast = null
67
	) {
68
		$share = new Share($source, $type);
69
		$share->setCircleId($circleId);
70
		$share->setItem($item);
71
		$share->setAuthor($this->userId);
72
73
		$this->circlesRequest->createShare($share);
74
75
		if ($broadcast !== null) {
76
			$broadcaster = \OC::$server->query($broadcast);
77
			if (!($broadcaster instanceof IBroadcaster)) {
78
				throw new BroadcasterIsNotCompatible();
79
			}
80
81
			$broadcaster->init();
82
83
			$users = $this->circlesRequest->getAudience($circleId);
84
			foreach ($users AS $user) {
85
				$broadcaster->broadcast($user['uid'], $share);
86
			}
87
		}
88
89
		return true;
90
	}
91
92
93
//	public function reshare($circleId, $source, $type, $shareid) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
//		$this->miscService->log(
95
//			"__reshare" . $circleId . ' ' . $source . ' ' . $type . ' ' . json_encode($item)
96
//		);
97
//
98
//		$share = new Share($source, $type);
99
//		$share->setCircleId($circleId);
100
//		$share->setItem($item);
101
//
102
//		$share->setAuthor($this->userId);
103
//
104
//		$this->circlesRequest->createShare($share);
105
//
106
//		return true;
107
//	}
108
109
}