Completed
Push — master ( 2813c1...14a1cb )
by Maxence
01:59
created

Provider::parseMemberAsMember()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 3
1
<?php
2
3
/**
4
 * Circles - Bring cloud-users closer together.
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Maxence Lange <[email protected]>
10
 * @copyright 2017
11
 * @license GNU AGPL version 3 or any later version
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 */
27
28
namespace OCA\Circles\Activity;
29
30
use Exception;
31
use InvalidArgumentException;
32
use OCA\Circles\AppInfo\Application;
33
use OCA\Circles\Exceptions\FakeException;
34
use OCA\Circles\Model\Circle;
35
use OCA\Circles\Model\FederatedLink;
36
use OCA\Circles\Model\Member;
37
use OCA\Circles\Service\CirclesService;
38
use OCA\Circles\Service\MiscService;
39
use OCP\Activity\IEvent;
40
use OCP\Activity\IManager;
41
use OCP\Activity\IProvider;
42
43
class Provider implements IProvider {
44
45
46
	/** @var ProviderSubjectCircle */
47
	private $parserCircle;
48
49
	/** @var ProviderSubjectMember */
50
	private $parserMember;
51
52
	/** @var ProviderSubjectGroup */
53
	private $parserGroup;
54
55
	/** @var ProviderSubjectLink */
56
	private $parserLink;
57
58
	/** @var MiscService */
59
	protected $miscService;
60
61
	/** @var IManager */
62
	protected $activityManager;
63
64
65
	public function __construct(
66
		IManager $activityManager, MiscService $miscService, ProviderSubjectCircle $parserCircle,
67
		ProviderSubjectMember $parserMember, ProviderSubjectGroup $parserGroup,
68
		ProviderSubjectLink $parserLink
69
	) {
70
		$this->activityManager = $activityManager;
71
		$this->miscService = $miscService;
72
73
		$this->parserCircle = $parserCircle;
74
		$this->parserMember = $parserMember;
75
		$this->parserGroup = $parserGroup;
76
		$this->parserLink = $parserLink;
77
	}
78
79
80
	/**
81
	 * @param string $lang
82
	 * @param IEvent $event
83
	 * @param IEvent|null $previousEvent
84
	 *
85
	 * @return IEvent
86
	 */
87
	public function parse($lang, IEvent $event, IEvent $previousEvent = null) {
88
89
		try {
90
			$params = $event->getSubjectParameters();
91
			$this->initActivityParser($event, $params);
92
			$circle = Circle::fromJSON($params['circle']);
93
94
			$this->setIcon($event, $circle);
95
			$this->parseAsMember($event, $circle, $params);
96
			$this->parseAsModerator($event, $circle, $params);
97
98
		} catch (FakeException $e) {
99
			$this->generateParsedSubject($event);
100
101
			return $event;
102
		}
103
104
		throw new InvalidArgumentException();
105
	}
106
107
108
	/**
109
	 * @param IEvent $event
110
	 * @param array $params
111
	 */
112
	private function initActivityParser(IEvent $event, $params) {
113
		if ($event->getApp() !== Application::APP_NAME) {
114
			throw new InvalidArgumentException();
115
		}
116
117
		if (!key_exists('circle', $params)) {
118
			throw new InvalidArgumentException();
119
		}
120
	}
121
122
123
	/**
124
	 * @param IEvent $event
125
	 */
126
	private function generateParsedSubject(IEvent &$event) {
127
		$subject = $event->getRichSubject();
128
		$params = $event->getRichSubjectParameters();
129
		$ak = array_keys($params);
130
		foreach ($ak as $k) {
131
			if (is_array($params[$k])) {
132
				$subject = str_replace('{' . $k . '}', $params[$k]['parsed'], $subject);
133
			}
134
		}
135
136
		$event->setParsedSubject($subject);
137
	}
138
139
140
	/**
141
	 * @param IEvent $event
142
	 * @param Circle $circle
143
	 */
144
	private function setIcon(IEvent &$event, Circle $circle) {
145
		$event->setIcon(
146
			CirclesService::getCircleIcon(
147
				$circle->getType(),
148
				(method_exists($this->activityManager, 'getRequirePNG')
149
				 && $this->activityManager->getRequirePNG())
150
			)
151
		);
152
	}
153
154
155
	/**
156
	 * @param IEvent $event
157
	 * @param Circle $circle
158
	 * @param array $params
159
	 *
160
	 * @throws InvalidArgumentError
161
	 */
162
	private function parseAsMember(IEvent &$event, Circle $circle, $params) {
163
		if ($event->getType() !== 'circles_as_member') {
164
			return;
165
		}
166
167
		$this->parserCircle->parseSubjectCircleCreate($event, $circle);
168
		$this->parserCircle->parseSubjectCircleDelete($event, $circle);
169
		$this->parseMemberAsMember($event, $circle, $params);
170
171
		throw new InvalidArgumentError();
172
	}
173
174
175
	/**
176
	 * @param Circle $circle
177
	 * @param IEvent $event
178
	 * @param array $params
179
	 *
180
	 * @throws Exception
181
	 */
182
	private function parseAsModerator(IEvent &$event, Circle $circle, $params) {
183
		if ($event->getType() !== 'circles_as_moderator') {
184
			return;
185
		}
186
187
		$this->parseMemberAsModerator($event, $circle, $params);
188
		$this->parseGroupAsModerator($event, $circle, $params);
189
		$this->parseLinkAsModerator($event, $circle, $params);
190
191
		throw new InvalidArgumentError();
192
	}
193
194
195
	/**
196
	 * @param IEvent $event
197
	 * @param Circle $circle
198
	 * @param array $params
199
	 *
200
	 * @throws InvalidArgumentError
201
	 */
202 View Code Duplication
	private function parseMemberAsMember(IEvent &$event, Circle $circle, $params) {
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...
203
204
		if (!key_exists('member', $params)) {
205
			return;
206
		}
207
208
		$member = Member::fromJSON($params['member']);
209
210
		$this->parserMember->parseSubjectMemberJoin($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 208 can be null; however, OCA\Circles\Activity\Pro...arseSubjectMemberJoin() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
211
		$this->parserMember->parseSubjectMemberAdd($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 208 can be null; however, OCA\Circles\Activity\Pro...parseSubjectMemberAdd() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
212
		$this->parserMember->parseSubjectMemberLeft($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 208 can be null; however, OCA\Circles\Activity\Pro...arseSubjectMemberLeft() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
213
		$this->parserMember->parseSubjectMemberRemove($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 208 can be null; however, OCA\Circles\Activity\Pro...seSubjectMemberRemove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
214
215
		throw new InvalidArgumentError();
216
	}
217
218
219
	/**
220
	 * @param IEvent $event
221
	 * @param Circle $circle
222
	 * @param array $params
223
	 */
224
	private function parseGroupAsModerator(IEvent &$event, Circle $circle, $params) {
225
		if (!key_exists('group', $params)) {
226
			return;
227
		}
228
229
		$group = Member::fromJSON($params['group']);
230
231
		$this->parserGroup->parseGroupLink($event, $circle, $group);
0 ignored issues
show
Bug introduced by
It seems like $group defined by \OCA\Circles\Model\Membe...mJSON($params['group']) on line 229 can be null; however, OCA\Circles\Activity\Pro...Group::parseGroupLink() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
232
		$this->parserGroup->parseGroupUnlink($event, $circle, $group);
0 ignored issues
show
Bug introduced by
It seems like $group defined by \OCA\Circles\Model\Membe...mJSON($params['group']) on line 229 can be null; however, OCA\Circles\Activity\Pro...oup::parseGroupUnlink() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
233
		$this->parserGroup->parseGroupLevel($event, $circle, $group);
0 ignored issues
show
Bug introduced by
It seems like $group defined by \OCA\Circles\Model\Membe...mJSON($params['group']) on line 229 can be null; however, OCA\Circles\Activity\Pro...roup::parseGroupLevel() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
234
235
		throw new InvalidArgumentException();
236
	}
237
238
239
	/**
240
	 * @param IEvent $event
241
	 * @param Circle $circle
242
	 * @param array $params
243
	 */
244 View Code Duplication
	private function parseMemberAsModerator(IEvent &$event, Circle $circle, $params) {
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...
245
		if (!key_exists('member', $params)) {
246
			return;
247
		}
248
249
		$member = Member::fromJSON($params['member']);
250
251
		$this->parserMember->parseMemberInvited($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 249 can be null; however, OCA\Circles\Activity\Pro...r::parseMemberInvited() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
252
		$this->parserMember->parseMemberLevel($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 249 can be null; however, OCA\Circles\Activity\Pro...ber::parseMemberLevel() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
253
		$this->parserMember->parseMemberRequestInvitation($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 249 can be null; however, OCA\Circles\Activity\Pro...mberRequestInvitation() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
254
		$this->parserMember->parseMemberOwner($event, $circle, $member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by \OCA\Circles\Model\Membe...JSON($params['member']) on line 249 can be null; however, OCA\Circles\Activity\Pro...ber::parseMemberOwner() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
255
256
		throw new InvalidArgumentException();
257
	}
258
259
260
	/**
261
	 * @param IEvent $event
262
	 * @param Circle $circle
263
	 * @param array $params
264
	 */
265
	private function parseLinkAsModerator(IEvent &$event, Circle $circle, $params) {
266
267
		if (!key_exists('link', $params)) {
268
			return;
269
		}
270
271
		$remote = FederatedLink::fromJSON($params['link']);
272
273
		$this->parserLink->parseLinkRequestSent($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...:parseLinkRequestSent() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
274
		$this->parserLink->parseLinkRequestReceived($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...seLinkRequestReceived() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
275
		$this->parserLink->parseLinkRequestRejected($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...seLinkRequestRejected() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
276
		$this->parserLink->parseLinkRequestCanceled($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...seLinkRequestCanceled() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
277
		$this->parserLink->parseLinkRequestAccepted($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...seLinkRequestAccepted() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
278
		$this->parserLink->parseLinkRequestRemoved($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...rseLinkRequestRemoved() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
279
		$this->parserLink->parseLinkRequestCanceling($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...eLinkRequestCanceling() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
280
		$this->parserLink->parseLinkRequestAccepting($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...eLinkRequestAccepting() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
281
		$this->parserLink->parseLinkUp($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...jectLink::parseLinkUp() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
282
		$this->parserLink->parseLinkDown($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...ctLink::parseLinkDown() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
283
		$this->parserLink->parseLinkRemove($event, $circle, $remote);
0 ignored issues
show
Bug introduced by
It seems like $remote defined by \OCA\Circles\Model\Feder...omJSON($params['link']) on line 271 can be null; however, OCA\Circles\Activity\Pro...Link::parseLinkRemove() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
284
285
		throw new InvalidArgumentException();
286
	}
287
288
289
}