Completed
Push — 183-default-layout-ext ( a97107 )
by
unknown
10:37
created

src/Template/match.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
        return $match(pathinfo($path, PATHINFO_EXTENSION));
10
    });
11
}
12
13
function matchExtensions(array $extensions) {
14
    return matchPathExtension(function($ext) use ($extensions) {
15
        return in_array($ext, $extensions);
16
    });
17
}
18
19
function matchAttribute($attribute, callable $match) {
20
    return function(Template $template) use ($attribute, $match) {
21
        return $match($template->get($attribute));
22
    };
23
}
24
25
function matchStub($res) {
26
    return function(Template $template) use ($res) {
0 ignored issues
show
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...
27
        return $res;
28
    };
29
}
30
31
function matchAny(array $matches) {
32
    return function(Template $template) use ($matches) {
33
        foreach ($matches as $match) {
34
            if ($match($template)) {
35
                return true;
36
            }
37
        }
38
39
        return false;
40
    };
41
}
42
43
function matchAll(array $matches) {
44
    return function(Template $template) use ($matches) {
45
        foreach ($matches as $match) {
46
            if (!$match($template)) {
47
                return false;
48
            }
49
        }
50
51
        return true;
52
    };
53
}
54