Test Setup Failed
Push — master ( 1685c5...687b3c )
by Michael
02:21
created

TemplateHookWithArgs   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 4 1
A getLabel() 0 6 2
A parseArgs() 0 8 1
A trimArg() 0 5 1
1
<?php
2
/**
3
 * {CLASS SUMMARY}
4
 *
5
 * Date: 7/27/18
6
 * Time: 11:31 PM
7
 * @author Michael Munger <[email protected]>
8
 */
9
10
namespace HPHIO\Farret;
11
12
13
class TemplateHookWithArgs extends AbstractTag
14
{
15
16
    public function setup()
17
    {
18
        $this->type = AbstractTag::HOOK;
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
        $this->parseArgs();
20
    }
21
22
    private function trimArg($arg) {
23
24
        $arg = str_replace("|",'',$arg);
25
        $arg = trim($arg);
26
        return $arg;
27
    }
28
29
    public function parseArgs() {
30
        $argsPattern = '/(\|(?:{{){0,1}([A-Za-z0-9-]+)(?:}}){0,1})/';
31
        $matches = [];
32
33
        preg_match_all($argsPattern, $this->tag, $matches, PREG_PATTERN_ORDER);
34
35
        //Clean up the args.
36
        $this->args = array_map([$this,'trimArg'], $matches[0]);
37
38
    }
39
40
    public function getLabel()
41
    {
42
        $matches = [];
43
        $result = (preg_match_all($this->pattern, $this->tag,$matches, PREG_SET_ORDER) !== false);
44
45
        return ($result ? $matches[0][1] : false);
46
    }
47
}