Completed
Push — 186-data ( d4ee1e )
by
unknown
08:25 queued 10s
created

CallableHydrateTemplate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A hydrateTemplate() 0 3 1
A stub() 0 3 1
A resolveData() 0 5 1
A resolvePath() 0 8 1
1
<?php
2
3
namespace League\Plates\HydrateTemplate;
4
5
use League\Plates;
6
7
/** Wraps a callable into the HydrateTemplate interface */
8
class CallableHydrateTemplate implements Plates\HydrateTemplate
9
{
10
    private $hydrate_template;
11
12
    public function __construct(callable $hydrate_template) {
13
        $this->hydrate_template = $hydrate_template;
14
    }
15
16
    public function hydrateTemplate(Plates\Template $template) {
17
        return ($this->hydrate_template)($template);
18
    }
19
20
    public static function stub() {
21
        return new self(function(Plates\Template $template) {});
0 ignored issues
show
Unused Code introduced by
The parameter $template is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    }
23
24
    public static function resolveData(callable $resolveData) {
25
        return new self(function($template) use ($resolveData) {
26
            $template->data = $resolveData(Plates\Template\ResolveDataArgs::fromTemplate($template));
27
        });
28
    }
29
30
    public static function resolvePath(callable $resolvePath) {
31
        return new self(function($template) use ($resolvePath) {
32
            Plates\Template\setPath(
33
                $template,
34
                $resolvePath(Plates\Template\ResolvePathArgs::fromTemplate($template))
35
            );
36
        });
37
    }
38
}
39