Completed
Push — master ( 8d3e79...9daf84 )
by Edson
04:12
created

ElseifView::elseif()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 9
ccs 8
cts 8
cp 1
crap 3
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Bonfim\Tpl;
4
5
trait ElseifView
0 ignored issues
show
Bug introduced by
Possible parse error: trait missing opening or closing brace
Loading history...
6
{
7
    private $elseif = array();
8
9
    abstract public function setCondition($condition): string;
10
    
11 8
    private function setElseifContent()
12
    {
13 8
        $pattern = '/{\s?elseif (.*?)\s?([><!=])(=)?(=)?\s?(.*?)\s?}(.*?){end}/is';
14 8
        if (preg_match_all($pattern, $this->ifContent, $matches, PREG_SET_ORDER)) {
15 4
            $count = count($matches);
16 4
            for ($i = 0; $i < $count; $i++) {
17 4
                $this->ifContent = str_replace($matches[$i][0], '', $this->ifContent);
0 ignored issues
show
Bug Best Practice introduced by
The property ifContent does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
18 4
                $this->elseif[$i]['firstCondition'] = $this->setCondition($matches[$i][1]);
19 4
                $this->elseif[$i]['secondCondition'] = $this->setCondition($matches[$i][5]);
20 4
                $this->elseif[$i]['operator'] = implode('', array_slice($matches[$i], 2, 3));
21 4
                $this->elseif[$i]['content'] = trim($matches[$i][6]);
22
            }
23
        }
24 8
        $this->ifContent = str_replace('{end}', '', $this->ifContent);
25 8
    }
26
27 8
    private function elseif(): void
28
    {
29 8
        $count = count($this->elseif);
30 8
        if ($count != 0) {
31 4
            for ($i = 0; $i < $count; $i++) {
32 4
                $this->replace .= "<?php elseif({$this->elseif[$i]['firstCondition']}";
33 4
                $this->replace .= " {$this->elseif[$i]['operator']}";
34 4
                $this->replace .= " {$this->elseif[$i]['secondCondition']}): ?>";
35 4
                $this->replace .= trim($this->elseif[$i]['content']);
36
            }
37
        }
38 8
    }
39
}
40