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

Name   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 192
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 65.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 192
ccs 58
cts 88
cp 0.6591
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hp ➔ prefixResolveName() 0 8 1
A hp ➔ relativeResolveName() 0 12 3
A hp ➔ folderResolveName() 0 17 3
A hp ➔ defaultFolderResolveName() 0 5 1
1
<?php
2
3
namespace League\Plates\Template;
4
5
use League\Plates;
6
7
/** appends a suffix to the name */
8
function extResolveName($ext = 'phtml') {
9
    return function($name, array $context) use ($ext) {
10
        return [$name . '.' . $ext, $context];
11
    };
12
}
13
14
function prefixResolveName($prefix) {
15
    return function($name, array $context) use ($prefix) {
16
        return [
17
            Plates\Util\joinPath([$prefix, $name]),
18
            $context
19
        ];
20
    };
21
}
22
23
/** If the template context stores a current directory and  */
24
function relativeResolveName() {
25
    return function($name, array $context) {
26
        if (strpos($path, './') !== 0 || !isset($context['current_directory'])) {
0 ignored issues
show
Bug introduced by
The variable $path does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
27
            return $name; // nothing to do
28
        }
29
30
        return [
31
            Plates\Util\joinPath([$context['current_directory'], substr($path, 2)]),
32
            $context
33
        ];
34
    };
35
}
36
37
/** assumes the template name is in the format of `folder::path`.
38
    folders */
39
function folderResolveName(array $folders, $sep = '::') {
40
    return function($name, array $context) use ($folders, $sep) {
41
        if (strpos($name, $sep) === false) {
42 150
            return [$name, $context];
43
        }
44 150
45 150
        list($folder, $path) = explode($sep, $name);
46 141
        if (!isset($folders[$folder])) {
47
            return [$name, $context];
48
        }
49
50
        return [
51
            Plates\Util\joinPath([$folders[$folder], $path]),
52
            $context
53 150
        ];
54
    };
55 150
}
56
57 150
/** will automatically*/
58
function defaultFolderResolveName(array $folders, $sep = '::') {
59
    return function($name, array $context) use ($folders, $sep) {
0 ignored issues
show
Unused Code introduced by
The parameter $name 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...
Unused Code introduced by
The parameter $context 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...
60
        // if (strpos($name, $sep))
61
    };
62
}
63