Completed
Push — extensions ( 84a6ae )
by
unknown
22:00 queued 07:01
created

Sections   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
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
    public function __construct(array $sections = []) {
12
        $this->sections = $sections;
13
    }
14
15
    public function add($name, $content) {
16
        $this->sections[$name] = $content;
17
    }
18
19
    public function append($name, $content) {
20
        $this->sections[$name] = ($this->get($name) ?: '') . $content;
21
    }
22
23
    public function prepend($name, $content) {
24
        $this->sections[$name] = $content . ($this->get($name) ?: '');
25
    }
26
27
    public function clear($name) {
28
        unset($this->sections[$name]);
29
    }
30
31
    public function get($name) {
32
        return array_key_exists($name, $this->sections)
33
            ? $this->sections[$name]
34
            : null;
35
    }
36
37
    public function merge(Sections $sections) {
38
        return new self(array_merge($this->sections, $sections->sections));
39
    }
40
}
41