Properties   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 1
A addAll() 0 8 2
A render() 0 14 3
1
<?php
2
namespace Jupitern\Table;
3
4
class Properties
5
{
6
	private $properties;
7
8
    /**
9
     * @param $property
10
     * @param $value
11
     * @return $this
12
     */
13
    public function add($property, $value)
14
	{
15
		$this->properties[$property] = $value;
16
17
		return $this;
18
	}
19
20
    /**
21
     * @param $properties
22
     * @return $this
23
     */
24
    public function addAll($properties)
25
	{
26
		if (is_array($properties)) {
27
			$this->properties = array_merge((array)$this->properties, $properties);
28
		}
29
30
		return $this;
31
	}
32
33
    /**
34
     * @param $elem
35
     * @param $template
36
     * @return string
37
     */
38
    public function render($template, $context = null)
39
	{
40
		$output = '';
41
		foreach ((array)$this->properties as $prop => $value) {
42
			if (is_callable($value)) {
43
				$val = $value($context);
44
			} else {
45
				$val = $value;
46
			}
47
			$output .= str_replace(['{prop}', '{val}'], [$prop, $val], $template);
48
		}
49
50
		return $output;
51
	}
52
53
}
54