Completed
Push — master ( fe8048...f27190 )
by Edson
01:22
created

RepeatTag   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 13 3
1
<?php
2
3
namespace Sketch\Tpl;
4
5
class RepeatTag extends Tag
6
{
7 10
    public function __construct()
8
    {
9 10
        parent::__construct(
10 10
            '/{(\s?)+repeat (\s?)+([\d]+)(\s?)+(:?)(\s?)+([\w]+)?(\s?)+}(.*?){(\s?)+\/repeat(\s?)+}/is'
11
        );
12 10
    }
13
14 8
    public function handle(array $match): string
15
    {
16 8
        static $count = 0;
17
18 8
        $index = !empty($match[5]) && !empty($match[7])
19 4
            ? $match[7]
20 8
            : 'index' . ++$count;
21
22 8
        $replace  = "<?php for (\$$index = 0; \$$index < $match[3]; \$$index++) { ?>";
23 8
        $replace .= $match[9];
24 8
        $replace .= "<?php } ?>";
25
26 8
        return $replace;
27
    }
28
}
29