Completed
Pull Request — master (#3)
by
unknown
01:02
created

Properties::getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
namespace Jupitern\Table;
3
4
class Properties
5
{
6
	private $properties;
7
8
	public function add($property, $value)
9
	{
10
		$this->properties[$property] = $value;
11
		return $this;
12
	}
13
14
	public function addAll($properties)
15
	{
16
		if (is_array($properties)) {
17
			$this->properties = array_merge((array)$this->properties, $properties);
18
		}
19
		return $this;
20
	}
21
22
	public function render($template, $context = null)
23
	{
24
		$output = '';
25
		foreach ((array)$this->properties as $prop => $val) {
26
			$val = $this->getValue($val, $context);
27
			$output .= str_replace(['{prop}', '{val}'], [$prop, $val], $template);
28
		}
29
		return $output;
30
	}
31
32
	public function getValue($value, $context)
33
	{
34
		$val = "";
0 ignored issues
show
Unused Code introduced by
$val 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...
35
		if (is_callable($value)) {
36
			$val = $value($context);
37
		} else {
38
			$val = $value;
39
		}
40
		return $val;
41
	}
42
43
}