match.php ➔ matchAll()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 1
nop 1
dl 0
loc 11
ccs 0
cts 5
cp 0
crap 12
rs 9.9
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 24
        return $match(pathinfo($path, PATHINFO_EXTENSION));
10 24
    });
11
}
12
13
function matchName($name) {
14
    return function(Template $template) use ($name) {
15 8
        return $template->get('normalized_name', $template->name) == $name;
16 8
    };
17
}
18
19
function matchExtensions(array $extensions) {
20
    return matchPathExtension(function($ext) use ($extensions) {
21 24
        return in_array($ext, $extensions);
22 24
    });
23
}
24
25
function matchAttribute($attribute, callable $match) {
26
    return function(Template $template) use ($attribute, $match) {
27 24
        return $match($template->get($attribute));
28 24
    };
29
}
30
31
function matchStub($res) {
32
    return function(Template $template) use ($res) {
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...
33 4
        return $res;
34 28
    };
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