Sections::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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