Sections   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 0

Complexity

Total Complexity 10

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 19
cts 21
cp 0.9048
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 3 1
A append() 0 3 2
A prepend() 0 3 2
A clear() 0 3 1
A get() 0 5 2
A merge() 0 3 1
1
<?php
2
3
namespace League\Plates\Extension\LayoutSections;
4
5
/** A simple store for managing section content. This needs to be a mutable object
6
    so that references can be shared across templates. */
7
final class Sections
8
{
9
    private $sections;
10
11 80
    public function __construct(array $sections = []) {
12 80
        $this->sections = $sections;
13 80
    }
14
15 36
    public function add($name, $content) {
16 36
        $this->sections[$name] = $content;
17 36
    }
18
19 12
    public function append($name, $content) {
20 12
        $this->sections[$name] = ($this->get($name) ?: '') . $content;
21 12
    }
22
23 12
    public function prepend($name, $content) {
24 12
        $this->sections[$name] = $content . ($this->get($name) ?: '');
25 12
    }
26
27 4
    public function clear($name) {
28 4
        unset($this->sections[$name]);
29 4
    }
30
31 68
    public function get($name) {
32 68
        return array_key_exists($name, $this->sections)
33 48
            ? $this->sections[$name]
34 68
            : null;
35
    }
36
37
    public function merge(Sections $sections) {
38
        return new self(array_merge($this->sections, $sections->sections));
39
    }
40
}
41