data.php ➔ mergeParentDataCompose()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Extension\Data;
4
5
use League\Plates\Template;
6
7
function addGlobalsCompose(array $globals) {
8
    return function(Template $template) use ($globals) {
9 4
        return $template->withData(array_merge($globals, $template->data));
10 4
    };
11
}
12
13
function mergeParentDataCompose() {
14
    return function(Template $template) {
15 24
        return $template->parent
16 16
            ? $template->withData(array_merge($template->parent()->data, $template->data))
17 24
            : $template;
18 24
    };
19
}
20
21
function perTemplateDataCompose(array $template_data_map) {
22
    return function(Template $template) use ($template_data_map) {
23 4
        $name = $template->get('normalized_name', $template->name);
24
25 4
        return isset($template_data_map[$name])
26 4
            ? $template->withData(array_merge($template_data_map[$name], $template->data))
27 4
            : $template;
28 4
    };
29
}
30