Completed
Push — master ( 160a90...29891d )
by Joas
13:59
created

Collection::joinParameterList()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 31
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 31
ccs 24
cts 24
cp 1
rs 8.439
cc 6
eloc 24
nc 6
nop 3
crap 6
1
<?php
2
3
/**
4
 * ownCloud - Activity App
5
 *
6
 * @author Joas Schilling
7
 * @copyright 2014 Joas Schilling [email protected]
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
 * License as published by the Free Software Foundation; either
12
 * version 3 of the License, or any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Activity\Parameter;
25
26
use OCP\IL10N;
27
use OCP\Util;
28
29
class Collection implements IParameter {
30
	/** @var IL10N */
31
	protected $l;
32
33
	/** @var Parameter[] */
34
	protected $parameters;
35
36
	/** @var string */
37
	protected $random;
38
39
	/**
40
	 * @param IL10N $l
41
	 * @param string $random
42
	 */
43 7
	public function __construct(IL10N $l, $random) {
44 7
		$this->l = $l;
45 7
		$this->random = $random;
46 7
		$this->parameters = [];
47 7
	}
48
49
	/**
50
	 * @param IParameter $parameter
51
	 */
52 1
	public function addParameter(IParameter $parameter) {
53 1
		foreach ($this->parameters as $existingParameter) {
54 1
			if ($existingParameter->getParameter() === $parameter->getParameter()) {
55 1
				return;
56
			}
57 1
		}
58 1
		$this->parameters[] = $parameter;
59 1
	}
60
61
	/**
62
	 * @return mixed
63
	 */
64 3
	public function getParameter() {
65 3
		return $this->random;
66
	}
67
68
	/**
69
	 * @return array With two entries: value and type
70
	 */
71 2
	public function getParameterInfo() {
72 2
		$parameters = [];
73 2
		foreach ($this->parameters as $parameter) {
74 1
			$parameters[] = $parameter->getParameterInfo();
75 2
		}
76
77
		return [
78 2
			'value' => $parameters,
79 2
			'type' => 'collection',
80 2
		];
81
	}
82
83
	/**
84
	 * @return string The formatted parameter
85
	 */
86 1
	public function format() {
87 1
		$parameterList = $plainParameterList = [];
0 ignored issues
show
Unused Code introduced by
$plainParameterList is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
88
89 1
		foreach ($this->parameters as $parameter) {
90 1
			$parameterList[] = $parameter->format();
91 1
		}
92
93 1
		return '<collection>' . implode('', $parameterList) . '</collection>';
94
	}
95
}
96