Completed
Push — master ( 6d3eb9...bd657a )
by
unknown
14:36
created

match.php ➔ matchName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\Plates\Template;
4
5
use League\Plates\Template;
6
7
function matchPathExtension(callable $match) {
8
    return matchAttribute('path', function($path) use ($match) {
9 16
        return $match(pathinfo($path, PATHINFO_EXTENSION));
10 16
    });
11
}
12
13
function matchName($name) {
14
    return function(Template $template) use ($name) {
15 16
        return $template->get('normalized_name', $template->name) == $name;
16 16
    };
17
}
18
19
function matchExtensions(array $extensions) {
20
    return matchPathExtension(function($ext) use ($extensions) {
21 16
        return in_array($ext, $extensions);
22 16
    });
23
}
24
25
function matchAttribute($attribute, callable $match) {
26
    return function(Template $template) use ($attribute, $match) {
27 4
        return $match($template->get($attribute));
28 20
    };
29
}
30
31
function matchStub($res) {
32
    return function(Template $template) use ($res) {
0 ignored issues
show
Unused Code introduced by RJ Garcia
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...
33
        return $res;
34
    };
35
}
36
37
function matchAny(array $matches) {
38
    return function(Template $template) use ($matches) {
39
        foreach ($matches as $match) {
40
            if ($match($template)) {
41
                return true;
42
            }
43
        }
44
45
        return false;
46
    };
47
}
48
49
function matchAll(array $matches) {
50
    return function(Template $template) use ($matches) {
51
        foreach ($matches as $match) {
52
            if (!$match($template)) {
53
                return false;
54
            }
55
        }
56
57
        return true;
58
    };
59
}
60