Completed
Push — master ( a203f6...ccc5ed )
by Maxence
04:27
created

Provider   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 213
Duplicated Lines 11.74 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 20
c 4
b 0
f 0
lcom 1
cbo 8
dl 25
loc 213
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A parse() 0 18 2
A initActivityParser() 0 9 3
A setIcon() 0 9 2
A parseAsMember() 0 9 2
A parseAsModerator() 0 9 2
A parseMemberAsMember() 13 13 2
A parseGroupAsModerator() 0 11 2
A parseMemberAsModerator() 12 12 2
A parseLinkAsModerator() 0 20 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
use OpenCloud\Common\Exceptions\InvalidArgumentError;
43
44
class Provider implements IProvider {
45
46
47
	/** @var ProviderSubjectCircle */
48
	private $parserCircle;
49
50
	/** @var ProviderSubjectMember */
51
	private $parserMember;
52
53
	/** @var ProviderSubjectGroup */
54
	private $parserGroup;
55
56
	/** @var ProviderSubjectLink */
57
	private $parserLink;
58
59
	/** @var MiscService */
60
	protected $miscService;
61
62
	/** @var IManager */
63
	protected $activityManager;
64
65
66
	public function __construct(
67
		IManager $activityManager, MiscService $miscService, ProviderSubjectCircle $parserCircle,
68
		ProviderSubjectMember $parserMember, ProviderSubjectGroup $parserGroup,
69
		ProviderSubjectLink $parserLink
70
	) {
71
		$this->activityManager = $activityManager;
72
		$this->miscService = $miscService;
73
74
		$this->parserCircle = $parserCircle;
75
		$this->parserMember = $parserMember;
76
		$this->parserGroup = $parserGroup;
77
		$this->parserLink = $parserLink;
78
	}
79
80
81
	/**
82
	 * {@inheritdoc}
83
	 */
84
	public function parse($lang, IEvent $event, IEvent $previousEvent = null) {
85
86
		try {
87
			$params = $event->getSubjectParameters();
88
			$this->initActivityParser($event, $params);
89
90
			$circle = Circle::fromJSON($params['circle']);
91
92
			$this->setIcon($event, $circle);
93
			$this->parseAsMember($event, $circle, $params);
94
			$this->parseAsModerator($event, $circle, $params);
95
96
		} catch (FakeException $e) {
97
			/** clean exit */
98
		}
99
100
		return $event;
101
	}
102
103
104
	/**
105
	 * @param IEvent $event
106
	 * @param array $params
107
	 */
108
	private function initActivityParser(IEvent $event, $params) {
109
		if ($event->getApp() !== Application::APP_NAME) {
110
			throw new InvalidArgumentException();
111
		}
112
113
		if (!key_exists('circle', $params)) {
114
			throw new InvalidArgumentException();
115
		}
116
	}
117
118
119
	/**
120
	 * @param IEvent $event
121
	 * @param Circle $circle
122
	 */
123
	private function setIcon(IEvent &$event, Circle $circle) {
124
		$event->setIcon(
125
			CirclesService::getCircleIcon(
126
				$circle->getType(),
127
				(method_exists($this->activityManager, 'getRequirePNG')
128
				 && $this->activityManager->getRequirePNG())
129
			)
130
		);
131
	}
132
133
134
	/**
135
	 * @param IEvent $event
136
	 * @param Circle $circle
137
	 * @param array $params
138
	 *
139
	 * @throws FakeException
140
	 */
141
	private function parseAsMember(IEvent &$event, Circle $circle, $params) {
142
		if ($event->getType() !== 'circles_as_member') {
143
			return;
144
		}
145
146
		$this->parserCircle->parseSubjectCircleCreate($event, $circle);
147
		$this->parserCircle->parseSubjectCircleDelete($event, $circle);
148
		$this->parseMemberAsMember($event, $circle, $params);
149
	}
150
151
152
	/**
153
	 * @param Circle $circle
154
	 * @param IEvent $event
155
	 * @param array $params
156
	 *
157
	 * @throws Exception
158
	 */
159
	private function parseAsModerator(IEvent &$event, Circle $circle, $params) {
160
		if ($event->getType() !== 'circles_as_moderator') {
161
			return;
162
		}
163
164
		$this->parseMemberAsModerator($event, $circle, $params);
165
		$this->parseGroupAsModerator($event, $circle, $params);
166
		$this->parseLinkAsModerator($event, $circle, $params);
167
	}
168
169
170
	/**
171
	 * @param IEvent $event
172
	 * @param Circle $circle
173
	 * @param array $params
174
	 *
175
	 * @throws InvalidArgumentError
176
	 */
177 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...
178
179
		if (!key_exists('member', $params)) {
180
			return;
181
		}
182
183
		$member = Member::fromJSON($params['member']);
184
185
		$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 183 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...
186
		$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 183 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...
187
		$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 183 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...
188
		$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 183 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...
189
	}
190
191
192
	/**
193
	 * @param IEvent $event
194
	 * @param Circle $circle
195
	 * @param array $params
196
	 */
197
	private function parseGroupAsModerator(IEvent &$event, Circle $circle, $params) {
198
		if (!key_exists('group', $params)) {
199
			return;
200
		}
201
202
		$group = Member::fromJSON($params['group']);
203
204
		$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 202 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...
205
		$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 202 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...
206
		$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 202 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...
207
	}
208
209
210
	/**
211
	 * @param IEvent $event
212
	 * @param Circle $circle
213
	 * @param array $params
214
	 */
215 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...
216
		if (!key_exists('member', $params)) {
217
			return;
218
		}
219
220
		$member = Member::fromJSON($params['member']);
221
222
		$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 220 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...
223
		$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 220 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...
224
		$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 220 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...
225
		$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 220 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...
226
	}
227
228
229
	/**
230
	 * @param IEvent $event
231
	 * @param Circle $circle
232
	 * @param array $params
233
	 */
234
	private function parseLinkAsModerator(IEvent &$event, Circle $circle, $params) {
235
236
		if (!key_exists('link', $params)) {
237
			return;
238
		}
239
240
		$remote = FederatedLink::fromJSON($params['link']);
241
242
		$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 240 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...
243
		$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 240 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...
244
		$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 240 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...
245
		$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 240 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...
246
		$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 240 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...
247
		$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 240 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...
248
		$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 240 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...
249
		$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 240 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...
250
		$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 240 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...
251
		$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 240 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...
252
		$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 240 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...
253
	}
254
255
256
}