1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Joas Schilling <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Activity\Parameter; |
24
|
|
|
|
25
|
|
|
use OCP\IL10N; |
26
|
|
|
|
27
|
|
|
class Collection implements IParameter { |
28
|
|
|
/** @var IL10N */ |
29
|
|
|
protected $l; |
30
|
|
|
|
31
|
|
|
/** @var Parameter[] */ |
32
|
|
|
protected $parameters; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
protected $random; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param IL10N $l |
39
|
|
|
* @param string $random |
40
|
|
|
*/ |
41
|
7 |
|
public function __construct(IL10N $l, $random) { |
42
|
7 |
|
$this->l = $l; |
43
|
7 |
|
$this->random = $random; |
44
|
7 |
|
$this->parameters = []; |
45
|
7 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param IParameter $parameter |
49
|
|
|
*/ |
50
|
1 |
|
public function addParameter(IParameter $parameter) { |
51
|
1 |
|
foreach ($this->parameters as $existingParameter) { |
52
|
1 |
|
if ($existingParameter->getParameterInfo() === $parameter->getParameterInfo()) { |
53
|
1 |
|
return; |
54
|
|
|
} |
55
|
|
|
} |
56
|
1 |
|
$this->parameters[] = $parameter; |
57
|
1 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
3 |
|
public function getParameter() { |
63
|
3 |
|
return $this->random; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array With two entries: value and type |
68
|
|
|
*/ |
69
|
2 |
|
public function getParameterInfo() { |
70
|
2 |
|
$parameters = []; |
71
|
2 |
|
foreach ($this->parameters as $parameter) { |
72
|
1 |
|
$parameters[] = $parameter->getParameterInfo(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return [ |
76
|
2 |
|
'value' => $parameters, |
77
|
2 |
|
'type' => 'collection', |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string The formatted parameter |
83
|
|
|
*/ |
84
|
1 |
|
public function format() { |
85
|
1 |
|
$parameterList = $plainParameterList = []; |
|
|
|
|
86
|
|
|
|
87
|
1 |
|
foreach ($this->parameters as $parameter) { |
88
|
1 |
|
$parameterList[] = $parameter->format(); |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
return '<collection>' . implode('', $parameterList) . '</collection>'; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.