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

ElseView::setElseContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 2
rs 9.4285
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 9 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 ElseView
0 ignored issues
show
Bug introduced by
Possible parse error: trait missing opening or closing brace
Loading history...
6
{
7
    private $elseContent = '';
8
9 8
    private function setElseContent()
10
    {
11 8
        $matches = array();
12 8
        if (preg_match('/(.*?){\s?else\s?}/is', $this->match[6], $matches)) {
13 4
            $this->ifContent = $matches[1];
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...
14 4
            $this->elseContent = str_replace($matches[0], '', $this->match[6]);
15
        } else {
16 4
            $this->ifContent = $this->match[6];
17 4
            $this->elseContent = '';
18
        }
19 8
        $this->ifContent = str_replace('{elseif', '{end}{elseif', $this->ifContent);
20 8
        $this->ifContent = $this->ifContent . "{end}";
21 8
    }
22
23 8
    private function else(): void
24
    {
25 8
        if (!empty($this->elseContent)) {
26 4
            $this->replace .= "<?php else: ?>";
27 4
            $this->replace .= trim($this->elseContent);
28
        }
29 8
    }
30
}
31