Completed
Push — v4.0 ( 3a8f05...488a49 )
by
unknown
03:09
created

LazyContent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fromTemplate() 0 3 1
A __toString() 0 9 2
1
<?php
2
3
namespace League\Plates\Content;
4
5
use League\Plates;
6
7
class LazyContent implements Plates\Content
8
{
9
    private $build_content;
10
    private $content;
11
12
    public function __construct(callable $build_content) {
13
        $this->build_content = $build_content;
14
    }
15
16
    public static function fromTemplate(Plates\Template $template) {
17
        return new self([$template, 'getContent']);
18
    }
19
20
    public function __toString() {
21
        if ($this->content !== null) {
22
            return $this->content;
23
        }
24
25
        $this->content = (string) call_user_func($this->build_content);
26
27
        return $this->content;
28
    }
29
}
30