Completed
Push — 186-data ( d4ee1e )
by
unknown
08:25 queued 10s
created

NameMatchQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matchQuery() 0 5 3
A matchesWildcardPrefix() 0 5 3
1
<?php
2
3
namespace League\Plates\Template\Query\MatchQuery;
4
5
use League\Plates\Template;
6
use League\Plates\Template\Query\MatchQuery;
7
8
class NameMatchQuery implements MatchQuery
9
{
10
    public function matchQuery($query, Template $template) {
11
        return $query === $template->name
12
            || $query === '*'
13
            || $this->matchesWildcardPrefix($query, $template);
14
    }
15
16
    private function matchesWildcardPrefix($query, Template $template) {
17
        return strlen($query)
18
            && $query[strlen($query) - 1] === '*'
19
            && strpos($template->name, substr($query, 0, -1)) === 0;
20
    }
21
}
22