Passed
Push — v5 ( c0775f...b45ef7 )
by Alexey
16:22
created

Parser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A cutTag() 0 4 1
A parseSource() 0 8 2
A findTags() 0 7 2
1
<?php
2
3
namespace Inji\View;
4
5
6
class Parser {
7
    public function parseSource($source) {
8
        $tags = static::findTags($source);
0 ignored issues
show
Bug Best Practice introduced by
The method Inji\View\Parser::findTags() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

8
        /** @scrutinizer ignore-call */ 
9
        $tags = static::findTags($source);
Loading history...
9
        foreach ($tags as $rawTag) {
10
            $tag = explode(':', $rawTag);
11
            $html = call_user_func_array([$this, strtolower($tag[0]) . 'Tag'], array_slice($tag, 1));
12
            $source = str_replace('{' . $rawTag . '}', $html, $source);
13
        }
14
        return $source;
15
    }
16
17
    public function findTags($source) {
18
        if (!$source) {
19
            return [];
20
        }
21
22
        preg_match_all("|{([^}]+)}|", $source, $result);
23
        return $result[1];
24
    }
25
26
    public function cutTag($source, $rawTag) {
27
        $pos = strpos($source, $rawTag) - 1;
28
        echo substr($source, 0, $pos);
29
        return substr($source, ($pos + strlen($rawTag) + 2));
30
    }
31
}