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

Name::getPath()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.5069

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 11
cp 0.7272
rs 8.8571
cc 5
eloc 7
nc 3
nop 0
crap 5.5069
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